@bitcobblers/wod-wiki-ui 0.51.2193 → 0.51.2195

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.
@@ -1251,6 +1251,18 @@ var referenceIndexReload = state.StateEffect.define();
1251
1251
  var frontmatterVisibility = state.Facet.define({
1252
1252
  combine: (values2) => values2[0] ?? true
1253
1253
  });
1254
+ var frontmatterDebugMode = state.Facet.define({
1255
+ combine: (values2) => values2[0] ?? false
1256
+ });
1257
+ var INTERNAL_FRONTMATTER_KEYS = /* @__PURE__ */ new Set([
1258
+ "type",
1259
+ "id",
1260
+ "registrysource",
1261
+ "registry-source"
1262
+ ]);
1263
+ function isInternalFrontmatterKey(key) {
1264
+ return INTERNAL_FRONTMATTER_KEYS.has(key.trim().toLowerCase());
1265
+ }
1254
1266
  var setFrontmatterDetailed = state.StateEffect.define();
1255
1267
  var frontmatterDetailed = state.StateField.define({
1256
1268
  create: () => false,
@@ -1279,6 +1291,45 @@ var frontmatterSource = state.StateField.define({
1279
1291
  }
1280
1292
  });
1281
1293
  var pendingFocus = /* @__PURE__ */ new WeakMap();
1294
+ var persistedDetailed = /* @__PURE__ */ new WeakMap();
1295
+ function exitToEditorBody(view) {
1296
+ const { sections } = view.state.field(sectionField);
1297
+ const fm = sections.find((s) => s.type === "frontmatter");
1298
+ const targetPos = fm ? Math.min(view.state.doc.length, fm.to) : 0;
1299
+ view.dispatch({
1300
+ selection: { anchor: targetPos },
1301
+ scrollIntoView: true
1302
+ });
1303
+ view.focus();
1304
+ }
1305
+ function triggerAddOrEditProperty(view, root, _sectionId) {
1306
+ const { sections } = view.state.field(sectionField);
1307
+ const fm = sections.find((s) => s.type === "frontmatter");
1308
+ if (!fm) {
1309
+ pendingFocus.set(view, { kind: "key", key: "property" });
1310
+ patchPropertyInView(view, "new", ["property"], "", true);
1311
+ return;
1312
+ }
1313
+ if (!view.state.field(frontmatterDetailed)) {
1314
+ view.dispatch({ effects: setFrontmatterDetailed.of(true) });
1315
+ }
1316
+ const activeRoot = root ?? view.dom.querySelector(".cm-frontmatter-preview");
1317
+ const emptyKey = activeRoot?.querySelector(
1318
+ 'input[data-frontmatter-field="key"]:is([value=""], [value="property"])'
1319
+ );
1320
+ if (emptyKey) {
1321
+ emptyKey.focus();
1322
+ emptyKey.select?.();
1323
+ return;
1324
+ }
1325
+ const addBtn = activeRoot?.querySelector('button[aria-label="Add property"]');
1326
+ if (addBtn) {
1327
+ addBtn.click();
1328
+ return;
1329
+ }
1330
+ pendingFocus.set(view, { kind: "key", key: "property" });
1331
+ patchPropertyInView(view, fm.id, ["property"], "", true);
1332
+ }
1282
1333
  var widgetCleanup = /* @__PURE__ */ new WeakMap();
1283
1334
  var helperId = 0;
1284
1335
  var TAG_CATEGORY_SUMMARY_KEYS = {
@@ -1332,7 +1383,7 @@ function attachSuggestions(input, view, root, kind, key, excluded, commit, value
1332
1383
  if (!provider || !input.parentElement) return;
1333
1384
  const panel = new SuggestionPanel(input, {
1334
1385
  label: kind === "key" ? "Suggested properties" : suggestionListLabel(valueKind),
1335
- onPick: () => commit(),
1386
+ onPick: () => commit(true),
1336
1387
  // The popup floats over the properties panel; it must never cover the
1337
1388
  // metadata actions below it.
1338
1389
  avoid: () => root.querySelector("[data-frontmatter-actions]")
@@ -1356,16 +1407,31 @@ function attachSuggestions(input, view, root, kind, key, excluded, commit, value
1356
1407
  const entries = valueKind === "effort" ? catalog.efforts ?? [] : catalog.equipment ?? [];
1357
1408
  candidates = entries.map((entry) => ({
1358
1409
  value: entry.slug,
1359
- label: `${entry.label} (${entry.slug})`,
1410
+ label: entry.label.toLowerCase() === entry.slug.toLowerCase() ? entry.label : `${entry.label} (${entry.slug})`,
1360
1411
  haystack: [entry.label, entry.slug, ...entry.aliases].join(" ").toLowerCase()
1361
1412
  }));
1362
1413
  } else {
1363
- 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() }));
1414
+ const normKey = key.trim().toLowerCase();
1415
+ const fromTags = catalog.tags.filter((tag) => isTagProperty(key) || tag.type?.toLowerCase() === normKey).map((tag) => ({ value: tag.label, label: tag.label, haystack: tag.label.toLowerCase() }));
1416
+ if (fromTags.length > 0) {
1417
+ candidates = fromTags;
1418
+ } else if (normKey === "discipline") {
1419
+ candidates = wodWikiLang.EFFORT_DISCIPLINES.map((d) => ({ value: d, label: d, haystack: d.toLowerCase() }));
1420
+ } else if (normKey === "intensitytier" || normKey === "intensity") {
1421
+ candidates = ["low", "moderate", "high"].map((t) => ({ value: t, label: t, haystack: t }));
1422
+ } else {
1423
+ candidates = [];
1424
+ }
1364
1425
  }
1365
1426
  const selected = new Set(excluded.map((label) => label.toLowerCase()));
1366
- const choices = candidates.filter(
1367
- (candidate) => (query === "" || candidate.haystack.includes(query)) && !selected.has(candidate.value.toLowerCase())
1368
- ).map((candidate) => ({ value: candidate.value, label: candidate.label }));
1427
+ const seenValues = /* @__PURE__ */ new Set();
1428
+ const choices = candidates.filter((candidate) => {
1429
+ const lower = candidate.value.toLowerCase();
1430
+ if (selected.has(lower) || seenValues.has(lower)) return false;
1431
+ if (query !== "" && !candidate.haystack.includes(query)) return false;
1432
+ seenValues.add(lower);
1433
+ return true;
1434
+ }).map((candidate) => ({ value: candidate.value, label: candidate.label }));
1369
1435
  panel.setChoices(choices);
1370
1436
  if (choices.length > 0) panel.open();
1371
1437
  } catch {
@@ -1420,8 +1486,12 @@ function patchPropertyInView(view, _sectionId, path, value, expandDetailed = fal
1420
1486
  if (expandDetailed) view.dispatch({ effects: setFrontmatterDetailed.of(true) });
1421
1487
  return;
1422
1488
  }
1489
+ const currentAnchor = view.state.selection.main.anchor;
1490
+ const fmEnd = next.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/)?.[0].length ?? 0;
1491
+ const safeAnchor = currentAnchor <= fmEnd ? fmEnd : Math.min(currentAnchor, next.length);
1423
1492
  view.dispatch({
1424
1493
  changes: { from: 0, to: wholeDoc.length, insert: next },
1494
+ selection: { anchor: safeAnchor },
1425
1495
  ...expandDetailed ? { effects: setFrontmatterDetailed.of(true) } : {}
1426
1496
  });
1427
1497
  }
@@ -1434,7 +1504,13 @@ function renamePropertyInView(view, _sectionId, fromKey, toKey, value) {
1434
1504
  null
1435
1505
  );
1436
1506
  if (next === wholeDoc) return;
1437
- view.dispatch({ changes: { from: 0, to: wholeDoc.length, insert: next } });
1507
+ const currentAnchor = view.state.selection.main.anchor;
1508
+ const fmEnd = next.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/)?.[0].length ?? 0;
1509
+ const safeAnchor = currentAnchor <= fmEnd ? fmEnd : Math.min(currentAnchor, next.length);
1510
+ view.dispatch({
1511
+ changes: { from: 0, to: wholeDoc.length, insert: next },
1512
+ selection: { anchor: safeAnchor }
1513
+ });
1438
1514
  }
1439
1515
  function detectDefinitionKind(meta) {
1440
1516
  const type = typeof meta.type === "string" ? meta.type.trim().toLowerCase() : "";
@@ -1443,42 +1519,9 @@ function detectDefinitionKind(meta) {
1443
1519
  if (meta.registrySource !== void 0 || meta.baseAttributes !== void 0) return "effort";
1444
1520
  return null;
1445
1521
  }
1446
- function readBaseAttributes(body, meta = {}) {
1447
- const out = {};
1448
- if (meta["metrics.met"] !== void 0 && !Array.isArray(meta["metrics.met"])) {
1449
- out.met = String(meta["metrics.met"]);
1450
- }
1451
- if (meta["discipline"] !== void 0 && !Array.isArray(meta["discipline"])) {
1452
- out.discipline = String(meta["discipline"]);
1453
- }
1454
- if (meta["intensityTier"] !== void 0 && !Array.isArray(meta["intensityTier"])) {
1455
- out.intensityTier = String(meta["intensityTier"]);
1456
- }
1457
- let inBase = false;
1458
- for (const line of body.split(/\r?\n/)) {
1459
- if (/^baseAttributes:\s*(#.*)?$/.test(line)) {
1460
- inBase = true;
1461
- out.hasBaseBlock = true;
1462
- continue;
1463
- }
1464
- if (!inBase) continue;
1465
- if (/^\S/.test(line)) break;
1466
- const match = line.match(/^\s+([\w-]+):\s*(.*)$/);
1467
- if (!match) continue;
1468
- if (match[1] === "met" || match[1] === "discipline" || match[1] === "intensityTier") {
1469
- out[match[1]] = unquoteYamlScalar(match[2].trim());
1470
- }
1471
- }
1472
- return out;
1473
- }
1474
- function unquoteYamlScalar(val) {
1475
- if (val.startsWith('"') && val.endsWith('"')) return val.slice(1, -1).replace(/\\(["\\])/g, "$1");
1476
- if (val.startsWith("'") && val.endsWith("'")) return val.slice(1, -1).replace(/\\'/g, "'");
1477
- return val;
1478
- }
1479
1522
  function referenceValueKind(key, docKind) {
1480
1523
  const normalized = key.trim().toLowerCase();
1481
- if (normalized === "metrics.effort") return "effort";
1524
+ if (normalized === "metrics.effort" || normalized === "effort") return "effort";
1482
1525
  if (normalized === "metrics.equipment" || normalized === "equipment") return "equipment";
1483
1526
  if (normalized === "aliases" && docKind === "equipment") return "equipment";
1484
1527
  if (normalized === "aliases" && docKind === "effort") return "effort";
@@ -1734,9 +1777,10 @@ function createSummaryDraftRow(view, commit) {
1734
1777
  const settle = (doCommit) => {
1735
1778
  if (settled) return;
1736
1779
  settled = true;
1737
- const rawKey = (keyInput.value.trim() || "summary").replace(/^summaries\./i, "");
1780
+ const keyTrim = keyInput.value.trim();
1781
+ const rawKey = (keyTrim || "summary").replace(/^summaries\./i, "");
1738
1782
  const rawExpr = valInput.value.trim();
1739
- if (doCommit && rawExpr) {
1783
+ if (doCommit && (rawExpr || keyTrim)) {
1740
1784
  commit([`summaries.${rawKey}`], rawExpr);
1741
1785
  }
1742
1786
  row.remove();
@@ -1768,7 +1812,7 @@ function createSummaryDraftRow(view, commit) {
1768
1812
  const onBlur = () => queueMicrotask(() => {
1769
1813
  if (!row.isConnected) return;
1770
1814
  if (row.contains(document.activeElement)) return;
1771
- settle(valInput.value.trim().length > 0);
1815
+ settle(keyInput.value.trim().length > 0 || valInput.value.trim().length > 0);
1772
1816
  });
1773
1817
  keyInput.addEventListener("blur", onBlur);
1774
1818
  valInput.addEventListener("blur", onBlur);
@@ -1903,7 +1947,13 @@ function createFrontmatterSummary(entries, onShowDetails) {
1903
1947
  { label: "Aliases", entries: entries.filter(([key]) => isAliasProperty(key)), hash: false }
1904
1948
  ];
1905
1949
  for (const group of groups) {
1906
- const values2 = group.entries.flatMap(([, value]) => parseTagList(value));
1950
+ const seen = /* @__PURE__ */ new Set();
1951
+ const values2 = group.entries.flatMap(([, value]) => parseTagList(value)).filter((val) => {
1952
+ const lower = val.toLowerCase();
1953
+ if (seen.has(lower)) return false;
1954
+ seen.add(lower);
1955
+ return true;
1956
+ });
1907
1957
  if (values2.length === 0) continue;
1908
1958
  const row = document.createElement("div");
1909
1959
  row.className = "flex flex-wrap items-center gap-1.5 px-3 py-2";
@@ -1955,15 +2005,17 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
1955
2005
  rawContent;
1956
2006
  readOnly;
1957
2007
  detailed;
1958
- constructor(sectionId, rawContent, readOnly = false, detailed = false) {
2008
+ debugMode;
2009
+ constructor(sectionId, rawContent, readOnly = false, detailed = false, debugMode = false) {
1959
2010
  super();
1960
2011
  this.sectionId = sectionId;
1961
2012
  this.rawContent = rawContent ?? "";
1962
2013
  this.readOnly = readOnly;
1963
2014
  this.detailed = detailed;
2015
+ this.debugMode = debugMode;
1964
2016
  }
1965
2017
  eq(other) {
1966
- return this.sectionId === other.sectionId && this.rawContent === other.rawContent && this.readOnly === other.readOnly && this.detailed === other.detailed;
2018
+ return this.sectionId === other.sectionId && this.rawContent === other.rawContent && this.readOnly === other.readOnly && this.detailed === other.detailed && this.debugMode === other.debugMode;
1967
2019
  }
1968
2020
  ignoreEvent() {
1969
2021
  return true;
@@ -1985,6 +2037,7 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
1985
2037
  summaryButton.className = "ml-auto px-1 py-0.5 text-[11px] font-normal hover:text-foreground cursor-pointer";
1986
2038
  summaryButton.textContent = "Hide details \u25B4";
1987
2039
  summaryButton.addEventListener("click", () => {
2040
+ persistedDetailed.set(view.dom, false);
1988
2041
  view.dispatch({ effects: setFrontmatterDetailed.of(false) });
1989
2042
  });
1990
2043
  heading.appendChild(summaryButton);
@@ -1996,12 +2049,13 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
1996
2049
  root.appendChild(box);
1997
2050
  const body = this.rawContent.replace(/^---\r?\n?/, "").replace(/\r?\n?---\r?$/, "");
1998
2051
  const meta = wodWikiWql.parseFrontmatterBody(body);
1999
- const entries = Object.entries(meta);
2052
+ const showInternal = this.debugMode || view.state.facet(frontmatterDebugMode);
2053
+ const entries = Object.entries(meta).filter(([key]) => showInternal || !isInternalFrontmatterKey(key));
2000
2054
  const docKind = detectDefinitionKind(meta);
2001
2055
  const referenceProvider = view.state.facet(frontmatterReferenceIndex)?.() ?? null;
2002
- const base = docKind === "effort" ? readBaseAttributes(body, meta) : {};
2003
2056
  if (!this.detailed) {
2004
2057
  box.appendChild(createFrontmatterSummary(entries, () => {
2058
+ persistedDetailed.set(view.dom, true);
2005
2059
  view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2006
2060
  }));
2007
2061
  } else {
@@ -2012,10 +2066,13 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2012
2066
  emptyRow.textContent = "No properties";
2013
2067
  box.appendChild(emptyRow);
2014
2068
  }
2015
- for (const [key, value] of entries) {
2069
+ const entryKeys = entries.map(([name]) => name);
2070
+ for (let idxInEntries = 0; idxInEntries < entries.length; idxInEntries++) {
2071
+ const [key, value] = entries[idxInEntries];
2016
2072
  const isTags = isTagProperty(key);
2017
2073
  const valueKind = referenceValueKind(key, docKind);
2018
2074
  const isReferenceList = (isReferenceKey(key, docKind) || key === "aliases") && Array.isArray(value);
2075
+ const isChipList = isTags || isReferenceList || Array.isArray(value);
2019
2076
  const nested = value === "" && ownsNestedBlock(body, key);
2020
2077
  const row = document.createElement("div");
2021
2078
  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";
@@ -2024,7 +2081,7 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2024
2081
  const keyCol = document.createElement("div");
2025
2082
  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";
2026
2083
  row.appendChild(keyCol);
2027
- keyCol.appendChild(isTags || isReferenceList ? createTagIcon() : createListIcon());
2084
+ keyCol.appendChild(isChipList ? createTagIcon() : createListIcon());
2028
2085
  if (this.readOnly || nested) {
2029
2086
  const keyLabel = document.createElement("span");
2030
2087
  keyLabel.className = "truncate font-medium text-foreground/90";
@@ -2046,16 +2103,22 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2046
2103
  ).id
2047
2104
  );
2048
2105
  let currentKey = key;
2049
- const commitKey = () => {
2106
+ const commitKey = (andFocusValue = false) => {
2050
2107
  const nextKey = keyInput.value.trim();
2051
2108
  if (!nextKey || nextKey === currentKey) {
2052
2109
  keyInput.value = currentKey;
2110
+ if (andFocusValue) {
2111
+ row.querySelector('input[data-frontmatter-field="value"]')?.focus();
2112
+ }
2053
2113
  return;
2054
2114
  }
2055
2115
  if (!/^[A-Za-z_][\w.-]*$/.test(nextKey) || nextKey in meta) {
2056
2116
  keyInput.value = currentKey;
2057
2117
  return;
2058
2118
  }
2119
+ if (andFocusValue) {
2120
+ pendingFocus.set(view, { kind: "value", key: nextKey });
2121
+ }
2059
2122
  renamePropertyInView(view, this.sectionId, currentKey, nextKey, value);
2060
2123
  delete meta[currentKey];
2061
2124
  meta[nextKey] = value;
@@ -2069,10 +2132,52 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2069
2132
  attachSuggestions(keyInput, view, root, "key", key, entries.map(([name]) => name), commitKey);
2070
2133
  keyInput.addEventListener("blur", commitKeyIfAttached);
2071
2134
  keyInput.addEventListener("keydown", (e) => {
2135
+ if ((e.metaKey || e.ctrlKey) && e.key === ";") {
2136
+ e.preventDefault();
2137
+ triggerAddOrEditProperty(view, root, this.sectionId);
2138
+ return;
2139
+ }
2072
2140
  if (e.defaultPrevented) return;
2141
+ if (e.key === "Tab") {
2142
+ e.preventDefault();
2143
+ if (!e.shiftKey) {
2144
+ commitKey(true);
2145
+ row.querySelector('input[data-frontmatter-field="value"]')?.focus();
2146
+ } else if (idxInEntries > 0) {
2147
+ commitKey(false);
2148
+ const prevKey = entryKeys[idxInEntries - 1];
2149
+ box.querySelector(`[data-frontmatter-row="${prevKey}"] input[data-frontmatter-field="value"]`)?.focus();
2150
+ } else {
2151
+ commitKey(false);
2152
+ root.querySelector('button[aria-label="Show property summary"]')?.focus();
2153
+ }
2154
+ return;
2155
+ }
2073
2156
  if (e.key === "Enter") {
2074
2157
  e.preventDefault();
2075
- keyInput.blur();
2158
+ commitKey(true);
2159
+ row.querySelector('input[data-frontmatter-field="value"]')?.focus();
2160
+ return;
2161
+ }
2162
+ if (e.key === "ArrowDown") {
2163
+ if (keyInput.getAttribute("aria-expanded") === "true") return;
2164
+ e.preventDefault();
2165
+ if (idxInEntries < entries.length - 1) {
2166
+ const nextKey = entryKeys[idxInEntries + 1];
2167
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="key"]`)?.focus();
2168
+ } else {
2169
+ root.querySelector('button[aria-label="Add property"]')?.focus();
2170
+ }
2171
+ return;
2172
+ }
2173
+ if (e.key === "ArrowUp") {
2174
+ if (keyInput.getAttribute("aria-expanded") === "true") return;
2175
+ e.preventDefault();
2176
+ if (idxInEntries > 0) {
2177
+ const prevKey = entryKeys[idxInEntries - 1];
2178
+ box.querySelector(`[data-frontmatter-row="${prevKey}"] input[data-frontmatter-field="key"]`)?.focus();
2179
+ }
2180
+ return;
2076
2181
  }
2077
2182
  });
2078
2183
  const focus = pendingFocus.get(view);
@@ -2096,7 +2201,7 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2096
2201
  if (!referenceProvider) return null;
2097
2202
  return valueKind === "effort" ? referenceProvider.resolveEffort(token) : valueKind === "equipment" ? referenceProvider.resolveEquipment(token) : null;
2098
2203
  };
2099
- if (isTags || isReferenceList) {
2204
+ if (isChipList) {
2100
2205
  const chips = parseTagList(value);
2101
2206
  const chipIsReference = valueKind !== "tags";
2102
2207
  const isAliasRow = isAliasProperty(key);
@@ -2104,24 +2209,25 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2104
2209
  const chip = chips[idx];
2105
2210
  const match = chipIsReference ? refMatch(chip) : null;
2106
2211
  const pill = document.createElement("span");
2107
- 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";
2212
+ 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";
2108
2213
  const pillText = document.createElement("span");
2109
2214
  pillText.textContent = isAliasRow ? chip : match ? match.label : chip;
2110
2215
  pill.appendChild(pillText);
2111
- if (match && referenceProvider) {
2216
+ if (match && referenceProvider && (!isAliasRow || idx === 0)) {
2112
2217
  const openLink = document.createElement("a");
2113
2218
  openLink.href = referenceProvider.openHref(valueKind, match.slug);
2114
2219
  openLink.title = `Open ${match.label} page`;
2115
2220
  openLink.setAttribute("aria-label", `Open ${match.label} page`);
2116
- openLink.className = "inline-flex items-center justify-center text-muted-foreground/60 hover:text-foreground cursor-pointer";
2221
+ 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";
2117
2222
  openLink.appendChild(createExternalIcon());
2118
2223
  pill.appendChild(openLink);
2119
2224
  }
2120
2225
  if (!this.readOnly) {
2121
2226
  const rmBtn = document.createElement("button");
2122
2227
  rmBtn.type = "button";
2228
+ rmBtn.tabIndex = -1;
2123
2229
  rmBtn.setAttribute("aria-label", isTags ? `Remove tag ${chip}` : `Remove ${chip}`);
2124
- rmBtn.className = "inline-flex items-center justify-center text-muted-foreground/60 hover:text-foreground dark:hover:text-foreground cursor-pointer";
2230
+ rmBtn.className = "inline-flex items-center justify-center text-muted-foreground/50 hover:text-destructive cursor-pointer transition-colors";
2125
2231
  rmBtn.appendChild(createCloseIcon("sm"));
2126
2232
  rmBtn.addEventListener("click", (e) => {
2127
2233
  e.preventDefault();
@@ -2134,7 +2240,7 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2134
2240
  }
2135
2241
  if (!this.readOnly) {
2136
2242
  const chipInput = document.createElement("input");
2137
- 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";
2243
+ 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";
2138
2244
  chipInput.placeholder = chips.length === 0 ? isReferenceList ? `Add ${valueKind === "effort" ? "effort" : "equipment"}\u2026` : "Add tags\u2026" : isTags ? "Add tag\u2026" : "Add\u2026";
2139
2245
  chipInput.setAttribute("aria-label", `Value for ${key}`);
2140
2246
  chipInput.dataset.frontmatterField = "value";
@@ -2157,21 +2263,78 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2157
2263
  valCol.appendChild(chipInput);
2158
2264
  attachSuggestions(chipInput, view, root, "value", key, chips, commitNewChip, valueKind);
2159
2265
  chipInput.addEventListener("keydown", (e) => {
2266
+ if ((e.metaKey || e.ctrlKey) && e.key === ";") {
2267
+ e.preventDefault();
2268
+ triggerAddOrEditProperty(view, root, this.sectionId);
2269
+ return;
2270
+ }
2160
2271
  if (e.defaultPrevented) return;
2161
- if (e.key === "Enter" || e.key === ",") {
2272
+ if ((e.key === "Enter" || e.key === ",") && chipInput.value.trim()) {
2162
2273
  e.preventDefault();
2163
2274
  commitNewChip();
2164
- } else if (e.key === "Backspace" && !chipInput.value && chips.length > 0) {
2275
+ return;
2276
+ }
2277
+ if (e.key === "Backspace" && !chipInput.value && chips.length > 0) {
2165
2278
  e.preventDefault();
2166
2279
  pendingFocus.set(view, { kind: "tag", key });
2167
2280
  commitList(chips.slice(0, -1));
2281
+ return;
2282
+ }
2283
+ if (e.key === "Tab") {
2284
+ if (chipInput.value.trim() && !e.shiftKey) {
2285
+ e.preventDefault();
2286
+ commitNewChip();
2287
+ return;
2288
+ }
2289
+ e.preventDefault();
2290
+ if (!e.shiftKey) {
2291
+ if (idxInEntries < entries.length - 1) {
2292
+ const nextKey = entryKeys[idxInEntries + 1];
2293
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="key"]`)?.focus();
2294
+ } else {
2295
+ root.querySelector('button[aria-label="Add property"]')?.focus();
2296
+ }
2297
+ } else {
2298
+ row.querySelector('input[data-frontmatter-field="key"]')?.focus();
2299
+ }
2300
+ return;
2301
+ }
2302
+ if (e.key === "Enter") {
2303
+ e.preventDefault();
2304
+ if (idxInEntries < entries.length - 1) {
2305
+ const nextKey = entryKeys[idxInEntries + 1];
2306
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="key"]`)?.focus();
2307
+ } else {
2308
+ root.querySelector('button[aria-label="Add property"]')?.click();
2309
+ }
2310
+ return;
2311
+ }
2312
+ if (e.key === "ArrowDown") {
2313
+ if (chipInput.getAttribute("aria-expanded") === "true") return;
2314
+ e.preventDefault();
2315
+ if (idxInEntries < entries.length - 1) {
2316
+ const nextKey = entryKeys[idxInEntries + 1];
2317
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="value"]`)?.focus();
2318
+ } else {
2319
+ exitToEditorBody(view);
2320
+ }
2321
+ return;
2322
+ }
2323
+ if (e.key === "ArrowUp") {
2324
+ if (chipInput.getAttribute("aria-expanded") === "true") return;
2325
+ e.preventDefault();
2326
+ if (idxInEntries > 0) {
2327
+ const prevKey = entryKeys[idxInEntries - 1];
2328
+ box.querySelector(`[data-frontmatter-row="${prevKey}"] input[data-frontmatter-field="value"]`)?.focus();
2329
+ }
2330
+ return;
2168
2331
  }
2169
2332
  });
2170
2333
  chipInput.addEventListener("blur", () => queueMicrotask(() => {
2171
2334
  if (chipInput.isConnected && chipInput.value.trim()) commitNewChip();
2172
2335
  }));
2173
2336
  const focus = pendingFocus.get(view);
2174
- if (focus?.kind === "tag" && focus.key === key) {
2337
+ if ((focus?.kind === "tag" || focus?.kind === "value") && focus.key === key) {
2175
2338
  setTimeout(() => {
2176
2339
  if (chipInput.isConnected) chipInput.focus();
2177
2340
  }, 0);
@@ -2218,8 +2381,9 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2218
2381
  valCol.appendChild(valSpan);
2219
2382
  } else {
2220
2383
  const valInput = document.createElement("input");
2221
- 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";
2384
+ 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";
2222
2385
  valInput.value = strVal;
2386
+ valInput.placeholder = "Empty";
2223
2387
  valInput.spellcheck = false;
2224
2388
  valInput.setAttribute("aria-label", `Value for ${key}`);
2225
2389
  valInput.dataset.frontmatterField = "value";
@@ -2229,13 +2393,18 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2229
2393
  appendFieldHelper(valCol, "Property value. Press Enter to apply.").id
2230
2394
  );
2231
2395
  let committedVal = strVal;
2232
- const commitVal = () => {
2396
+ const commitVal = (pendingNextKey) => {
2233
2397
  const cur = valInput.value.trim();
2234
2398
  if (cur !== committedVal) {
2235
2399
  committedVal = cur;
2236
2400
  const num = Number(cur);
2237
2401
  const next = cur !== "" && !isNaN(num) ? num : cur;
2238
2402
  meta[key] = next;
2403
+ if (typeof pendingNextKey === "string") {
2404
+ pendingFocus.set(view, { kind: "key", key: pendingNextKey });
2405
+ } else if (pendingNextKey === true) {
2406
+ pendingFocus.set(view, { kind: "value", key });
2407
+ }
2239
2408
  patchPropertyInView(view, this.sectionId, [key], next);
2240
2409
  }
2241
2410
  };
@@ -2256,29 +2425,85 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2256
2425
  );
2257
2426
  valInput.addEventListener("blur", commitValIfAttached);
2258
2427
  valInput.addEventListener("keydown", (e) => {
2428
+ if ((e.metaKey || e.ctrlKey) && e.key === ";") {
2429
+ e.preventDefault();
2430
+ triggerAddOrEditProperty(view, root, this.sectionId);
2431
+ return;
2432
+ }
2259
2433
  if (e.defaultPrevented) return;
2434
+ if (e.key === "Tab") {
2435
+ e.preventDefault();
2436
+ if (!e.shiftKey) {
2437
+ if (idxInEntries < entries.length - 1) {
2438
+ const nextKey = entryKeys[idxInEntries + 1];
2439
+ commitVal(nextKey);
2440
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="key"]`)?.focus();
2441
+ } else {
2442
+ commitVal();
2443
+ root.querySelector('button[aria-label="Add property"]')?.focus();
2444
+ }
2445
+ } else {
2446
+ commitVal();
2447
+ row.querySelector('input[data-frontmatter-field="key"]')?.focus();
2448
+ }
2449
+ return;
2450
+ }
2260
2451
  if (e.key === "Enter") {
2261
2452
  e.preventDefault();
2262
- valInput.blur();
2453
+ if (idxInEntries < entries.length - 1) {
2454
+ const nextKey = entryKeys[idxInEntries + 1];
2455
+ commitVal(nextKey);
2456
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="key"]`)?.focus();
2457
+ } else {
2458
+ commitVal();
2459
+ root.querySelector('button[aria-label="Add property"]')?.click();
2460
+ }
2461
+ return;
2462
+ }
2463
+ if (e.key === "ArrowDown") {
2464
+ if (valInput.getAttribute("aria-expanded") === "true") return;
2465
+ e.preventDefault();
2466
+ if (idxInEntries < entries.length - 1) {
2467
+ const nextKey = entryKeys[idxInEntries + 1];
2468
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="value"]`)?.focus();
2469
+ } else {
2470
+ exitToEditorBody(view);
2471
+ }
2472
+ return;
2473
+ }
2474
+ if (e.key === "ArrowUp") {
2475
+ if (valInput.getAttribute("aria-expanded") === "true") return;
2476
+ e.preventDefault();
2477
+ if (idxInEntries > 0) {
2478
+ const prevKey = entryKeys[idxInEntries - 1];
2479
+ box.querySelector(`[data-frontmatter-row="${prevKey}"] input[data-frontmatter-field="value"]`)?.focus();
2480
+ }
2481
+ return;
2263
2482
  }
2264
2483
  });
2484
+ const focus = pendingFocus.get(view);
2485
+ if (focus?.kind === "value" && focus.key === key) {
2486
+ setTimeout(() => {
2487
+ if (!valInput.isConnected) return;
2488
+ valInput.focus();
2489
+ valInput.select?.();
2490
+ }, 0);
2491
+ pendingFocus.delete(view);
2492
+ }
2265
2493
  if (key.trim().toLowerCase() === "metrics.effort" && referenceProvider) {
2266
2494
  const match = referenceProvider.resolveEffort(strVal);
2267
2495
  if (match) {
2268
- const pill = document.createElement("span");
2269
- 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";
2270
- const pillText = document.createElement("span");
2271
- pillText.textContent = match.label;
2272
- pill.appendChild(pillText);
2496
+ 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";
2273
2497
  const openLink = document.createElement("a");
2274
2498
  openLink.href = referenceProvider.openHref("effort", match.slug);
2275
2499
  openLink.title = `Open ${match.label} page`;
2276
2500
  openLink.setAttribute("aria-label", `Open ${match.label} page`);
2277
- openLink.className = "inline-flex items-center justify-center text-muted-foreground/60 hover:text-foreground cursor-pointer";
2501
+ 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";
2502
+ const linkLabel = document.createElement("span");
2503
+ linkLabel.textContent = match.label;
2504
+ openLink.appendChild(linkLabel);
2278
2505
  openLink.appendChild(createExternalIcon());
2279
- pill.appendChild(openLink);
2280
- valCol.insertBefore(pill, valInput);
2281
- 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";
2506
+ valCol.appendChild(openLink);
2282
2507
  }
2283
2508
  const diag = renderEffortValueDiagnostics(
2284
2509
  referenceProvider,
@@ -2308,6 +2533,7 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2308
2533
  actionsCol.className = "flex items-center pr-2";
2309
2534
  const delBtn = document.createElement("button");
2310
2535
  delBtn.type = "button";
2536
+ delBtn.tabIndex = -1;
2311
2537
  delBtn.setAttribute("aria-label", `Remove property ${key}`);
2312
2538
  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";
2313
2539
  delBtn.appendChild(createCloseIcon("md"));
@@ -2321,9 +2547,6 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2321
2547
  row.appendChild(actionsCol);
2322
2548
  }
2323
2549
  }
2324
- if (docKind === "effort" && !this.readOnly) {
2325
- box.appendChild(this.buildDefinitionRows(view, base));
2326
- }
2327
2550
  }
2328
2551
  if (!this.readOnly) {
2329
2552
  const existingTagKey = entries.find(([key]) => key.trim().toLowerCase() === "tags")?.[0] ?? entries.find(([key]) => isTagProperty(key))?.[0];
@@ -2341,6 +2564,10 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2341
2564
  addBtn.addEventListener("click", (e) => {
2342
2565
  e.preventDefault();
2343
2566
  e.stopPropagation();
2567
+ if (!this.detailed) {
2568
+ persistedDetailed.set(view.dom, true);
2569
+ view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2570
+ }
2344
2571
  let newKey = "property";
2345
2572
  let count2 = 1;
2346
2573
  while (newKey in meta) {
@@ -2348,13 +2575,24 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2348
2575
  newKey = `property_${count2}`;
2349
2576
  }
2350
2577
  pendingFocus.set(view, { kind: "key", key: newKey });
2351
- patchPropertyInView(view, this.sectionId, [newKey], "", !this.detailed);
2352
- const keyField = view.dom.querySelector(
2578
+ patchPropertyInView(view, this.sectionId, [newKey], "", true);
2579
+ const activeRoot = view.dom.querySelector(".cm-frontmatter-preview") ?? root;
2580
+ const keyField = activeRoot.querySelector(
2353
2581
  `[data-frontmatter-row="${newKey}"] [data-frontmatter-field="key"]`
2354
2582
  );
2355
2583
  keyField?.focus();
2356
2584
  keyField?.select();
2357
2585
  });
2586
+ addBtn.addEventListener("keydown", (e) => {
2587
+ if (e.key === "ArrowDown" || e.key === "Tab" && !e.shiftKey) {
2588
+ e.preventDefault();
2589
+ exitToEditorBody(view);
2590
+ } else if (e.key === "ArrowUp" || e.key === "Tab" && e.shiftKey) {
2591
+ e.preventDefault();
2592
+ const allInputs = box.querySelectorAll("input[data-frontmatter-field]:not([disabled])");
2593
+ allInputs[allInputs.length - 1]?.focus();
2594
+ }
2595
+ });
2358
2596
  actionsRow.appendChild(addBtn);
2359
2597
  {
2360
2598
  const addMetricBtn = document.createElement("button");
@@ -2369,6 +2607,7 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2369
2607
  addMetricBtn.addEventListener("click", (e) => {
2370
2608
  e.preventDefault();
2371
2609
  e.stopPropagation();
2610
+ persistedDetailed.set(view.dom, true);
2372
2611
  if (!this.detailed) {
2373
2612
  view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2374
2613
  }
@@ -2401,6 +2640,7 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2401
2640
  addSummaryBtn.addEventListener("click", (e) => {
2402
2641
  e.preventDefault();
2403
2642
  e.stopPropagation();
2643
+ persistedDetailed.set(view.dom, true);
2404
2644
  if (!this.detailed) {
2405
2645
  view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2406
2646
  }
@@ -2412,7 +2652,7 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2412
2652
  return;
2413
2653
  }
2414
2654
  const draftRow = createSummaryDraftRow(view, (path, value) => {
2415
- patchPropertyInView(view, this.sectionId, path, value);
2655
+ patchPropertyInView(view, this.sectionId, path, value, true);
2416
2656
  });
2417
2657
  activeBox.appendChild(draftRow);
2418
2658
  draftRow.querySelector("input")?.focus();
@@ -2432,6 +2672,7 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2432
2672
  addTagBtn.addEventListener("click", (e) => {
2433
2673
  e.preventDefault();
2434
2674
  e.stopPropagation();
2675
+ persistedDetailed.set(view.dom, true);
2435
2676
  if (!this.detailed) {
2436
2677
  view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2437
2678
  }
@@ -2481,90 +2722,18 @@ var DefaultFrontmatterWidget = class extends view.WidgetType {
2481
2722
  });
2482
2723
  view.focus();
2483
2724
  });
2725
+ editYamlBtn.addEventListener("keydown", (e) => {
2726
+ if (e.key === "ArrowDown" || e.key === "Tab" && !e.shiftKey) {
2727
+ e.preventDefault();
2728
+ exitToEditorBody(view);
2729
+ }
2730
+ });
2484
2731
  actionsRow.appendChild(editYamlBtn);
2485
2732
  }
2486
2733
  root.appendChild(actionsRow);
2487
2734
  }
2488
2735
  return root;
2489
2736
  }
2490
- /**
2491
- * Effort-definition attribute rows (MET / discipline / intensity tier).
2492
- * Values live in the nested baseAttributes block; each edit patches that
2493
- * one path, so unknown sibling keys and comments elsewhere survive.
2494
- */
2495
- buildDefinitionRows(view, base) {
2496
- const wrap = document.createElement("div");
2497
- wrap.setAttribute("data-frontmatter-definition", "true");
2498
- wrap.className = "border-t border-dashed border-border/60";
2499
- const header = document.createElement("div");
2500
- header.className = "px-3 pt-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground";
2501
- header.textContent = "Definition";
2502
- wrap.appendChild(header);
2503
- const commitField = (field, raw) => {
2504
- if (field === "met") {
2505
- const num = Number(raw);
2506
- const path2 = base.hasBaseBlock ? ["baseAttributes", "met"] : ["metrics.met"];
2507
- patchPropertyInView(view, this.sectionId, path2, raw !== "" && !Number.isNaN(num) ? num : null);
2508
- return;
2509
- }
2510
- const path = base.hasBaseBlock ? ["baseAttributes", field] : [field];
2511
- patchPropertyInView(view, this.sectionId, path, raw === "" ? null : raw);
2512
- };
2513
- const fieldRow = (label, child) => {
2514
- const row = document.createElement("label");
2515
- 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";
2516
- const name = document.createElement("span");
2517
- name.className = "w-28 shrink-0 text-muted-foreground";
2518
- name.textContent = label;
2519
- row.appendChild(name);
2520
- child.className = "flex-1 min-w-0 bg-transparent text-xs text-foreground outline-none py-0.5";
2521
- row.appendChild(child);
2522
- wrap.appendChild(row);
2523
- };
2524
- const met = document.createElement("input");
2525
- met.type = "number";
2526
- met.step = "0.1";
2527
- met.inputMode = "decimal";
2528
- met.value = base.met ?? "";
2529
- met.setAttribute("aria-label", "MET value");
2530
- met.addEventListener("change", () => queueMicrotask(() => {
2531
- if (met.isConnected) commitField("met", met.value.trim());
2532
- }));
2533
- fieldRow("MET", met);
2534
- const discipline = document.createElement("select");
2535
- discipline.setAttribute("aria-label", "Discipline");
2536
- discipline.className = "flex-1 min-w-0 rounded-md border border-input bg-background px-1.5 text-[11px] text-muted-foreground outline-none";
2537
- const unset = document.createElement("option");
2538
- unset.value = "";
2539
- unset.textContent = "Unset";
2540
- discipline.appendChild(unset);
2541
- for (const option of wodWikiLang.EFFORT_DISCIPLINES) {
2542
- const opt = document.createElement("option");
2543
- opt.value = option;
2544
- opt.textContent = option;
2545
- discipline.appendChild(opt);
2546
- }
2547
- discipline.value = base.discipline ?? "";
2548
- discipline.addEventListener("change", () => commitField("discipline", discipline.value));
2549
- fieldRow("Discipline", discipline);
2550
- const tier = document.createElement("select");
2551
- tier.setAttribute("aria-label", "Intensity tier");
2552
- tier.className = "flex-1 min-w-0 rounded-md border border-input bg-background px-1.5 text-[11px] text-muted-foreground outline-none";
2553
- const tierUnset = document.createElement("option");
2554
- tierUnset.value = "";
2555
- tierUnset.textContent = "Unset";
2556
- tier.appendChild(tierUnset);
2557
- for (const option of ["low", "moderate", "high"]) {
2558
- const opt = document.createElement("option");
2559
- opt.value = option;
2560
- opt.textContent = option;
2561
- tier.appendChild(opt);
2562
- }
2563
- tier.value = base.intensityTier ?? "";
2564
- tier.addEventListener("change", () => commitField("intensityTier", tier.value));
2565
- fieldRow("Intensity tier", tier);
2566
- return wrap;
2567
- }
2568
2737
  destroy(dom) {
2569
2738
  widgetCleanup.get(dom)?.forEach((close) => close());
2570
2739
  widgetCleanup.delete(dom);
@@ -2603,14 +2772,23 @@ var EmptyFrontmatterWidget = class extends view.WidgetType {
2603
2772
  addBtn.addEventListener("click", (e) => {
2604
2773
  e.preventDefault();
2605
2774
  e.stopPropagation();
2775
+ persistedDetailed.set(view.dom, true);
2776
+ view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2606
2777
  pendingFocus.set(view, { kind: "key", key: "property" });
2607
2778
  patchPropertyInView(view, "new", ["property"], "", true);
2608
- const keyField = view.dom.querySelector(
2779
+ const activeRoot = view.dom.querySelector(".cm-frontmatter-preview") ?? root;
2780
+ const keyField = activeRoot.querySelector(
2609
2781
  '[data-frontmatter-row="property"] [data-frontmatter-field="key"]'
2610
2782
  );
2611
2783
  keyField?.focus();
2612
2784
  keyField?.select();
2613
2785
  });
2786
+ addBtn.addEventListener("keydown", (e) => {
2787
+ if (e.key === "ArrowDown" || e.key === "Tab" && !e.shiftKey) {
2788
+ e.preventDefault();
2789
+ exitToEditorBody(view);
2790
+ }
2791
+ });
2614
2792
  actionsRow.appendChild(addBtn);
2615
2793
  const addMetricBtn = document.createElement("button");
2616
2794
  addMetricBtn.type = "button";
@@ -2624,6 +2802,7 @@ var EmptyFrontmatterWidget = class extends view.WidgetType {
2624
2802
  addMetricBtn.addEventListener("click", (e) => {
2625
2803
  e.preventDefault();
2626
2804
  e.stopPropagation();
2805
+ persistedDetailed.set(view.dom, true);
2627
2806
  if (!this.detailed) view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2628
2807
  const activeRoot = view.dom.querySelector(".cm-frontmatter-preview") ?? root;
2629
2808
  const existing = activeRoot.querySelector("[data-frontmatter-metric-draft] input");
@@ -2653,6 +2832,7 @@ var EmptyFrontmatterWidget = class extends view.WidgetType {
2653
2832
  addSummaryBtn.addEventListener("click", (e) => {
2654
2833
  e.preventDefault();
2655
2834
  e.stopPropagation();
2835
+ persistedDetailed.set(view.dom, true);
2656
2836
  if (!this.detailed) view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2657
2837
  const activeRoot = view.dom.querySelector(".cm-frontmatter-preview") ?? root;
2658
2838
  const existing = activeRoot.querySelector("[data-frontmatter-summary-draft] input");
@@ -2714,14 +2894,16 @@ function buildFrontmatterDecos(state$1) {
2714
2894
  builder.add(section.from, to, view.Decoration.replace({ block: true }));
2715
2895
  continue;
2716
2896
  }
2717
- const selected = !state$1.readOnly && (state$1.field(frontmatterSource) || state$1.selection.ranges.some((range) => range.from < section.to && range.to > section.from));
2897
+ const detailed = state$1.field(frontmatterDetailed);
2898
+ const selected = !state$1.readOnly && state$1.field(frontmatterSource);
2718
2899
  if (selected) continue;
2719
2900
  const rawContent = state$1.doc.sliceString(section.from, section.to);
2901
+ const debugMode = state$1.facet(frontmatterDebugMode);
2720
2902
  builder.add(
2721
2903
  section.from,
2722
2904
  section.to,
2723
2905
  view.Decoration.replace({
2724
- widget: new DefaultFrontmatterWidget(section.id, rawContent, state$1.readOnly, state$1.field(frontmatterDetailed)),
2906
+ widget: new DefaultFrontmatterWidget(section.id, rawContent, state$1.readOnly, detailed, debugMode),
2725
2907
  block: true
2726
2908
  })
2727
2909
  );
@@ -2756,7 +2938,85 @@ var frontmatterPreviewField = state.StateField.define({
2756
2938
  )
2757
2939
  ]
2758
2940
  });
2759
- var frontmatterPreview = [frontmatterDetailed, frontmatterSource, frontmatterPreviewField];
2941
+ var frontmatterDetailSync = view.EditorView.updateListener.of((update) => {
2942
+ const current = update.state.field(frontmatterDetailed);
2943
+ const prev = update.startState.field(frontmatterDetailed);
2944
+ if (current !== prev) {
2945
+ if (update.transactions.some((tr) => tr.effects.some((e) => e.is(setFrontmatterDetailed)))) {
2946
+ persistedDetailed.set(update.view.dom, current);
2947
+ } else if (persistedDetailed.get(update.view.dom) === true && !current) {
2948
+ queueMicrotask(() => {
2949
+ if (update.view.state.field(frontmatterDetailed) === false) {
2950
+ update.view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2951
+ }
2952
+ });
2953
+ }
2954
+ } else if (persistedDetailed.get(update.view.dom) === true && !current) {
2955
+ queueMicrotask(() => {
2956
+ if (update.view.state.field(frontmatterDetailed) === false) {
2957
+ update.view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2958
+ }
2959
+ });
2960
+ }
2961
+ });
2962
+ var frontmatterKeymap = state.Prec.highest(
2963
+ view.keymap.of([
2964
+ {
2965
+ key: "Mod-;",
2966
+ run(view) {
2967
+ if (view.state.readOnly) return false;
2968
+ triggerAddOrEditProperty(view);
2969
+ return true;
2970
+ }
2971
+ },
2972
+ {
2973
+ key: "ArrowUp",
2974
+ run(view) {
2975
+ if (view.state.readOnly) return false;
2976
+ if (view.state.field(frontmatterSource)) return false;
2977
+ if (!view.state.facet(frontmatterVisibility)) return false;
2978
+ const { head } = view.state.selection.main;
2979
+ const { sections } = view.state.field(sectionField);
2980
+ const fm = sections.find((s) => s.type === "frontmatter");
2981
+ if (!fm) return false;
2982
+ const cursorLine = view.state.doc.lineAt(head);
2983
+ const fmEndLine = view.state.doc.lineAt(fm.to);
2984
+ if (cursorLine.number > fmEndLine.number + 1) return false;
2985
+ const allInputs = view.dom.querySelectorAll(
2986
+ ".cm-frontmatter-preview input[data-frontmatter-field]:not([disabled])"
2987
+ );
2988
+ if (allInputs.length === 0) {
2989
+ const addBtn = view.dom.querySelector(
2990
+ '.cm-frontmatter-preview button[aria-label="Add property"]'
2991
+ );
2992
+ if (addBtn) {
2993
+ addBtn.focus();
2994
+ return true;
2995
+ }
2996
+ const detailsBtn = view.dom.querySelector(
2997
+ '.cm-frontmatter-preview button[aria-label="Show property details"]'
2998
+ );
2999
+ if (detailsBtn) {
3000
+ detailsBtn.focus();
3001
+ return true;
3002
+ }
3003
+ return false;
3004
+ }
3005
+ const target = allInputs[allInputs.length - 1];
3006
+ target.focus();
3007
+ target.select?.();
3008
+ return true;
3009
+ }
3010
+ }
3011
+ ])
3012
+ );
3013
+ var frontmatterPreview = [
3014
+ frontmatterDetailed,
3015
+ frontmatterSource,
3016
+ frontmatterPreviewField,
3017
+ frontmatterDetailSync,
3018
+ frontmatterKeymap
3019
+ ];
2760
3020
  var HEADING_RE = /^(#{1,6}) /;
2761
3021
  var BOLD_RE = /\*\*([^*\n]+)\*\*/g;
2762
3022
  var ITALIC_STAR_RE = /(?<!\*)\*([^*\n]+)\*(?!\*)/g;
@@ -13629,6 +13889,7 @@ Object.defineProperty(exports, "blockContentId", {
13629
13889
  get: function () { return wodWikiCore.blockContentId; }
13630
13890
  });
13631
13891
  exports.DefaultFrontmatterWidget = DefaultFrontmatterWidget;
13892
+ exports.INTERNAL_FRONTMATTER_KEYS = INTERNAL_FRONTMATTER_KEYS;
13632
13893
  exports.activeCursorSection = activeCursorSection;
13633
13894
  exports.addRuntimePanel = addRuntimePanel;
13634
13895
  exports.autocompleteTooltipTheme = autocompleteTooltipTheme;
@@ -13648,7 +13909,9 @@ exports.fenceCompletion = fenceCompletion;
13648
13909
  exports.findQueryBlockSection = findQueryBlockSection;
13649
13910
  exports.findWorkoutErrors = findWorkoutErrors;
13650
13911
  exports.forceSectionParse = forceSectionParse;
13912
+ exports.frontmatterDebugMode = frontmatterDebugMode;
13651
13913
  exports.frontmatterDetailed = frontmatterDetailed;
13914
+ exports.frontmatterKeymap = frontmatterKeymap;
13652
13915
  exports.frontmatterPreview = frontmatterPreview;
13653
13916
  exports.frontmatterPreviewField = frontmatterPreviewField;
13654
13917
  exports.frontmatterReferenceIndex = frontmatterReferenceIndex;
@@ -13661,6 +13924,7 @@ exports.gutterHighlightsField = gutterHighlightsField;
13661
13924
  exports.gutterUnified = gutterUnified;
13662
13925
  exports.handleFenceAutoWrap = handleFenceAutoWrap;
13663
13926
  exports.inlineButtonDecoration = inlineButtonDecoration;
13927
+ exports.isInternalFrontmatterKey = isInternalFrontmatterKey;
13664
13928
  exports.lineIdsExtension = lineIdsExtension;
13665
13929
  exports.linkOpen = linkOpen;
13666
13930
  exports.linkPreview = linkPreview;