@kungal/editor-core 0.9.0 → 0.10.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/CHANGELOG.md +25 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/preset/index.cjs +30 -17
- package/dist/preset/index.cjs.map +1 -1
- package/dist/preset/index.d.cts +25 -9
- package/dist/preset/index.d.ts +25 -9
- package/dist/preset/index.js +31 -18
- package/dist/preset/index.js.map +1 -1
- package/dist/{types-BXLT8DV7.d.cts → types-EgTLraa1.d.cts} +12 -0
- package/dist/{types-BXLT8DV7.d.ts → types-EgTLraa1.d.ts} +12 -0
- package/package.json +1 -1
package/dist/preset/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MilkdownPlugin, Ctx } from '@milkdown/kit/ctx';
|
|
2
2
|
import { KatexOptions } from 'katex';
|
|
3
|
-
import { b as KunEditorLocale, N as Notify, U as UploadImage, K as KunEditorAdapters, a as KunEditorFeatures } from '../types-
|
|
3
|
+
import { b as KunEditorLocale, N as Notify, U as UploadImage, K as KunEditorAdapters, a as KunEditorFeatures } from '../types-EgTLraa1.cjs';
|
|
4
4
|
import * as _milkdown_kit_utils from '@milkdown/kit/utils';
|
|
5
5
|
import { Extension } from '@codemirror/state';
|
|
6
6
|
import { Uploader } from '@milkdown/kit/plugin/upload';
|
|
@@ -95,22 +95,38 @@ declare const applyCodeBlockConfig: (ctx: Ctx, options?: CodeBlockOptions) => vo
|
|
|
95
95
|
declare const createCodeBlockPlugins: (options?: CodeBlockOptions) => MilkdownPlugin[];
|
|
96
96
|
|
|
97
97
|
declare const mentionId = "mention";
|
|
98
|
+
/**
|
|
99
|
+
* How an @mention's user id maps TO / FROM its markdown link URL — host policy.
|
|
100
|
+
* Default: the `kungal-user:<id>` scheme (shared with the KUN server).
|
|
101
|
+
*/
|
|
102
|
+
interface MentionUrlConfig {
|
|
103
|
+
/** Build the link URL for a mention of `userId`. */
|
|
104
|
+
toUrl?: (userId: number) => string;
|
|
105
|
+
/** Parse a link URL back to a user id, or `null` if it isn't a mention. */
|
|
106
|
+
fromUrl?: (url: string) => number | null;
|
|
107
|
+
}
|
|
108
|
+
/** Default (kungal-user:) mention schema — for advanced direct use. */
|
|
98
109
|
declare const mentionSchema: _milkdown_kit_utils.$NodeSchema<"mention">;
|
|
99
|
-
/**
|
|
110
|
+
/** Default (kungal-user:) mention remark transform — for advanced direct use. */
|
|
100
111
|
declare const remarkMentionPlugin: _milkdown_kit_utils.$Remark<"remarkMention", unknown>;
|
|
101
112
|
/**
|
|
102
113
|
* Insert a mention chip at the cursor, replacing the selection. The render-layer
|
|
103
|
-
* dropdown
|
|
104
|
-
*
|
|
105
|
-
* continue past the atom naturally.
|
|
114
|
+
* dropdown usually replaces the `@query` range itself; this is the programmatic
|
|
115
|
+
* path (toolbar / tests / the imperative insertMention handle). A trailing space
|
|
116
|
+
* lets the caret continue past the atom naturally. Resolves the node type by id
|
|
117
|
+
* from the live schema, so it works with any mention config.
|
|
106
118
|
*/
|
|
107
119
|
declare const insertMentionCommand: _milkdown_kit_utils.$Command<{
|
|
108
120
|
userId: number;
|
|
109
121
|
name: string;
|
|
110
122
|
}>;
|
|
111
|
-
/**
|
|
112
|
-
*
|
|
113
|
-
|
|
123
|
+
/**
|
|
124
|
+
* The mention plugin bundle: schema + remark round-trip + insert command. Pass
|
|
125
|
+
* `toUrl` / `fromUrl` to use a host-specific mention link form; omit for the
|
|
126
|
+
* default `kungal-user:` scheme. The `searchMentionUsers` adapter (the `@`
|
|
127
|
+
* autocomplete) is consumed by the render-layer dropdown.
|
|
128
|
+
*/
|
|
129
|
+
declare const createMentionPlugin: (config?: MentionUrlConfig) => MilkdownPlugin[];
|
|
114
130
|
|
|
115
131
|
declare const quoteId = "quote";
|
|
116
132
|
/** The payload a host passes to insert a reference. `refId` is opaque (the host
|
|
@@ -182,4 +198,4 @@ interface KunEditorPluginOptions {
|
|
|
182
198
|
*/
|
|
183
199
|
declare const createKunEditorPlugins: (adapters?: KunEditorAdapters, features?: KunEditorFeatures, options?: KunEditorPluginOptions) => MilkdownPlugin[];
|
|
184
200
|
|
|
185
|
-
export { type CodeBlockOptions, type KunEditorPluginOptions, type QuoteReference, type UploadPluginOptions, applyCodeBlockConfig, applyUploadConfig, blockKatexSchema, chevronDownIcon, clearIcon, copyIcon, createCodeBlockPlugins, createKatexPlugins, createKunEditorPlugins, createMentionPlugin, createQuotePlugin, createSpoilerPlugin, createStopLinkPlugin, createUploadPlugin, createUploadWidgetFactory, createUploader, editIcon, insertKunSpoilerCommand, insertMentionCommand, insertQuoteCommand, insertSpoilerInputRule, kunCM, kunCMHighlightStyle, kunCMTheme, linkCustomKeymap, mathBlockInputRule, mathInlineId, mathInlineInputRule, mathInlineSchema, mentionId, mentionSchema, quoteId, quoteSchema, remarkMathBlockPlugin, remarkMathPlugin, remarkMentionPlugin, remarkQuotePlugin, remarkSpoilerPlugin, searchIcon, spoilerAttr, spoilerSchema, stopLinkCommand, toggleLatexCommand, visibilityOffIcon };
|
|
201
|
+
export { type CodeBlockOptions, type KunEditorPluginOptions, type MentionUrlConfig, type QuoteReference, type UploadPluginOptions, applyCodeBlockConfig, applyUploadConfig, blockKatexSchema, chevronDownIcon, clearIcon, copyIcon, createCodeBlockPlugins, createKatexPlugins, createKunEditorPlugins, createMentionPlugin, createQuotePlugin, createSpoilerPlugin, createStopLinkPlugin, createUploadPlugin, createUploadWidgetFactory, createUploader, editIcon, insertKunSpoilerCommand, insertMentionCommand, insertQuoteCommand, insertSpoilerInputRule, kunCM, kunCMHighlightStyle, kunCMTheme, linkCustomKeymap, mathBlockInputRule, mathInlineId, mathInlineInputRule, mathInlineSchema, mentionId, mentionSchema, quoteId, quoteSchema, remarkMathBlockPlugin, remarkMathPlugin, remarkMentionPlugin, remarkQuotePlugin, remarkSpoilerPlugin, searchIcon, spoilerAttr, spoilerSchema, stopLinkCommand, toggleLatexCommand, visibilityOffIcon };
|
package/dist/preset/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MilkdownPlugin, Ctx } from '@milkdown/kit/ctx';
|
|
2
2
|
import { KatexOptions } from 'katex';
|
|
3
|
-
import { b as KunEditorLocale, N as Notify, U as UploadImage, K as KunEditorAdapters, a as KunEditorFeatures } from '../types-
|
|
3
|
+
import { b as KunEditorLocale, N as Notify, U as UploadImage, K as KunEditorAdapters, a as KunEditorFeatures } from '../types-EgTLraa1.js';
|
|
4
4
|
import * as _milkdown_kit_utils from '@milkdown/kit/utils';
|
|
5
5
|
import { Extension } from '@codemirror/state';
|
|
6
6
|
import { Uploader } from '@milkdown/kit/plugin/upload';
|
|
@@ -95,22 +95,38 @@ declare const applyCodeBlockConfig: (ctx: Ctx, options?: CodeBlockOptions) => vo
|
|
|
95
95
|
declare const createCodeBlockPlugins: (options?: CodeBlockOptions) => MilkdownPlugin[];
|
|
96
96
|
|
|
97
97
|
declare const mentionId = "mention";
|
|
98
|
+
/**
|
|
99
|
+
* How an @mention's user id maps TO / FROM its markdown link URL — host policy.
|
|
100
|
+
* Default: the `kungal-user:<id>` scheme (shared with the KUN server).
|
|
101
|
+
*/
|
|
102
|
+
interface MentionUrlConfig {
|
|
103
|
+
/** Build the link URL for a mention of `userId`. */
|
|
104
|
+
toUrl?: (userId: number) => string;
|
|
105
|
+
/** Parse a link URL back to a user id, or `null` if it isn't a mention. */
|
|
106
|
+
fromUrl?: (url: string) => number | null;
|
|
107
|
+
}
|
|
108
|
+
/** Default (kungal-user:) mention schema — for advanced direct use. */
|
|
98
109
|
declare const mentionSchema: _milkdown_kit_utils.$NodeSchema<"mention">;
|
|
99
|
-
/**
|
|
110
|
+
/** Default (kungal-user:) mention remark transform — for advanced direct use. */
|
|
100
111
|
declare const remarkMentionPlugin: _milkdown_kit_utils.$Remark<"remarkMention", unknown>;
|
|
101
112
|
/**
|
|
102
113
|
* Insert a mention chip at the cursor, replacing the selection. The render-layer
|
|
103
|
-
* dropdown
|
|
104
|
-
*
|
|
105
|
-
* continue past the atom naturally.
|
|
114
|
+
* dropdown usually replaces the `@query` range itself; this is the programmatic
|
|
115
|
+
* path (toolbar / tests / the imperative insertMention handle). A trailing space
|
|
116
|
+
* lets the caret continue past the atom naturally. Resolves the node type by id
|
|
117
|
+
* from the live schema, so it works with any mention config.
|
|
106
118
|
*/
|
|
107
119
|
declare const insertMentionCommand: _milkdown_kit_utils.$Command<{
|
|
108
120
|
userId: number;
|
|
109
121
|
name: string;
|
|
110
122
|
}>;
|
|
111
|
-
/**
|
|
112
|
-
*
|
|
113
|
-
|
|
123
|
+
/**
|
|
124
|
+
* The mention plugin bundle: schema + remark round-trip + insert command. Pass
|
|
125
|
+
* `toUrl` / `fromUrl` to use a host-specific mention link form; omit for the
|
|
126
|
+
* default `kungal-user:` scheme. The `searchMentionUsers` adapter (the `@`
|
|
127
|
+
* autocomplete) is consumed by the render-layer dropdown.
|
|
128
|
+
*/
|
|
129
|
+
declare const createMentionPlugin: (config?: MentionUrlConfig) => MilkdownPlugin[];
|
|
114
130
|
|
|
115
131
|
declare const quoteId = "quote";
|
|
116
132
|
/** The payload a host passes to insert a reference. `refId` is opaque (the host
|
|
@@ -182,4 +198,4 @@ interface KunEditorPluginOptions {
|
|
|
182
198
|
*/
|
|
183
199
|
declare const createKunEditorPlugins: (adapters?: KunEditorAdapters, features?: KunEditorFeatures, options?: KunEditorPluginOptions) => MilkdownPlugin[];
|
|
184
200
|
|
|
185
|
-
export { type CodeBlockOptions, type KunEditorPluginOptions, type QuoteReference, type UploadPluginOptions, applyCodeBlockConfig, applyUploadConfig, blockKatexSchema, chevronDownIcon, clearIcon, copyIcon, createCodeBlockPlugins, createKatexPlugins, createKunEditorPlugins, createMentionPlugin, createQuotePlugin, createSpoilerPlugin, createStopLinkPlugin, createUploadPlugin, createUploadWidgetFactory, createUploader, editIcon, insertKunSpoilerCommand, insertMentionCommand, insertQuoteCommand, insertSpoilerInputRule, kunCM, kunCMHighlightStyle, kunCMTheme, linkCustomKeymap, mathBlockInputRule, mathInlineId, mathInlineInputRule, mathInlineSchema, mentionId, mentionSchema, quoteId, quoteSchema, remarkMathBlockPlugin, remarkMathPlugin, remarkMentionPlugin, remarkQuotePlugin, remarkSpoilerPlugin, searchIcon, spoilerAttr, spoilerSchema, stopLinkCommand, toggleLatexCommand, visibilityOffIcon };
|
|
201
|
+
export { type CodeBlockOptions, type KunEditorPluginOptions, type MentionUrlConfig, type QuoteReference, type UploadPluginOptions, applyCodeBlockConfig, applyUploadConfig, blockKatexSchema, chevronDownIcon, clearIcon, copyIcon, createCodeBlockPlugins, createKatexPlugins, createKunEditorPlugins, createMentionPlugin, createQuotePlugin, createSpoilerPlugin, createStopLinkPlugin, createUploadPlugin, createUploadWidgetFactory, createUploader, editIcon, insertKunSpoilerCommand, insertMentionCommand, insertQuoteCommand, insertSpoilerInputRule, kunCM, kunCMHighlightStyle, kunCMTheme, linkCustomKeymap, mathBlockInputRule, mathInlineId, mathInlineInputRule, mathInlineSchema, mentionId, mentionSchema, quoteId, quoteSchema, remarkMathBlockPlugin, remarkMathPlugin, remarkMentionPlugin, remarkQuotePlugin, remarkSpoilerPlugin, searchIcon, spoilerAttr, spoilerSchema, stopLinkCommand, toggleLatexCommand, visibilityOffIcon };
|
package/dist/preset/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QUOTE_SCHEME, MENTION_SCHEME } from '../chunk-KY2VN6IQ.js';
|
|
2
2
|
import { linkSchema, codeBlockSchema, commonmark } from '@milkdown/kit/preset/commonmark';
|
|
3
3
|
import { gfm } from '@milkdown/kit/preset/gfm';
|
|
4
4
|
import { history } from '@milkdown/kit/plugin/history';
|
|
@@ -716,7 +716,13 @@ var codeBlockConfigPlugin = (options) => (ctx) => () => {
|
|
|
716
716
|
};
|
|
717
717
|
var createCodeBlockPlugins = (options = {}) => [...codeBlockComponent, codeBlockConfigPlugin(options)];
|
|
718
718
|
var mentionId = "mention";
|
|
719
|
-
var
|
|
719
|
+
var defaultToUrl = (userId) => `${MENTION_SCHEME}${userId}`;
|
|
720
|
+
var defaultFromUrl = (url) => {
|
|
721
|
+
if (!url.startsWith(MENTION_SCHEME)) return null;
|
|
722
|
+
const id = Number.parseInt(url.slice(MENTION_SCHEME.length), 10);
|
|
723
|
+
return Number.isInteger(id) && id > 0 ? id : null;
|
|
724
|
+
};
|
|
725
|
+
var makeMentionSchema = (toUrl) => $nodeSchema(mentionId, () => ({
|
|
720
726
|
group: "inline",
|
|
721
727
|
inline: true,
|
|
722
728
|
atom: true,
|
|
@@ -755,29 +761,24 @@ var mentionSchema = $nodeSchema(mentionId, () => ({
|
|
|
755
761
|
toMarkdown: {
|
|
756
762
|
match: (node) => node.type.name === mentionId,
|
|
757
763
|
runner: (state, node) => {
|
|
758
|
-
state.openNode("link", void 0, {
|
|
759
|
-
url: `${MENTION_SCHEME}${node.attrs.userId}`
|
|
760
|
-
});
|
|
764
|
+
state.openNode("link", void 0, { url: toUrl(node.attrs.userId) });
|
|
761
765
|
state.addNode("text", void 0, `@${node.attrs.name}`);
|
|
762
766
|
state.closeNode();
|
|
763
767
|
}
|
|
764
768
|
}
|
|
765
769
|
}));
|
|
766
|
-
var
|
|
770
|
+
var makeRemarkMention = (fromUrl) => $remark("remarkMention", () => () => {
|
|
767
771
|
const transformer = (tree) => {
|
|
768
772
|
visit(tree, "link", (node, index, parent) => {
|
|
769
|
-
if (typeof node.url !== "string"
|
|
773
|
+
if (typeof node.url !== "string") {
|
|
770
774
|
return;
|
|
771
775
|
}
|
|
772
|
-
const userId =
|
|
773
|
-
if (
|
|
776
|
+
const userId = fromUrl(node.url);
|
|
777
|
+
if (userId == null) {
|
|
774
778
|
return;
|
|
775
779
|
}
|
|
776
780
|
const first = node.children?.[0];
|
|
777
|
-
const name = (typeof first?.value === "string" ? first.value : "").replace(
|
|
778
|
-
/^@/,
|
|
779
|
-
""
|
|
780
|
-
);
|
|
781
|
+
const name = (typeof first?.value === "string" ? first.value : "").replace(/^@/, "");
|
|
781
782
|
if (typeof index === "number" && parent.children) {
|
|
782
783
|
parent.children.splice(index, 1, {
|
|
783
784
|
type: mentionId,
|
|
@@ -789,9 +790,11 @@ var remarkMentionPlugin = $remark("remarkMention", () => () => {
|
|
|
789
790
|
};
|
|
790
791
|
return transformer;
|
|
791
792
|
});
|
|
793
|
+
var mentionSchema = makeMentionSchema(defaultToUrl);
|
|
794
|
+
var remarkMentionPlugin = makeRemarkMention(defaultFromUrl);
|
|
792
795
|
var insertMentionCommand = $command(
|
|
793
796
|
"InsertKunMention",
|
|
794
|
-
(
|
|
797
|
+
() => (payload) => (state, dispatch) => {
|
|
795
798
|
if (!payload || !dispatch) {
|
|
796
799
|
return false;
|
|
797
800
|
}
|
|
@@ -799,17 +802,22 @@ var insertMentionCommand = $command(
|
|
|
799
802
|
if (!Number.isInteger(userId) || userId <= 0) {
|
|
800
803
|
return false;
|
|
801
804
|
}
|
|
802
|
-
const
|
|
803
|
-
if (!
|
|
805
|
+
const type = state.schema.nodes[mentionId];
|
|
806
|
+
if (!type) {
|
|
804
807
|
return false;
|
|
805
808
|
}
|
|
809
|
+
const node = type.create({ userId, name });
|
|
806
810
|
const tr = state.tr.replaceSelectionWith(node);
|
|
807
811
|
tr.insertText(" ");
|
|
808
812
|
dispatch(tr.scrollIntoView());
|
|
809
813
|
return true;
|
|
810
814
|
}
|
|
811
815
|
);
|
|
812
|
-
var createMentionPlugin = () =>
|
|
816
|
+
var createMentionPlugin = (config = {}) => {
|
|
817
|
+
const schema = config.toUrl ? makeMentionSchema(config.toUrl) : mentionSchema;
|
|
818
|
+
const remark = config.fromUrl ? makeRemarkMention(config.fromUrl) : remarkMentionPlugin;
|
|
819
|
+
return [schema, remark, insertMentionCommand].flat();
|
|
820
|
+
};
|
|
813
821
|
var quoteId = "quote";
|
|
814
822
|
var quoteSchema = $nodeSchema(quoteId, () => ({
|
|
815
823
|
group: "inline",
|
|
@@ -984,7 +992,12 @@ var createKunEditorPlugins = (adapters = {}, features = {}, options = {}) => {
|
|
|
984
992
|
plugins.push(createSpoilerPlugin());
|
|
985
993
|
}
|
|
986
994
|
if (mention) {
|
|
987
|
-
plugins.push(
|
|
995
|
+
plugins.push(
|
|
996
|
+
createMentionPlugin({
|
|
997
|
+
toUrl: adapters.mentionToUrl,
|
|
998
|
+
fromUrl: adapters.mentionFromUrl
|
|
999
|
+
})
|
|
1000
|
+
);
|
|
988
1001
|
}
|
|
989
1002
|
if (quote) {
|
|
990
1003
|
plugins.push(createQuotePlugin());
|