Skip to content

Commit

Permalink
Merge pull request #233 from KonnorRogers/main
Browse files Browse the repository at this point in the history
Main -> Latest
  • Loading branch information
KonnorRogers authored Nov 22, 2024
2 parents 5214072 + 8d0cc73 commit 0c7901c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 40 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.14.1

### Patch Changes

- [#231](https://github.com/KonnorRogers/rhino-editor/pull/231) [`01dbfbf`](https://github.com/KonnorRogers/rhino-editor/commit/01dbfbf01a421fe07f38ac005c2073f900c03ad8) Thanks [@KonnorRogers](https://github.com/KonnorRogers)! - Fix the hacky workaround for slow / unstable connections

- [#231](https://github.com/KonnorRogers/rhino-editor/pull/231) [`01dbfbf`](https://github.com/KonnorRogers/rhino-editor/commit/01dbfbf01a421fe07f38ac005c2073f900c03ad8) Thanks [@KonnorRogers](https://github.com/KonnorRogers)! - remove unnecessary console.log

- [#230](https://github.com/KonnorRogers/rhino-editor/pull/230) [`588abba`](https://github.com/KonnorRogers/rhino-editor/commit/588abba117d2fe2257b874832c94a0a91d274362) Thanks [@bjhess](https://github.com/bjhess)! - Fix the UX of link insertions

## 0.14.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rhino-editor",
"version": "0.14.0",
"version": "0.14.1",
"description": "A custom element wrapped rich text editor",
"type": "module",
"main": "exports/index.js",
Expand Down
20 changes: 20 additions & 0 deletions src/exports/attachment-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { uuidv4 } from "../internal/uuidv4.js";
import type { EditorView } from "@tiptap/pm/view";
import { LOADING_STATES } from "./elements/attachment-editor.js";
import { toDefaultCaption } from "../internal/to-default-caption.js";
import {
AttachmentUpload,
AttachmentUploadCompleteEvent,
AttachmentUploadSucceedEvent,
} from "./attachment-upload.js";

export interface AttachmentManagerAttributes {
src: string;
Expand Down Expand Up @@ -30,6 +35,7 @@ export interface AttachmentManagerAttributes {
export class AttachmentManager implements AttachmentManagerAttributes {
attributes: AttachmentManagerAttributes;
editorView: EditorView;
directUpload?: AttachmentUpload;

static get previewableRegex() {
return /^image(\/(gif|png|jpe?g)|$)/;
Expand Down Expand Up @@ -77,6 +83,8 @@ export class AttachmentManager implements AttachmentManagerAttributes {
previewable: this.isPreviewable,
});

this.handleSuccess();

return;
}

Expand Down Expand Up @@ -107,6 +115,7 @@ export class AttachmentManager implements AttachmentManagerAttributes {
previewable: this.isPreviewable,
});
image.remove();
this.handleSuccess();
};
return;
}
Expand All @@ -120,6 +129,17 @@ export class AttachmentManager implements AttachmentManagerAttributes {
contentType: this.contentType,
previewable: this.isPreviewable,
});
this.handleSuccess();
}

handleSuccess() {
this.setUploadProgress(100);
const upload = this.directUpload;

if (upload) {
upload.element.dispatchEvent(new AttachmentUploadSucceedEvent(upload));
upload.element.dispatchEvent(new AttachmentUploadCompleteEvent(upload));
}
}

/**
Expand Down
36 changes: 8 additions & 28 deletions src/exports/attachment-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,34 +152,14 @@ export class AttachmentUpload implements DirectUploadDelegate {
return;
}

const blobUrl = this.createBlobUrl(blob.signed_id, blob.filename);
this.attachment.setAttributes({
sgid: blob.attachable_sgid ?? "",
url: blobUrl,
});

// TODO: This may create problems for non-images, could use something like an `<object src="<url>">` instead.
const template = document.createElement("template");
const obj = document.createElement("object");
obj.toggleAttribute("hidden", true);
template.append(obj);

obj.onload = () => {
template.remove();
this.progress = 100;
this.setUploadProgress();
this.element.dispatchEvent(new AttachmentUploadSucceedEvent(this));
this.element.dispatchEvent(new AttachmentUploadCompleteEvent(this));
};

obj.onerror = () => {
template.remove();
this.handleError();
};

obj.data = blobUrl;
// Needs to append to for onerror / onload to fire.
document.body.append(template);
if (blob.attachable_sgid) {
const blobUrl = this.createBlobUrl(blob.signed_id, blob.filename);
this.attachment.directUpload = this;
this.attachment.setAttributes({
sgid: blob.attachable_sgid,
url: blobUrl,
});
}
}

setUploadProgress() {
Expand Down
1 change: 0 additions & 1 deletion src/exports/elements/tip-tap-editor-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ export class TipTapEditorBase extends BaseElement {
return attachment === e.attachmentUpload;
});

console.log("complete");
if (index > -1) {
this.pendingAttachments.splice(index, 1);
}
Expand Down
25 changes: 15 additions & 10 deletions src/exports/elements/tip-tap-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export class TipTapEditor extends TipTapEditorBase {

closeLinkDialog(): void {
this.linkDialogExpanded = false;
this.editor?.commands.focus();
}

showLinkDialog(): void {
Expand Down Expand Up @@ -350,24 +351,29 @@ export class TipTapEditor extends TipTapEditorBase {
} catch (error) {
inputElement.setCustomValidity("Not a valid URL");
this.__invalidLink__ = true;
inputElement.reportValidity();
return;
}

if (!this.editor) {
return;
}

if (href) {
this.closeLinkDialog();
inputElement.value = "";
const chain = this.editor
?.chain()
.extendMarkRange("link")
.setLink({ href });

if (chain && this.editor?.state.selection.empty) {
chain.insertContent(href);
if (
this.editor.state.selection.empty &&
!this.editor.getAttributes("link").href
) {
const from = this.editor.state.selection.anchor;
this.editor.commands.insertContent(href);
const to = this.editor.state.selection.anchor;
this.editor.commands.setTextSelection({ from, to });
}

if (chain) {
chain.run();
}
this.editor?.chain().extendMarkRange("link").setLink({ href }).run();
}
}

Expand Down Expand Up @@ -1559,7 +1565,6 @@ export class TipTapEditor extends TipTapEditorBase {
if (e.defaultPrevented) {
return;
}
console.log("show");
const anchoredRegion = e.currentTarget as RoleAnchoredRegion;
anchoredRegion.anchor = { getBoundingClientRect: e.clientRect };
Expand Down

0 comments on commit 0c7901c

Please sign in to comment.