@kungal/editor-core 0.2.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/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # @kungal/editor-core
2
+
3
+ The **framework-agnostic core** of KunEditor. Pure TypeScript — no Vue, no
4
+ React. It owns the Milkdown/ProseMirror mechanism (nodes, marks, input rules,
5
+ keymaps, markdown (de)serialization, plugin wiring) and exposes it through
6
+ small **adapter contracts** the host fills in.
7
+
8
+ Ships dual ESM/CJS with type declarations.
9
+
10
+ ## The one idea
11
+
12
+ > **The editor ships the mechanism; the host injects the policy.**
13
+
14
+ The editor does not know where an image upload goes, how an `@mention` resolves
15
+ to a user, what stickers exist, or how a toast is shown. Those are per-host
16
+ *policy*, passed in as adapters:
17
+
18
+ ```ts
19
+ import type { KunEditorAdapters } from '@kungal/editor-core'
20
+
21
+ const adapters: KunEditorAdapters = {
22
+ uploadImage: (file) => api.uploadTopicImage(file), // → Promise<url>
23
+ searchMentionUsers: (q) => oauth.searchUsers(q), // → Promise<MentionUser[]>
24
+ notify: (msg, level) => toast(msg, level),
25
+ }
26
+ ```
27
+
28
+ Omit an adapter and the matching plugin simply isn't wired — that is how the
29
+ "image-free" editor (galgame 简介) is expressed: no `uploadImage`, no upload/
30
+ paste/sticker paths, no special-casing.
31
+
32
+ ## What's here today
33
+
34
+ | Export | Purpose |
35
+ | --- | --- |
36
+ | `KunEditorAdapters` | the policy bundle a host passes (`uploadImage` / `searchMentionUsers` / `stickerSource` / `notify`) |
37
+ | `UploadImage`, `SearchMentionUsers`, `StickerSource`, `Notify` | the individual adapter function types |
38
+ | `MentionUser`, `StickerItem`, `StickerPack` | the data shapes crossing the boundary |
39
+ | `KunEditorFeatures`, `KunEditorLocale` | feature toggles + UI language |
40
+ | `MENTION_SCHEME` (`kungal-user:`) | the markdown link scheme shared with the server |
41
+
42
+ The Milkdown plugin ports land incrementally — see
43
+ [`../../docs/architecture.md`](../../docs/architecture.md) § migration.
44
+
45
+ ## The `/preset` subpath — the Milkdown plugins
46
+
47
+ The main entry above is deliberately **light**: types + `MENTION_SCHEME`, zero
48
+ runtime deps, so the server can import the `@mention` scheme without installing
49
+ Milkdown. The actual Milkdown plugins live behind a separate subpath that pulls
50
+ in the peers:
51
+
52
+ ```ts
53
+ import { createKunEditorPlugins } from '@kungal/editor-core/preset'
54
+
55
+ // The single call the render layer makes — assembles the Milkdown baseline
56
+ // (commonmark/gfm/history/listener/clipboard/indent/trailing) with the KunEditor
57
+ // plugins, wiring each optional one only when its feature/adapter is present.
58
+ editor.use(createKunEditorPlugins(adapters, features, { locale: 'zh-cn' }))
59
+ ```
60
+
61
+ Landed so far — each a **factory**, never a module-level singleton bound to one
62
+ host:
63
+
64
+ **P1** (pure — no host policy):
65
+
66
+ | Export (from `/preset`) | Syntax / behaviour |
67
+ | --- | --- |
68
+ | `createSpoilerPlugin()` | `\|\|hidden\|\|` inline node + `$remark` round-trip |
69
+ | `createKatexPlugins()` | inline `$…$` and block `$$…$$` LaTeX (KaTeX) |
70
+ | `createCodeBlockPlugins(opts)` | CodeMirror code block: theme, languages, toolbar, `latex` preview |
71
+ | `createStopLinkPlugin()` | Space clears the active link mark |
72
+
73
+ **P2** (adapter-driven):
74
+
75
+ | Export (from `/preset`) | Syntax / behaviour | Host policy |
76
+ | --- | --- | --- |
77
+ | `createUploadPlugin(uploadImage, opts)` | paste / drop / toolbar image upload | `uploadImage(file) → url` (+ optional `notify`) |
78
+ | `createMentionPlugin()` | `[@name](kungal-user:id)` mention atom | schema is pure; the `@` dropdown (P3) uses `searchMentionUsers` |
79
+ | `createQuotePlugin()` | `[label](kungal-reply:refId)` inline reference atom | host inserts via `insertQuoteCommand({ refId, label })` |
80
+
81
+ Stickers have **no core plugin** — a sticker is a plain image node, so the picker
82
+ is a render-layer view (P3) that reads the `stickerSource` adapter and inserts an
83
+ image. The `<KunEditor>` Vue component + toolbar + plugin views land in P3.
84
+
85
+ ## Peer dependencies (and why)
86
+
87
+ `@milkdown/kit` and `@milkdown/prose` are **peer** dependencies, not bundled.
88
+ ProseMirror MUST resolve to a single runtime instance — a second
89
+ `prosemirror-model` copy silently breaks schema/node identity. Keeping Milkdown
90
+ as a peer means the host owns the one copy. `katex`, `codemirror`, the
91
+ `@codemirror/*` packages and `@lezer/highlight` are **optional** peers, needed
92
+ only if you enable the katex / code-block plugins (i.e. import `/preset`).
93
+
94
+ ## Build & test
95
+
96
+ ```bash
97
+ pnpm --filter @kungal/editor-core build # tsup → dist (esm + cjs + d.ts)
98
+ pnpm --filter @kungal/editor-core typecheck
99
+ pnpm --filter @kungal/editor-core test # vitest — headless markdown round-trip
100
+ ```
@@ -0,0 +1,8 @@
1
+ // src/index.ts
2
+ var MENTION_SCHEME = "kungal-user:";
3
+ var QUOTE_SCHEME = "kungal-reply:";
4
+ var KUN_EDITOR_CORE_VERSION = "0.0.0";
5
+
6
+ export { KUN_EDITOR_CORE_VERSION, MENTION_SCHEME, QUOTE_SCHEME };
7
+ //# sourceMappingURL=chunk-KY2VN6IQ.js.map
8
+ //# sourceMappingURL=chunk-KY2VN6IQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAYO,IAAM,cAAA,GAAiB;AAMvB,IAAM,YAAA,GAAe;AAErB,IAAM,uBAAA,GAA0B","file":"chunk-KY2VN6IQ.js","sourcesContent":["// @kungal/editor-core — public entry.\n//\n// STATUS: scaffold. The adapter contracts (the stable public surface) are\n// defined and exported now; the Milkdown plugin ports land incrementally per\n// docs/architecture.md § migration. Consumers should code against the types\n// below — those are the contract that will not churn as plugins move over.\n\nexport * from './types'\n\n// Markdown scheme used to encode an @mention as a plain link the server can\n// render + parse: `[@name](kungal-user:<id>)`. Lives here (not the plugin) so\n// hosts and the server can share the exact string. See ./plugins/mention.\nexport const MENTION_SCHEME = 'kungal-user:'\n\n// Markdown scheme for an inline reference (reply quote): `[label](kungal-reply:<refId>)`.\n// Like MENTION_SCHEME, shared with the server renderer so both agree on the\n// exact string. The reference is opaque here — the host decides what `refId` /\n// `label` mean (see docs/architecture.md § the reply-quote question, option 1).\nexport const QUOTE_SCHEME = 'kungal-reply:'\n\nexport const KUN_EDITOR_CORE_VERSION = '0.0.0'\n\n// ── The Milkdown plugins live in the `./preset` subpath ──────────────────────\n// This main entry stays light on purpose: types + MENTION_SCHEME, ZERO runtime\n// deps, so the server (which only needs the @mention scheme string) can import\n// it without installing @milkdown/kit / katex / codemirror.\n//\n// The composed Milkdown bundle and the individual plugin factories are exported\n// from `@kungal/editor-core/preset` (they pull in the peer deps):\n//\n// import { createKunEditorPlugins } from '@kungal/editor-core/preset'\n//\n// P1 landed (docs/architecture.md § migration): spoiler, katex, code-block,\n// stop-link — each a factory (createXxxPlugin), never a host-bound singleton.\n// P2 adds the adapter-driven plugins (upload / mention / sticker).\n"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ // src/index.ts
4
+ var MENTION_SCHEME = "kungal-user:";
5
+ var QUOTE_SCHEME = "kungal-reply:";
6
+ var KUN_EDITOR_CORE_VERSION = "0.0.0";
7
+
8
+ exports.KUN_EDITOR_CORE_VERSION = KUN_EDITOR_CORE_VERSION;
9
+ exports.MENTION_SCHEME = MENTION_SCHEME;
10
+ exports.QUOTE_SCHEME = QUOTE_SCHEME;
11
+ //# sourceMappingURL=index.cjs.map
12
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAYO,IAAM,cAAA,GAAiB;AAMvB,IAAM,YAAA,GAAe;AAErB,IAAM,uBAAA,GAA0B","file":"index.cjs","sourcesContent":["// @kungal/editor-core — public entry.\n//\n// STATUS: scaffold. The adapter contracts (the stable public surface) are\n// defined and exported now; the Milkdown plugin ports land incrementally per\n// docs/architecture.md § migration. Consumers should code against the types\n// below — those are the contract that will not churn as plugins move over.\n\nexport * from './types'\n\n// Markdown scheme used to encode an @mention as a plain link the server can\n// render + parse: `[@name](kungal-user:<id>)`. Lives here (not the plugin) so\n// hosts and the server can share the exact string. See ./plugins/mention.\nexport const MENTION_SCHEME = 'kungal-user:'\n\n// Markdown scheme for an inline reference (reply quote): `[label](kungal-reply:<refId>)`.\n// Like MENTION_SCHEME, shared with the server renderer so both agree on the\n// exact string. The reference is opaque here — the host decides what `refId` /\n// `label` mean (see docs/architecture.md § the reply-quote question, option 1).\nexport const QUOTE_SCHEME = 'kungal-reply:'\n\nexport const KUN_EDITOR_CORE_VERSION = '0.0.0'\n\n// ── The Milkdown plugins live in the `./preset` subpath ──────────────────────\n// This main entry stays light on purpose: types + MENTION_SCHEME, ZERO runtime\n// deps, so the server (which only needs the @mention scheme string) can import\n// it without installing @milkdown/kit / katex / codemirror.\n//\n// The composed Milkdown bundle and the individual plugin factories are exported\n// from `@kungal/editor-core/preset` (they pull in the peer deps):\n//\n// import { createKunEditorPlugins } from '@kungal/editor-core/preset'\n//\n// P1 landed (docs/architecture.md § migration): spoiler, katex, code-block,\n// stop-link — each a factory (createXxxPlugin), never a host-bound singleton.\n// P2 adds the adapter-driven plugins (upload / mention / sticker).\n"]}
@@ -0,0 +1,7 @@
1
+ export { K as KunEditorAdapters, a as KunEditorFeatures, b as KunEditorLocale, M as MentionUser, N as Notify, c as NotifyLevel, S as SearchMentionUsers, d as StickerItem, e as StickerPack, f as StickerSource, U as UploadImage } from './types-B_iVOftJ.cjs';
2
+
3
+ declare const MENTION_SCHEME = "kungal-user:";
4
+ declare const QUOTE_SCHEME = "kungal-reply:";
5
+ declare const KUN_EDITOR_CORE_VERSION = "0.0.0";
6
+
7
+ export { KUN_EDITOR_CORE_VERSION, MENTION_SCHEME, QUOTE_SCHEME };
@@ -0,0 +1,7 @@
1
+ export { K as KunEditorAdapters, a as KunEditorFeatures, b as KunEditorLocale, M as MentionUser, N as Notify, c as NotifyLevel, S as SearchMentionUsers, d as StickerItem, e as StickerPack, f as StickerSource, U as UploadImage } from './types-B_iVOftJ.js';
2
+
3
+ declare const MENTION_SCHEME = "kungal-user:";
4
+ declare const QUOTE_SCHEME = "kungal-reply:";
5
+ declare const KUN_EDITOR_CORE_VERSION = "0.0.0";
6
+
7
+ export { KUN_EDITOR_CORE_VERSION, MENTION_SCHEME, QUOTE_SCHEME };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { KUN_EDITOR_CORE_VERSION, MENTION_SCHEME, QUOTE_SCHEME } from './chunk-KY2VN6IQ.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}