@blankdotpage/cake 0.1.46 → 0.1.47

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 +1 @@
1
- {"version":3,"file":"link-popover.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/link/link-popover.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AA0DlD,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,MAAM,GACP,EAAE;IACD,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B,kDAkXA"}
1
+ {"version":3,"file":"link-popover.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/link/link-popover.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AA0DlD,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,MAAM,GACP,EAAE;IACD,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B,kDAiYA"}
@@ -155,6 +155,10 @@ export function CakeLinkPopover({ editor, styles, }) {
155
155
  useEffect(() => {
156
156
  function handleUpdate() {
157
157
  if (stateRef.current.status !== "closed") {
158
+ const anchor = anchorRef.current;
159
+ if (!anchor || !anchor.isConnected) {
160
+ close();
161
+ }
158
162
  return;
159
163
  }
160
164
  const selection = editor.getSelection();
@@ -230,6 +234,11 @@ export function CakeLinkPopover({ editor, styles, }) {
230
234
  if (state.status !== "open") {
231
235
  return;
232
236
  }
237
+ const selection = getSelection();
238
+ if (!selection) {
239
+ close();
240
+ return;
241
+ }
233
242
  const draftValue = inputRef.current?.value ?? state.draftUrl;
234
243
  const trimmed = draftValue.trim();
235
244
  if (!trimmed) {
@@ -237,8 +246,13 @@ export function CakeLinkPopover({ editor, styles, }) {
237
246
  return;
238
247
  }
239
248
  const nextUrl = ensureHttpsProtocol(trimmed);
240
- const anchor = anchorRef.current;
241
- anchor?.setAttribute("href", nextUrl);
249
+ executeCommand({
250
+ type: "set-link-url",
251
+ start: selection.start,
252
+ end: selection.end,
253
+ url: nextUrl,
254
+ selectLabel: state.url.trim() === "",
255
+ });
242
256
  setState({
243
257
  status: "open",
244
258
  url: nextUrl,
@@ -12,8 +12,16 @@ export type UnlinkCommand = {
12
12
  start: number;
13
13
  end: number;
14
14
  };
15
+ /** Command to update the URL for an existing link */
16
+ export type SetLinkUrlCommand = {
17
+ type: "set-link-url";
18
+ start: number;
19
+ end: number;
20
+ url: string;
21
+ selectLabel?: boolean;
22
+ };
15
23
  /** All link extension commands */
16
- export type LinkCommand = WrapLinkCommand | UnlinkCommand;
24
+ export type LinkCommand = WrapLinkCommand | UnlinkCommand | SetLinkUrlCommand;
17
25
  export type OnRequestLinkInput = (editor: CakeEditor) => Promise<{
18
26
  url: string;
19
27
  text: string;
@@ -1 +1 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/link/link.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,oBAAoB,CAAC;AAU5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AA2F3D,8CAA8C;AAC9C,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,kCAAkC;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,CAAC,EAAE,oBAAoB,GAAG,aAAa,CAAC"}
@@ -193,6 +193,56 @@ function installLinkExtension(editor, options) {
193
193
  },
194
194
  };
195
195
  }
196
+ if (command.type === "set-link-url") {
197
+ const cursorPos = Math.min(command.start, command.end);
198
+ const sourcePos = state.map.cursorToSource(cursorPos, "forward");
199
+ const source = state.source;
200
+ // Search backwards for the opening bracket
201
+ let linkStart = sourcePos;
202
+ while (linkStart > 0 && source[linkStart] !== "[") {
203
+ linkStart--;
204
+ }
205
+ if (source[linkStart] !== "[") {
206
+ return null;
207
+ }
208
+ // Find the ]( separator
209
+ const labelClose = source.indexOf("](", linkStart + 1);
210
+ if (labelClose === -1) {
211
+ return null;
212
+ }
213
+ // Find the closing )
214
+ const urlClose = source.indexOf(")", labelClose + 2);
215
+ if (urlClose === -1) {
216
+ return null;
217
+ }
218
+ const nextSource = source.slice(0, labelClose + 2) +
219
+ command.url +
220
+ source.slice(urlClose);
221
+ const nextState = state.runtime.createState(nextSource);
222
+ if (command.selectLabel) {
223
+ const labelStartSource = linkStart + 1;
224
+ const labelEndSource = labelClose;
225
+ const startCursor = nextState.map.sourceToCursor(labelStartSource, "forward");
226
+ const endCursor = nextState.map.sourceToCursor(labelEndSource, "backward");
227
+ return {
228
+ source: nextSource,
229
+ selection: {
230
+ start: startCursor.cursorOffset,
231
+ end: endCursor.cursorOffset,
232
+ affinity: "forward",
233
+ },
234
+ };
235
+ }
236
+ const endCursor = nextState.map.sourceToCursor(labelClose, "backward");
237
+ return {
238
+ source: nextSource,
239
+ selection: {
240
+ start: endCursor.cursorOffset,
241
+ end: endCursor.cursorOffset,
242
+ affinity: "backward",
243
+ },
244
+ };
245
+ }
196
246
  if (command.type !== "wrap-link") {
197
247
  return null;
198
248
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blankdotpage/cake",
3
- "version": "0.1.46",
3
+ "version": "0.1.47",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",