@hello-ai-company/editor-core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yuki Shibata
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @hello-ai-company/editor-core
2
+
3
+ Portable TypeScript document model, JSON serialization, and optional provider types.
4
+
5
+ This is a **small host-neutral document layer** — not a rich-text editor, not a React component, and not a BlockNote/UI package.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @hello-ai-company/editor-core
11
+ ```
12
+
13
+ Requirements: Node.js `>=20`, ESM. No runtime dependencies. No CommonJS export.
14
+
15
+ Until the first public npmjs publish, pack from this repository:
16
+
17
+ ```bash
18
+ npm pack -w @hello-ai-company/editor-core
19
+ npm install ./hello-ai-company-editor-core-0.1.0.tgz
20
+ ```
21
+
22
+ ## Quickstart
23
+
24
+ ```ts
25
+ import {
26
+ createEditorDocument,
27
+ serializeEditorDocument,
28
+ deserializeEditorDocument,
29
+ EDITOR_DOCUMENT_SCHEMA_VERSION
30
+ } from "@hello-ai-company/editor-core";
31
+
32
+ const doc = createEditorDocument([
33
+ {
34
+ id: "p1",
35
+ type: "paragraph",
36
+ props: { text: "Hello" },
37
+ content: [{ type: "text", text: "Hello" }]
38
+ }
39
+ ]);
40
+
41
+ const json = serializeEditorDocument(doc);
42
+ const roundTrip = deserializeEditorDocument(json);
43
+
44
+ if (roundTrip.schemaVersion !== EDITOR_DOCUMENT_SCHEMA_VERSION) {
45
+ throw new Error("unexpected schemaVersion");
46
+ }
47
+ ```
48
+
49
+ `createEditorDocument` takes an **array of blocks**, not a `{ blocks }` wrapper. Unknown `type` strings are first-class data and round-trip. `schemaVersion` is the positive integer `1`.
50
+
51
+ ## What this package is
52
+
53
+ - `EditorDocument` / `EditorBlock` / `JsonValue`
54
+ - JSON serialize / deserialize
55
+ - Optional provider **types** only (no network clients, no UI)
56
+
57
+ ## What this package is not
58
+
59
+ - Not a rich-text editor
60
+ - Not a host app, sync layer, or HTTP client
61
+ - Not an adapter package (host integrations belong in later separate packages)
62
+
63
+ Public runtime and type lists: [docs/public-api.md](https://github.com/hello-ai-company/open-editor/blob/main/docs/public-api.md).
64
+
65
+ ## License
66
+
67
+ MIT. Copyright (c) 2026 Yuki Shibata.
@@ -0,0 +1,4 @@
1
+ export { EDITOR_DOCUMENT_SCHEMA_VERSION, cloneEditorBlock, cloneEditorBlocks, createEditorDocument, isEditorBlock, isEditorDocument, isJsonValue, isSupportedSchemaVersion, type EditorBlock, type EditorBlockProps, type EditorDocument, type JsonValue } from "./model.js";
2
+ export { EditorDocumentSerializationError, deserializeEditorDocument, fromSerializedEditorDocument, serializeEditorDocument, toSerializedEditorDocument, type SerializedEditorDocument } from "./serialization.js";
3
+ export type { AIEditAction, AIEditRequest, AIProvider, AssetProvider, AssetUploadScope, CommentsProvider, CreatedChildPage, DatabaseListOptions, DatabaseProvider, DatabaseRowItem, DatabaseRowsPage, EditorAsset, EditorAssetKind, EditorComment, EditorPageLink, EditorProviders, EditorUploadFile, EditorVersionSnapshot, ImageSearchProvider, ImageSearchResult, NativeBridge, NativeBridgeStats, NativeHostRequest, NativeHostResponse, PageProvider, VersionProvider } from "./providers.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,wBAAwB,EACxB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,SAAS,EACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,gCAAgC,EAChC,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,KAAK,wBAAwB,EAC9B,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EAChB,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { EDITOR_DOCUMENT_SCHEMA_VERSION, cloneEditorBlock, cloneEditorBlocks, createEditorDocument, isEditorBlock, isEditorDocument, isJsonValue, isSupportedSchemaVersion } from "./model.js";
2
+ export { EditorDocumentSerializationError, deserializeEditorDocument, fromSerializedEditorDocument, serializeEditorDocument, toSerializedEditorDocument } from "./serialization.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,wBAAwB,EAKzB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,gCAAgC,EAChC,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAE3B,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Provider-neutral editor document model.
3
+ *
4
+ * This module is a seam only: it describes typed block trees without host
5
+ * workspace, privacy, source, or server metadata.
6
+ */
7
+ export declare const EDITOR_DOCUMENT_SCHEMA_VERSION = 1;
8
+ export type JsonValue = string | number | boolean | null | JsonValue[] | {
9
+ readonly [key: string]: JsonValue;
10
+ };
11
+ export type EditorBlockProps = Record<string, JsonValue>;
12
+ /**
13
+ * Minimal extensible block. Unknown `type` values and extra `props` keys are
14
+ * first-class so a newer producer can round-trip through an older consumer.
15
+ */
16
+ export type EditorBlock = {
17
+ id: string;
18
+ type: string;
19
+ props?: EditorBlockProps;
20
+ content?: JsonValue;
21
+ children?: EditorBlock[];
22
+ };
23
+ export type EditorDocument = {
24
+ schemaVersion: number;
25
+ blocks: EditorBlock[];
26
+ };
27
+ /**
28
+ * Phase 2 contract: only the positive integer `1` is a supported schemaVersion.
29
+ * Rejects `-1`, `0`, `1.5`, `2`, and any non-integer numeric value.
30
+ */
31
+ export declare function isSupportedSchemaVersion(value: unknown): value is number;
32
+ export declare function createEditorDocument(blocks: EditorBlock[], schemaVersion?: number): EditorDocument;
33
+ export declare function cloneEditorBlocks(blocks: EditorBlock[]): EditorBlock[];
34
+ export declare function cloneEditorBlock(block: EditorBlock): EditorBlock;
35
+ export declare function isEditorBlock(value: unknown): value is EditorBlock;
36
+ export declare function isJsonValue(value: unknown): value is JsonValue;
37
+ export declare function isEditorDocument(value: unknown): value is EditorDocument;
38
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAEhD,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAE1C,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEzD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAMxE;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,aAAa,SAAiC,GAAG,cAAc,CAQ1H;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAEtE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAehE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAWlE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAQ9D;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAMxE"}
package/dist/model.js ADDED
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Provider-neutral editor document model.
3
+ *
4
+ * This module is a seam only: it describes typed block trees without host
5
+ * workspace, privacy, source, or server metadata.
6
+ */
7
+ export const EDITOR_DOCUMENT_SCHEMA_VERSION = 1;
8
+ /**
9
+ * Phase 2 contract: only the positive integer `1` is a supported schemaVersion.
10
+ * Rejects `-1`, `0`, `1.5`, `2`, and any non-integer numeric value.
11
+ */
12
+ export function isSupportedSchemaVersion(value) {
13
+ return typeof value === "number"
14
+ && Number.isInteger(value)
15
+ && Number.isFinite(value)
16
+ && value > 0
17
+ && value === EDITOR_DOCUMENT_SCHEMA_VERSION;
18
+ }
19
+ export function createEditorDocument(blocks, schemaVersion = EDITOR_DOCUMENT_SCHEMA_VERSION) {
20
+ if (!isSupportedSchemaVersion(schemaVersion)) {
21
+ throw new Error("Editor document schemaVersion must be the positive integer 1.");
22
+ }
23
+ return {
24
+ schemaVersion,
25
+ blocks: cloneEditorBlocks(blocks)
26
+ };
27
+ }
28
+ export function cloneEditorBlocks(blocks) {
29
+ return blocks.map(cloneEditorBlock);
30
+ }
31
+ export function cloneEditorBlock(block) {
32
+ const cloned = {
33
+ id: block.id,
34
+ type: block.type
35
+ };
36
+ if (block.props !== undefined) {
37
+ cloned.props = cloneJsonValue(block.props);
38
+ }
39
+ if (block.content !== undefined) {
40
+ cloned.content = cloneJsonValue(block.content);
41
+ }
42
+ if (block.children !== undefined) {
43
+ cloned.children = cloneEditorBlocks(block.children);
44
+ }
45
+ return cloned;
46
+ }
47
+ export function isEditorBlock(value) {
48
+ if (!value || typeof value !== "object" || Array.isArray(value))
49
+ return false;
50
+ const block = value;
51
+ if (typeof block.id !== "string" || block.id.length === 0)
52
+ return false;
53
+ if (typeof block.type !== "string" || block.type.length === 0)
54
+ return false;
55
+ if (block.props !== undefined && !(isPlainObject(block.props) && isJsonValue(block.props)))
56
+ return false;
57
+ if (block.content !== undefined && !isJsonValue(block.content))
58
+ return false;
59
+ if (block.children !== undefined) {
60
+ if (!Array.isArray(block.children) || !block.children.every(isEditorBlock))
61
+ return false;
62
+ }
63
+ return true;
64
+ }
65
+ export function isJsonValue(value) {
66
+ if (value === null)
67
+ return true;
68
+ const kind = typeof value;
69
+ if (kind === "string" || kind === "boolean")
70
+ return true;
71
+ if (kind === "number")
72
+ return Number.isFinite(value);
73
+ if (Array.isArray(value))
74
+ return value.every(isJsonValue);
75
+ if (!isPlainObject(value))
76
+ return false;
77
+ return Object.values(value).every(isJsonValue);
78
+ }
79
+ export function isEditorDocument(value) {
80
+ if (!value || typeof value !== "object" || Array.isArray(value))
81
+ return false;
82
+ const document = value;
83
+ if (!isSupportedSchemaVersion(document.schemaVersion))
84
+ return false;
85
+ if (!Array.isArray(document.blocks) || !document.blocks.every(isEditorBlock))
86
+ return false;
87
+ return true;
88
+ }
89
+ function isPlainObject(value) {
90
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
91
+ }
92
+ function cloneJsonValue(value) {
93
+ return JSON.parse(JSON.stringify(value));
94
+ }
95
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC;AA6BhD;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,OAAO,OAAO,KAAK,KAAK,QAAQ;WAC3B,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;WACvB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;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,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,MAAM,QAAQ,GAAG,KAAgC,CAAC;IAClD,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,aAAa,CAAC;QAAE,OAAO,KAAK,CAAC;IACpE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3F,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,cAAc,CAAI,KAAQ;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAM,CAAC;AAChD,CAAC"}
@@ -0,0 +1,201 @@
1
+ import type { EditorDocument, JsonValue } from "./model.js";
2
+ /**
3
+ * Optional seams the host may implement. Every provider is optional so a
4
+ * consumer can mount a read-only document with zero integrations.
5
+ *
6
+ * Contracts stay host-neutral: edit/transform, persistence, comments,
7
+ * versions, assets, pages, and a generic native host protocol.
8
+ */
9
+ export type AIEditAction = "improve" | "shorten" | "expand" | "rewrite" | "custom";
10
+ export type AIEditRequest = {
11
+ prompt: string;
12
+ selectionText?: string;
13
+ action?: AIEditAction;
14
+ instruction?: string;
15
+ };
16
+ export type AIProvider = {
17
+ edit?(request: AIEditRequest): Promise<string>;
18
+ };
19
+ export type DatabaseListOptions = {
20
+ limit?: number;
21
+ cursor?: string;
22
+ query?: string;
23
+ sortBy?: "position" | "title";
24
+ direction?: "asc" | "desc";
25
+ includeTrashed?: boolean;
26
+ trashedOnly?: boolean;
27
+ };
28
+ export type DatabaseRowItem = {
29
+ rowKey: string;
30
+ sortOrder: number;
31
+ deletedAt?: string | null;
32
+ row: Record<string, JsonValue>;
33
+ };
34
+ export type DatabaseRowsPage = {
35
+ databaseId: string;
36
+ rows: Array<Record<string, JsonValue>>;
37
+ items: DatabaseRowItem[];
38
+ schema: Record<string, string>;
39
+ config: Record<string, JsonValue>;
40
+ pagination: {
41
+ limit: number;
42
+ nextCursor: string | null;
43
+ hasMore: boolean;
44
+ total: number;
45
+ };
46
+ };
47
+ export type DatabaseProvider = {
48
+ listRows?(databaseId: string, options?: DatabaseListOptions): Promise<DatabaseRowsPage>;
49
+ getRow?(databaseId: string, rowKey: string): Promise<{
50
+ databaseId: string;
51
+ row: Record<string, JsonValue>;
52
+ }>;
53
+ createRow?(databaseId: string, row: Record<string, JsonValue>, options?: {
54
+ rowKey?: string;
55
+ sortOrder?: number;
56
+ }): Promise<JsonValue>;
57
+ updateRow?(databaseId: string, rowKey: string, row: Record<string, JsonValue>, sortOrder?: number): Promise<JsonValue>;
58
+ deleteRow?(databaseId: string, rowKey: string): Promise<JsonValue>;
59
+ restoreRow?(databaseId: string, rowKey: string): Promise<JsonValue>;
60
+ reorderRows?(databaseId: string, rowKeys: string[]): Promise<JsonValue>;
61
+ };
62
+ export type EditorComment = {
63
+ id: string;
64
+ blockId: string;
65
+ text: string;
66
+ createdAt: string;
67
+ resolved?: boolean;
68
+ };
69
+ export type CommentsProvider = {
70
+ list?(documentId: string): Promise<EditorComment[]>;
71
+ add?(documentId: string, blockId: string, text: string): Promise<EditorComment | void>;
72
+ update?(documentId: string, commentId: string, update: {
73
+ text?: string;
74
+ resolved?: boolean;
75
+ }): Promise<EditorComment | void>;
76
+ delete?(documentId: string, commentId: string): Promise<void>;
77
+ };
78
+ export type EditorVersionSnapshot = {
79
+ id: string;
80
+ name?: string;
81
+ title?: string;
82
+ createdAt: string;
83
+ document: EditorDocument;
84
+ };
85
+ export type VersionProvider = {
86
+ list?(documentId: string): Promise<EditorVersionSnapshot[]>;
87
+ save?(documentId: string, snapshot: Omit<EditorVersionSnapshot, "id" | "createdAt"> & {
88
+ id?: string;
89
+ createdAt?: string;
90
+ }): Promise<EditorVersionSnapshot | void>;
91
+ restore?(documentId: string, versionId: string): Promise<EditorVersionSnapshot | void>;
92
+ rename?(documentId: string, versionId: string, name: string): Promise<void>;
93
+ delete?(documentId: string, versionId: string): Promise<void>;
94
+ };
95
+ export type EditorAssetKind = "image" | "video" | "audio" | "pdf" | "file";
96
+ export type EditorAsset = {
97
+ url: string;
98
+ attachmentId?: string;
99
+ name: string;
100
+ mimeType: string;
101
+ size?: number;
102
+ kind?: EditorAssetKind;
103
+ };
104
+ export type EditorUploadFile = {
105
+ name: string;
106
+ type: string;
107
+ size: number;
108
+ arrayBuffer(): Promise<ArrayBuffer>;
109
+ };
110
+ export type AssetUploadScope = {
111
+ documentId?: string;
112
+ blockId?: string;
113
+ };
114
+ export type AssetProvider = {
115
+ upload?(file: EditorUploadFile, scope?: AssetUploadScope): Promise<EditorAsset>;
116
+ insertCloud?(asset: EditorAsset): void;
117
+ };
118
+ export type ImageSearchResult = {
119
+ id: string;
120
+ title: string;
121
+ url: string;
122
+ keywords?: string;
123
+ };
124
+ export type ImageSearchProvider = {
125
+ search?(query: string, page?: number, perPage?: number): Promise<{
126
+ configured: boolean;
127
+ page: number;
128
+ perPage: number;
129
+ total: number;
130
+ hasMore: boolean;
131
+ results: ImageSearchResult[];
132
+ }>;
133
+ };
134
+ export type EditorPageLink = {
135
+ id: string;
136
+ title: string;
137
+ preview?: string;
138
+ imageUrl?: string;
139
+ imageAlt?: string;
140
+ };
141
+ export type CreatedChildPage = {
142
+ id: string;
143
+ title: string;
144
+ preview?: string;
145
+ imageUrl?: string;
146
+ imageAlt?: string;
147
+ };
148
+ export type PageProvider = {
149
+ listLinks?(excludePageId?: string): Promise<EditorPageLink[]>;
150
+ createChildPage?(): CreatedChildPage | void;
151
+ openPage?(pageId: string): void;
152
+ };
153
+ export type NativeBridgeStats = {
154
+ characters?: number;
155
+ words?: number;
156
+ blocks?: number;
157
+ headings?: number;
158
+ tasks?: number;
159
+ completedTasks?: number;
160
+ media?: number;
161
+ tables?: number;
162
+ links?: number;
163
+ readingMinutes?: number;
164
+ };
165
+ export type NativeHostRequest = {
166
+ id: string;
167
+ method: string;
168
+ payload?: JsonValue;
169
+ };
170
+ export type NativeHostResponse = {
171
+ id: string;
172
+ ok: boolean;
173
+ payload?: JsonValue;
174
+ error?: string;
175
+ };
176
+ /**
177
+ * Minimal generic host protocol. Host-specific transport (network proxy,
178
+ * document chrome, workforce actions) maps onto hostRequest / hostResponse.
179
+ */
180
+ export type NativeBridge = {
181
+ ready?(documentId: string): void;
182
+ change?(payload: {
183
+ dirty: boolean;
184
+ stats?: NativeBridgeStats;
185
+ }): void;
186
+ commit?(payload: Record<string, JsonValue>): void;
187
+ error?(message: string): void;
188
+ hostRequest?(request: NativeHostRequest): void;
189
+ hostResponse?(response: NativeHostResponse): void;
190
+ };
191
+ export type EditorProviders = {
192
+ ai?: AIProvider;
193
+ database?: DatabaseProvider;
194
+ comments?: CommentsProvider;
195
+ versions?: VersionProvider;
196
+ assets?: AssetProvider;
197
+ imageSearch?: ImageSearchProvider;
198
+ pages?: PageProvider;
199
+ nativeBridge?: NativeBridge;
200
+ };
201
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5D;;;;;;GAMG;AAEH,MAAM,M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iB,GAAG,IAAI,CAAC;IAC/C,YAAY,CAAC,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACnD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=providers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.js","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import { type EditorBlock, type EditorDocument } from "./model.js";
2
+ export declare class EditorDocumentSerializationError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ export type SerializedEditorDocument = {
6
+ schemaVersion: number;
7
+ blocks: EditorBlock[];
8
+ };
9
+ export declare function serializeEditorDocument(document: EditorDocument): string;
10
+ export declare function deserializeEditorDocument(payload: string): EditorDocument;
11
+ export declare function toSerializedEditorDocument(document: EditorDocument): SerializedEditorDocument;
12
+ export declare function fromSerializedEditorDocument(payload: unknown): EditorDocument;
13
+ //# sourceMappingURL=serialization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;AAEpB,qBAAa,gCAAiC,SAAQ,KAAK;gBAC7C,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAExE;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAQzE;AAED,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,cAAc,GAAG,wBAAwB,CAW7F;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,CAyB7E"}
@@ -0,0 +1,67 @@
1
+ import { EDITOR_DOCUMENT_SCHEMA_VERSION, cloneEditorBlock, isEditorBlock, isSupportedSchemaVersion } from "./model.js";
2
+ export class EditorDocumentSerializationError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "EditorDocumentSerializationError";
6
+ }
7
+ }
8
+ export function serializeEditorDocument(document) {
9
+ return JSON.stringify(toSerializedEditorDocument(document));
10
+ }
11
+ export function deserializeEditorDocument(payload) {
12
+ let parsed;
13
+ try {
14
+ parsed = JSON.parse(payload);
15
+ }
16
+ catch {
17
+ throw new EditorDocumentSerializationError("Editor document JSON is not valid.");
18
+ }
19
+ return fromSerializedEditorDocument(parsed);
20
+ }
21
+ export function toSerializedEditorDocument(document) {
22
+ if (!isSupportedSchemaVersion(document.schemaVersion)) {
23
+ throw new EditorDocumentSerializationError("Editor document schemaVersion must be the positive integer 1.");
24
+ }
25
+ if (!Array.isArray(document.blocks)) {
26
+ throw new EditorDocumentSerializationError("Editor document blocks must be an array.");
27
+ }
28
+ return {
29
+ schemaVersion: document.schemaVersion,
30
+ blocks: document.blocks.map(normalizeEditorBlock)
31
+ };
32
+ }
33
+ export function fromSerializedEditorDocument(payload) {
34
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
35
+ throw new EditorDocumentSerializationError("Editor document must be an object.");
36
+ }
37
+ const record = payload;
38
+ const schemaVersion = record.schemaVersion === undefined ? EDITOR_DOCUMENT_SCHEMA_VERSION : record.schemaVersion;
39
+ if (!isSupportedSchemaVersion(schemaVersion)) {
40
+ throw new EditorDocumentSerializationError(typeof schemaVersion === "number"
41
+ ? `Unsupported editor document schemaVersion ${schemaVersion}.`
42
+ : "Editor document schemaVersion must be the positive integer 1.");
43
+ }
44
+ if (!Array.isArray(record.blocks)) {
45
+ throw new EditorDocumentSerializationError("Editor document blocks must be an array.");
46
+ }
47
+ return {
48
+ schemaVersion,
49
+ blocks: record.blocks.map((block, index) => {
50
+ if (!isEditorBlock(block)) {
51
+ throw new EditorDocumentSerializationError(`Editor document block at index ${index} is invalid.`);
52
+ }
53
+ return normalizeEditorBlock(block);
54
+ })
55
+ };
56
+ }
57
+ function normalizeEditorBlock(block) {
58
+ const normalized = cloneEditorBlock(block);
59
+ if (normalized.children?.length === 0) {
60
+ delete normalized.children;
61
+ }
62
+ if (normalized.props && Object.keys(normalized.props).length === 0) {
63
+ delete normalized.props;
64
+ }
65
+ return normalized;
66
+ }
67
+ //# sourceMappingURL=serialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.js","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAChB,aAAa,EACb,wBAAwB,EAGzB,MAAM,YAAY,CAAC;AAEpB,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IACzD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kCAAkC,CAAC;IACjD,CAAC;CACF;AAOD,MAAM,UAAU,uBAAuB,CAAC,QAAwB;IAC9D,OAAO,IAAI,CAAC,SAAS,CAAC,0BAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,OAAe;IACvD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC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MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,gCAAgC,CAAC,0CAA0C,CAAC,CAAC;IACzF,CAAC;IACD,OAAO;QACL,aAAa;QACb,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YACzC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,gCAAgC,CAAC,kCAAkC,KAAK,cAAc,CAAC,CAAC;YACpG,CAAC;YACD,OAAO,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC,CAAC;KACH,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAkB;IAC9C,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,UAAU,CAAC,QAAQ,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;QACtC,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IACD,IAAI,UAAU,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnE,OAAO,UAAU,CAAC,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@hello-ai-company/editor-core",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "Portable TypeScript document model, JSON serialization, and optional provider types. A small host-neutral document layer - not a rich-text editor.",
6
+ "keywords": [
7
+ "document-model",
8
+ "serialization",
9
+ "typescript",
10
+ "json",
11
+ "editor-core",
12
+ "portable-document",
13
+ "schema"
14
+ ],
15
+ "homepage": "https://github.com/hello-ai-company/open-editor/tree/main/packages/core#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/hello-ai-company/open-editor/issues"
18
+ },
19
+ "author": "Yuki Shibata",
20
+ "type": "module",
21
+ "main": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "LICENSE",
32
+ "README.md"
33
+ ],
34
+ "scripts": {
35
+ "build": "tsc -p tsconfig.build.json",
36
+ "typecheck": "tsc -p tsconfig.json --noEmit",
37
+ "test": "vitest run"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/hello-ai-company/open-editor.git",
42
+ "directory": "packages/core"
43
+ },
44
+ "publishConfig": {
45
+ "registry": "https://registry.npmjs.org",
46
+ "access": "public"
47
+ },
48
+ "devDependencies": {
49
+ "typescript": "^5.9.2",
50
+ "vitest": "^3.2.4"
51
+ },
52
+ "engines": {
53
+ "node": ">=20"
54
+ }
55
+ }