@open-document/core 0.13.0 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { n as readCoreVersion } from "./package-version-C89gtYSk.js";
2
2
  import { n as loadUserConfig } from "./open-doc-plugin-DnX5usgI.js";
3
- import { N as makeContext } from "./config-DKKNIbvO.js";
3
+ import { L as makeContext } from "./config-CltJJVsw.js";
4
4
  //#region src/cli/context.ts
5
5
  /** The same context the dev API and the MCP server run on, for commands that call `ops/`. */
6
6
  async function cliContext(userCwd = process.cwd()) {
@@ -1,4 +1,4 @@
1
- import { t as createViteConfig } from "./config-DKKNIbvO.js";
1
+ import { t as createViteConfig } from "./config-CltJJVsw.js";
2
2
  import { createServer, mergeConfig } from "vite";
3
3
  //#region src/cli/dev.ts
4
4
  async function dev(opts = {}) {
@@ -1,5 +1,5 @@
1
- import { s as diffDocument } from "./ops-DmEecq1k.js";
2
- import { t as cliContext } from "./context-DXNP8v9I.js";
1
+ import { s as diffDocument } from "./ops-CSR5RlrE.js";
2
+ import { t as cliContext } from "./context-CWgfsHoE.js";
3
3
  import chalk from "chalk";
4
4
  //#region src/cli/diff.ts
5
5
  const MARK = {
@@ -1,7 +1,7 @@
1
1
  import { r as EXPORT_FORMATS } from "./sdk-CqNZzbkz.js";
2
- import { D as listDocIds } from "./config-DKKNIbvO.js";
3
- import { n as closeRenderSession, r as exportDocument } from "./ops-DmEecq1k.js";
4
- import { t as cliContext } from "./context-DXNP8v9I.js";
2
+ import { j as listDocIds } from "./config-CltJJVsw.js";
3
+ import { n as closeRenderSession, r as exportDocument } from "./ops-CSR5RlrE.js";
4
+ import { t as cliContext } from "./context-CWgfsHoE.js";
5
5
  import chalk from "chalk";
6
6
  //#region src/cli/export.ts
7
7
  const FORMATS = EXPORT_FORMATS;
@@ -1,5 +1,5 @@
1
- import { a as importMarkdown } from "./ops-DmEecq1k.js";
2
- import { t as cliContext } from "./context-DXNP8v9I.js";
1
+ import { a as importMarkdown } from "./ops-CSR5RlrE.js";
2
+ import { t as cliContext } from "./context-CWgfsHoE.js";
3
3
  import chalk from "chalk";
4
4
  import path from "node:path";
5
5
  //#region src/cli/import.ts
package/dist/index.js CHANGED
@@ -1386,6 +1386,8 @@ function tokenStyle(kind) {
1386
1386
  default: return;
1387
1387
  }
1388
1388
  }
1389
+ /** Marks a framed component whose parts the Word export keeps inside one frame. */
1390
+ const PANEL_ATTR = "data-od-panel";
1389
1391
  /**
1390
1392
  * Print-ready syntax-highlighted code block with optional header bar, line
1391
1393
  * numbers, and highlighted lines. Uses `--od-*` variables so it harmonizes with
@@ -1396,6 +1398,7 @@ function CodeBlock({ code, children, lang, title, lineNumbers = false, highlight
1396
1398
  const highlighted = new Set(highlightLines ?? []);
1397
1399
  return /* @__PURE__ */ jsxs("div", {
1398
1400
  ...sourceAttrs(loc),
1401
+ [PANEL_ATTR]: "",
1399
1402
  className,
1400
1403
  style: {
1401
1404
  border: "1px solid var(--od-rule, #e5e7eb)",
@@ -93,6 +93,28 @@ declare function revertChange(ctx: ApiContext, docId: string, opts: {
93
93
  ok: true;
94
94
  }>;
95
95
  //#endregion
96
+ //#region src/ops/concurrency.d.ts
97
+ /**
98
+ * Deterministic 16-char SHA-256 hex digest of a document's UTF-8 source.
99
+ * Used as a lightweight optimistic concurrency token (`hash` / `expectedHash`)
100
+ * so clients and MCP agents do not need to re-send the full source string.
101
+ */
102
+ declare function hashSource(source: string): string;
103
+ /**
104
+ * Verifies that `current` on disk still matches what the caller last read,
105
+ * either via full-source comparison (`expected`) or SHA-256 digest (`expectedHash`).
106
+ */
107
+ declare function assertExpectedSource(current: string, opts?: {
108
+ expected?: string;
109
+ expectedHash?: string;
110
+ }): void;
111
+ /**
112
+ * Serializes async read-modify-write operations on the same file path in FIFO order.
113
+ * Prevents concurrent edits (e.g. over high-latency GCS FUSE mounts or parallel
114
+ * MCP tool calls) from reading the same stale snapshot and overwriting each other.
115
+ */
116
+ declare function withFileLock<T>(filePath: string, fn: () => Promise<T>): Promise<T>;
117
+ //#endregion
96
118
  //#region src/app/lib/diagnostics.d.ts
97
119
  type LayoutRule = 'unresolved-ref' | 'duplicate-id' | 'heading-skip' | 'page-overflow' | 'off-page' | 'blank-page' | 'oversized-block' | 'orphan-heading' | 'tiny-text' | 'broken-image';
98
120
  type LayoutSeverity = 'error' | 'warn';
@@ -189,23 +211,30 @@ declare function readDocument(ctx: ApiContext, docId: string): Promise<{
189
211
  id: string;
190
212
  entry: string;
191
213
  source: string;
214
+ hash: string;
192
215
  }>;
193
216
  declare function createDocument(ctx: ApiContext, docId: string, source: string): Promise<{
194
217
  id: string;
195
218
  entry: string;
219
+ hash: string;
196
220
  }>;
197
221
  /**
198
- * Whole-file overwrite. `expected` is the source the caller believes is on
199
- * disk; passing it turns a blind overwrite into a conflict check, which is what
200
- * keeps two agents (or an agent and a person) from clobbering each other.
222
+ * Whole-file overwrite. `expected` (full source) or `expectedHash` (16-char
223
+ * SHA-256 digest from `readDocument`) turns a blind overwrite into an atomic
224
+ * conflict check inside a per-file write lock, keeping two agents (or an agent
225
+ * and a person on GCS FUSE) from clobbering each other.
201
226
  */
202
- declare function writeDocument(ctx: ApiContext, docId: string, source: string, expected?: string): Promise<{
227
+ declare function writeDocument(ctx: ApiContext, docId: string, source: string, expected?: string, expectedHash?: string): Promise<{
203
228
  id: string;
204
229
  entry: string;
230
+ hash: string;
205
231
  }>;
206
- declare function renameDocument(ctx: ApiContext, docId: string, rawTitle: unknown): Promise<{
232
+ declare function renameDocument(ctx: ApiContext, docId: string, rawTitle: unknown, opts?: {
233
+ expectedHash?: string;
234
+ }): Promise<{
207
235
  id: string;
208
236
  title: string;
237
+ hash: string;
209
238
  }>;
210
239
  declare function duplicateDocument(ctx: ApiContext, docId: string, newId?: string): Promise<{
211
240
  id: string;
@@ -383,6 +412,33 @@ declare function createFromTemplate(ctx: ApiContext, opts: {
383
412
  entry: string;
384
413
  }>;
385
414
  //#endregion
415
+ //#region src/app/lib/inspector/format.d.ts
416
+ /**
417
+ * The element panel's Format section, shared by the viewer and the dev server:
418
+ * which style keys it may write, which design tokens each one offers, and what
419
+ * a value has to look like before it is spliced into a document's source.
420
+ */
421
+ declare const STYLE_PROPS: readonly ["fontFamily", "fontSize", "fontWeight", "fontStyle", "textAlign", "lineHeight", "letterSpacing", "color", "background"];
422
+ type StyleProp = (typeof STYLE_PROPS)[number];
423
+ /** `null` takes the key off the element, so the value comes from wherever it did before. */
424
+ type StyleValue = string | number | null;
425
+ type StyleChanges = Partial<Record<StyleProp, StyleValue>>;
426
+ /** What the source says about one key: a literal, a design token, or code the panel can only show. */
427
+ type StyleSource = {
428
+ kind: 'literal';
429
+ value: string | number;
430
+ } | {
431
+ kind: 'token';
432
+ token: string;
433
+ } | {
434
+ kind: 'code';
435
+ code: string;
436
+ };
437
+ /** `from` names the shared style object the key comes from, when it is not the element's own. */
438
+ type StyleOrigin = StyleSource & {
439
+ from?: string;
440
+ };
441
+ //#endregion
386
442
  //#region src/editing/edit-ops.d.ts
387
443
  type EditTarget = {
388
444
  line: number;
@@ -414,6 +470,15 @@ type TextEditOutcome = {
414
470
  error: string;
415
471
  };
416
472
  //#endregion
473
+ //#region src/editing/style-ops.d.ts
474
+ type StyleEdit = EditTarget & {
475
+ /** The tag the viewer clicked; a mismatch means the location points elsewhere now. */
476
+ tag: string;
477
+ changes: StyleChanges;
478
+ /** What the viewer was shown for each changed key; a write over anything else is refused. */
479
+ expected?: Partial<Record<StyleProp, StyleOrigin | null>>;
480
+ };
481
+ //#endregion
417
482
  //#region src/ops/text.d.ts
418
483
  type Loc = {
419
484
  line: number;
@@ -428,17 +493,19 @@ declare function readText(ctx: ApiContext, docId: string, locs: Loc[], shown?: s
428
493
  /**
429
494
  * `expected` is the text the caller believes is there; when it no longer
430
495
  * matches the write is refused rather than silently overwriting someone else's
431
- * edit. `index` picks a run when the element mixes text and markup. A run that
432
- * carries code, emphasis or links must be written as `segments`, or the write
433
- * is refused rather than dropping the formatting.
496
+ * edit. `expectedHash` optionally verifies the file-level SHA-256 digest.
497
+ * All reads and writes on the same document are serialized via `withFileLock`.
434
498
  */
435
499
  declare function writeText(ctx: ApiContext, docId: string, loc: Loc, text: string, opts?: {
436
500
  index?: number;
437
501
  expected?: string;
502
+ expectedHash?: string;
503
+ shown?: string;
438
504
  segments?: TextSegment[];
439
505
  prop?: string;
440
506
  }): Promise<{
441
507
  ok: true;
508
+ hash: string;
442
509
  }>;
443
510
  /**
444
511
  * Several run replacements in one read and one write, so an editing session
@@ -446,12 +513,30 @@ declare function writeText(ctx: ApiContext, docId: string, loc: Loc, text: strin
446
513
  * that each re-paginate the document. Per-edit failures are reported, not
447
514
  * thrown: the edits that still apply are written.
448
515
  */
449
- declare function writeTexts(ctx: ApiContext, docId: string, edits: TextEdit[]): Promise<{
516
+ declare function writeTexts(ctx: ApiContext, docId: string, edits: TextEdit[], opts?: {
517
+ expectedHash?: string;
518
+ }): Promise<{
450
519
  results: TextEditOutcome[];
520
+ hash: string;
521
+ }>;
522
+ /**
523
+ * One save from the element panel: retyped text and style changes, located
524
+ * against the same read of the file and written once. Per-edit failures are
525
+ * reported, not thrown, like `writeTexts`.
526
+ */
527
+ declare function writeEdits(ctx: ApiContext, docId: string, texts: TextEdit[], styles: StyleEdit[], opts?: {
528
+ expectedHash?: string;
529
+ }): Promise<{
530
+ texts: TextEditOutcome[];
531
+ styles: TextEditOutcome[];
532
+ hash: string;
451
533
  }>;
452
534
  /** Leaves a `@doc-comment` marker in the source for a later agent pass to act on. */
453
- declare function addComment(ctx: ApiContext, docId: string, loc: Loc, note: string, hint?: string): Promise<{
535
+ declare function addComment(ctx: ApiContext, docId: string, loc: Loc, note: string, hint?: string, opts?: {
536
+ expectedHash?: string;
537
+ }): Promise<{
454
538
  id: string;
539
+ hash: string;
455
540
  }>;
456
541
  //#endregion
457
- export { type ApiContext, type AssetSummary, type ChangesResult, type DiffResult, type DocumentSummary, EXPORT_FORMATS, type ExportFormat, type ExportResult, type ImportMarkdownOptions, type ImportResult, type LayoutFinding, type LayoutReport, type Loc, ORIENTATIONS, OpsError, type Orientation, PAGE_SIZE_NAMES, type PageChange, type PageSizeName, type PageStatus, type Revision, type TemplateSummary, type ThemeSummary, addComment, checkLayout, closeRenderSession, createDocument, createFolder, createFromTemplate, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listRevisions, listTemplates, listThemes, makeContext, readChanges, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, revertChange, slugify, suggestDocId, writeAsset, writeDocument, writeText, writeTexts };
542
+ export { type ApiContext, type AssetSummary, type ChangesResult, type DiffResult, type DocumentSummary, EXPORT_FORMATS, type ExportFormat, type ExportResult, type ImportMarkdownOptions, type ImportResult, type LayoutFinding, type LayoutReport, type Loc, ORIENTATIONS, OpsError, type Orientation, PAGE_SIZE_NAMES, type PageChange, type PageSizeName, type PageStatus, type Revision, type TemplateSummary, type ThemeSummary, addComment, assertExpectedSource, checkLayout, closeRenderSession, createDocument, createFolder, createFromTemplate, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, hashSource, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listRevisions, listTemplates, listThemes, makeContext, readChanges, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, revertChange, slugify, suggestDocId, withFileLock, writeAsset, writeDocument, writeEdits, writeText, writeTexts };
package/dist/ops/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { i as ORIENTATIONS, o as PAGE_SIZE_NAMES, r as EXPORT_FORMATS } from "../sdk-CqNZzbkz.js";
2
- import { A as renameDocument, C as createDocument, D as listDocIds, E as duplicateDocument, M as writeDocument, N as makeContext, O as listDocuments, S as OpsError, T as docDir, _ as writeAsset, a as writeTexts, b as readChanges, c as suggestDocId, d as fileDocument, f as findAssetUsages, g as readTheme, h as listThemes, i as writeText, j as resolveEntry, k as readDocument, l as createFolder, m as listFolders, n as addComment, o as createFromTemplate, p as listAssets, r as readText, s as listTemplates, u as deleteAsset, w as deleteDocument, x as revertChange, y as listRevisions } from "../config-DKKNIbvO.js";
3
- import { a as importMarkdown, i as renderDocPage, n as closeRenderSession, o as slugify, r as exportDocument, s as diffDocument, t as checkLayout } from "../ops-DmEecq1k.js";
4
- export { EXPORT_FORMATS, ORIENTATIONS, OpsError, PAGE_SIZE_NAMES, addComment, checkLayout, closeRenderSession, createDocument, createFolder, createFromTemplate, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listRevisions, listTemplates, listThemes, makeContext, readChanges, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, revertChange, slugify, suggestDocId, writeAsset, writeDocument, writeText, writeTexts };
2
+ import { A as duplicateDocument, C as assertExpectedSource, D as createDocument, E as OpsError, F as resolveEntry, I as writeDocument, L as makeContext, M as listDocuments, N as readDocument, O as deleteDocument, P as renameDocument, S as revertChange, T as withFileLock, _ as readTheme, a as writeText, b as listRevisions, c as listTemplates, d as deleteAsset, f as fileDocument, g as listThemes, h as listFolders, i as writeEdits, j as listDocIds, k as docDir, l as suggestDocId, m as listAssets, n as addComment, o as writeTexts, p as findAssetUsages, r as readText, s as createFromTemplate, u as createFolder, v as writeAsset, w as hashSource, x as readChanges } from "../config-CltJJVsw.js";
3
+ import { a as importMarkdown, i as renderDocPage, n as closeRenderSession, o as slugify, r as exportDocument, s as diffDocument, t as checkLayout } from "../ops-CSR5RlrE.js";
4
+ export { EXPORT_FORMATS, ORIENTATIONS, OpsError, PAGE_SIZE_NAMES, addComment, assertExpectedSource, checkLayout, closeRenderSession, createDocument, createFolder, createFromTemplate, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, hashSource, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listRevisions, listTemplates, listThemes, makeContext, readChanges, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, revertChange, slugify, suggestDocId, withFileLock, writeAsset, writeDocument, writeEdits, writeText, writeTexts };
@@ -1,6 +1,6 @@
1
1
  import { c as isPageSizeName, i as ORIENTATIONS, o as PAGE_SIZE_NAMES, s as isOrientation } from "./sdk-CqNZzbkz.js";
2
2
  import { t as DOC_ID_RE } from "./open-doc-plugin-DnX5usgI.js";
3
- import { C as createDocument, D as listDocIds, S as OpsError, j as resolveEntry, t as createViteConfig, v as validateAssetName } from "./config-DKKNIbvO.js";
3
+ import { D as createDocument, E as OpsError, F as resolveEntry, j as listDocIds, t as createViteConfig, y as validateAssetName } from "./config-CltJJVsw.js";
4
4
  import path from "node:path";
5
5
  import fs from "node:fs/promises";
6
6
  import { existsSync } from "node:fs";
@@ -1,4 +1,4 @@
1
- import { t as createViteConfig } from "./config-DKKNIbvO.js";
1
+ import { t as createViteConfig } from "./config-CltJJVsw.js";
2
2
  import { mergeConfig, preview as preview$1 } from "vite";
3
3
  //#region src/cli/preview.ts
4
4
  async function preview(opts = {}) {
@@ -1,6 +1,6 @@
1
- import { o as createFromTemplate, s as listTemplates } from "./config-DKKNIbvO.js";
2
- import "./ops-DmEecq1k.js";
3
- import { t as cliContext } from "./context-DXNP8v9I.js";
1
+ import { c as listTemplates, s as createFromTemplate } from "./config-CltJJVsw.js";
2
+ import "./ops-CSR5RlrE.js";
3
+ import { t as cliContext } from "./context-CWgfsHoE.js";
4
4
  import chalk from "chalk";
5
5
  //#region src/cli/templates.ts
6
6
  /**
@@ -1,3 +1,3 @@
1
1
  import { r as openDocPlugin } from "../open-doc-plugin-DnX5usgI.js";
2
- import { t as createViteConfig } from "../config-DKKNIbvO.js";
2
+ import { t as createViteConfig } from "../config-CltJJVsw.js";
3
3
  export { createViteConfig, openDocPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-document/core",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "description": "Runtime and CLI for open-doc — write documents in docs/, we handle the pages, print layout, and export.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -126,6 +126,9 @@ function tokenStyle(kind: TokenKind): CSSProperties | undefined {
126
126
  }
127
127
  }
128
128
 
129
+ /** Marks a framed component whose parts the Word export keeps inside one frame. */
130
+ export const PANEL_ATTR = 'data-od-panel';
131
+
129
132
  /**
130
133
  * Print-ready syntax-highlighted code block with optional header bar, line
131
134
  * numbers, and highlighted lines. Uses `--od-*` variables so it harmonizes with
@@ -149,6 +152,7 @@ export function CodeBlock({
149
152
  return (
150
153
  <div
151
154
  {...sourceAttrs(loc)}
155
+ {...{ [PANEL_ATTR]: '' }}
152
156
  className={className}
153
157
  style={{
154
158
  border: '1px solid var(--od-rule, #e5e7eb)',