@kungal/editor-core 0.25.1 → 0.26.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 CHANGED
@@ -1,5 +1,34 @@
1
1
  # @kungal/editor-core
2
2
 
3
+ ## 0.26.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 945708d: Add an insert-link feature (click to add a URL).
8
+
9
+ The `link` mark already existed (so `[text](url)` round-trips and pasted URLs
10
+ autolink), but there was no click-to-insert UI. Now there is:
11
+
12
+ - **editor-core**: `insertLinkCommand` (`{ href, text? }`) — applies the link mark
13
+ to the selection, or inserts linked text on an empty selection; clears the
14
+ stored mark afterwards. Re-exported from `@kungal/editor-core/preset`.
15
+ - **editor-vue**: `KunEditorToolbarApi.insertLink(payload)`; a `link` button in the
16
+ default toolbar and the selection bubble (both default-on); `'link'` added to
17
+ `KunToolbarItem` and `KunSelectionItem`. Headless UI prompts for the URL.
18
+ - **editor-nuxt**: `<KunEditorToolbar>` gains a `link` button — a KunPopover with a
19
+ KunInput for the URL.
20
+
21
+ A link is a **mark** (`[text](url)`), deliberately distinct from the custom-NODE
22
+ embeds (mention / quote). A future "article card" or custom component would be a
23
+ node like those (schema + toUrl/fromUrl), not this — a separate mechanism.
24
+
25
+ Verified in the docs production build: the KunUI toolbar popover wraps a selection
26
+ (`[…](https://example.com)`); the selection bubble does too
27
+ (`[linktext](https://kun.com)`); 4 new core tests (wrap / insert / autolink
28
+ fallback / blank-href no-op) pass; 0 console errors.
29
+
30
+ ## 0.25.2
31
+
3
32
  ## 0.25.1
4
33
 
5
34
  ## 0.25.0
@@ -196,6 +196,29 @@ var linkCustomKeymap = utils.$useKeymap("linkCustomKeymap", {
196
196
  }
197
197
  });
198
198
  var createStopLinkPlugin = () => [stopLinkCommand, linkCustomKeymap].flat();
199
+ var insertLinkCommand = utils.$command(
200
+ "InsertKunLink",
201
+ (ctx) => (payload) => (state, dispatch) => {
202
+ const href = payload?.href?.trim();
203
+ if (!href) {
204
+ return false;
205
+ }
206
+ const markType = commonmark.linkSchema.type(ctx);
207
+ const mark = markType.create({ href });
208
+ const { from, to, empty } = state.selection;
209
+ if (empty) {
210
+ const text = payload?.text?.trim() || href;
211
+ const tr = state.tr.insertText(text, from);
212
+ tr.addMark(from, from + text.length, mark);
213
+ tr.removeStoredMark(markType);
214
+ dispatch?.(tr.scrollIntoView());
215
+ } else {
216
+ dispatch?.(state.tr.addMark(from, to, mark).scrollIntoView());
217
+ }
218
+ return true;
219
+ }
220
+ );
221
+ var createLinkPlugin = () => [insertLinkCommand].flat();
199
222
  var setHeadingCommand = utils.$command(
200
223
  "SetHeadingKun",
201
224
  (ctx) => (level = 0) => level >= 1 && level <= 6 ? commands.setBlockType(commonmark.headingSchema.type(ctx), { level }) : commands.setBlockType(commonmark.paragraphSchema.type(ctx))
@@ -1160,6 +1183,7 @@ var createKunEditorPlugins = (adapters = {}, features = {}, options = {}) => {
1160
1183
  plugins.push(imageUploadPlaceholder);
1161
1184
  }
1162
1185
  plugins.push(createStopLinkPlugin());
1186
+ plugins.push(createLinkPlugin());
1163
1187
  plugins.push(createHeadingPlugin());
1164
1188
  if (options.placeholder) {
1165
1189
  plugins.push(
@@ -1182,6 +1206,7 @@ exports.createCodeBlockPlugins = createCodeBlockPlugins;
1182
1206
  exports.createHeadingPlugin = createHeadingPlugin;
1183
1207
  exports.createKatexPlugins = createKatexPlugins;
1184
1208
  exports.createKunEditorPlugins = createKunEditorPlugins;
1209
+ exports.createLinkPlugin = createLinkPlugin;
1185
1210
  exports.createMentionPlugin = createMentionPlugin;
1186
1211
  exports.createPlaceholderPlugin = createPlaceholderPlugin;
1187
1212
  exports.createQuotePlugin = createQuotePlugin;
@@ -1193,6 +1218,7 @@ exports.createUploader = createUploader;
1193
1218
  exports.editIcon = editIcon;
1194
1219
  exports.imageUploadPlaceholder = imageUploadPlaceholder;
1195
1220
  exports.insertKunSpoilerCommand = insertKunSpoilerCommand;
1221
+ exports.insertLinkCommand = insertLinkCommand;
1196
1222
  exports.insertMentionCommand = insertMentionCommand;
1197
1223
  exports.insertQuoteCommand = insertQuoteCommand;
1198
1224
  exports.insertSpoilerInputRule = insertSpoilerInputRule;