@threadlabs/looma 0.44.3 → 0.44.5
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/components/ui-button/ui-button.html +3 -3
- package/components/ui-icon-button/ui-icon-button.html +5 -24
- package/dist/index.js +1 -1
- package/docs/README.md +1 -1
- package/docs/catalog.json +18 -10
- package/docs/theme.mjs +25 -10
- package/editor/file-uploads.d.ts +3 -1
- package/package.json +1 -1
- package/styles/ui-button.css +3 -3
- package/styles/ui-icon-button.css +5 -24
- package/tokens.css +7 -7
- package/vue/UiButton.vue +3 -6
- package/vue/UiIconButton.vue +7 -17
- package/vue/chunks/UiButton.js +1 -1
- package/vue/chunks/UiIconButton.js +1 -1
- package/vue/chunks/compact.js +1 -1
- package/vue/components.css +18 -50
- package/vue/editor/index.js +105 -57
package/vue/editor/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { n as LoomaCompactEditor } from "../chunks/compact.js";
|
|
|
2
2
|
import { Teleport, computed, defineComponent, h, nextTick, onBeforeUnmount, onMounted, onUpdated, reactive, ref, shallowRef, useId, watch } from "vue";
|
|
3
3
|
import { DEFAULT_MENTION_RESULT_LIMIT, LOOMA_ICONS, createLoomaMentionExtension, createLoomaSlashCommandExtension, getActiveTableUiState, getDefaultEditorExtensions, getDefaultSlashCommands, getTableOfContentsEntries, getVisualViewportRect, handleTableAction, handleTableOverlayAction, measureTableOverlayGeometry, normalizeActiveTableColumnWidths, normalizeTableOfContentsConfig } from "@threadlabs/looma/editor";
|
|
4
4
|
import { Button, Card, Cluster, EditorBlockActions, EditorChipEditor, EditorCodeLanguage, EditorFootnoteEditor, EditorImageToolbar, EditorInsertTableGrid, EditorLinkCard, EditorLinkForm, EditorMentionMenu, EditorMentionMenuItem, EditorSlashMenu, EditorSlashMenuGroup, EditorSlashMenuItem, EditorSurface, EditorTableContextMenu, EditorTableOverlay, EditorTableToolbar, EditorToolbar, IconButton, Popover, Stack, StatusMessage, Text, Tooltip } from "@threadlabs/looma/vue";
|
|
5
|
+
import { closeHistory } from "@tiptap/pm/history";
|
|
5
6
|
import { Editor, Extension, InputRule, Node as Node$1, PasteRule, getText, getTextSerializersFromSchema, isNodeSelection, mergeAttributes, nodeInputRule, posToDOMRect } from "@tiptap/core";
|
|
6
7
|
import { Editor as Editor$1 } from "@tiptap/vue-3";
|
|
7
8
|
import { AllSelection, NodeSelection, Plugin, PluginKey, Selection, TextSelection } from "@tiptap/pm/state";
|
|
@@ -9,7 +10,6 @@ import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
|
9
10
|
import { createLowlight } from "lowlight";
|
|
10
11
|
import { RequestEvent, componentRegistry } from "@nextwebwg/html-next/runtime";
|
|
11
12
|
import "@tiptap/pm/tables";
|
|
12
|
-
import { closeHistory } from "@tiptap/pm/history";
|
|
13
13
|
import { DOMParser, DOMSerializer, Fragment as Fragment$1, Slice } from "@tiptap/pm/model";
|
|
14
14
|
import "@tiptap/pm/transform";
|
|
15
15
|
import { IndexedList, NONCONFORMING, READY_INPUT, UNRESOLVED_INPUT, acceptProps, activateModule, armElement, attachGeneratedController, awaitInput, buildTemplate, checkBoolean, checkConstrained, checkFormat, checkInteger, checkNumber, checkObject, checkSelected, checkString, clearRegion, computedCycle, defineComponent as defineComponent$1, detailCheck, dispatchDeclared, dispose, evaluateInput, fillSlot, formatOf, generatedInputs, hostState, inputRead, keywordFormat, manageProps, notifyPropertySet, project, readIndex, readMember, readonlyView, readsChanged, rec, recordValue, replaceRoot, textCall, toAttribute, toText, trackContainer, truthy, writeAttribute, writeUrlAttribute } from "@nextwebwg/html-next/generated-runtime";
|
|
@@ -49,68 +49,102 @@ var EDITOR_ADAPTER_COMPONENT_TAG_MAP = {
|
|
|
49
49
|
};
|
|
50
50
|
//#endregion
|
|
51
51
|
//#region src/editor/file-uploads.ts
|
|
52
|
-
/** Captures the caret before
|
|
52
|
+
/** Captures the caret before transport and retains its mapped position for an explicit retry. */
|
|
53
53
|
function createFileUploads(options) {
|
|
54
|
+
const { editor } = options;
|
|
54
55
|
let active;
|
|
55
|
-
const state = (uploading, progress = null) => options.onState?.({
|
|
56
|
+
const state = (uploading, progress = null, failed = null) => options.onState?.({
|
|
56
57
|
uploading,
|
|
57
|
-
progress
|
|
58
|
+
progress,
|
|
59
|
+
failed
|
|
58
60
|
});
|
|
61
|
+
const finish = (job) => {
|
|
62
|
+
if (active !== job) return;
|
|
63
|
+
if (job) editor.off("transaction", job.map);
|
|
64
|
+
active = void 0;
|
|
65
|
+
state(false);
|
|
66
|
+
};
|
|
67
|
+
const cancel = (job) => {
|
|
68
|
+
if (active !== job) return;
|
|
69
|
+
job?.controller?.abort();
|
|
70
|
+
finish(job);
|
|
71
|
+
};
|
|
72
|
+
const run = async (job) => {
|
|
73
|
+
const upload = options.upload();
|
|
74
|
+
if (!upload || editor.isDestroyed || !editor.isEditable) {
|
|
75
|
+
cancel(job);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const controller = new AbortController();
|
|
79
|
+
job.controller = controller;
|
|
80
|
+
job.failed = false;
|
|
81
|
+
const current = () => active === job && job.controller === controller && !controller.signal.aborted;
|
|
82
|
+
state(true);
|
|
83
|
+
try {
|
|
84
|
+
const answer = await upload(job.file, {
|
|
85
|
+
signal: controller.signal,
|
|
86
|
+
progress: (loaded, total) => {
|
|
87
|
+
if (current() && !job.failed) state(true, {
|
|
88
|
+
loaded,
|
|
89
|
+
total
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
if (!current()) return;
|
|
94
|
+
if (!answer || editor.isDestroyed || !editor.isEditable) {
|
|
95
|
+
finish(job);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!/^(?:https?:\/\/|\/(?!\/))/.test(answer.href) || !Number.isSafeInteger(answer.size) || answer.size < 0) throw new Error("Invalid file descriptor");
|
|
99
|
+
const size = answer.size < 1e3 ? `${answer.size} B` : answer.size < 1e6 ? `${Math.ceil(answer.size / 1e3)} KB` : `${Number((answer.size / 1e6).toFixed(1))} MB`;
|
|
100
|
+
editor.view.dispatch(closeHistory(editor.state.tr));
|
|
101
|
+
editor.chain().focus().insertContentAt(job.position, [{
|
|
102
|
+
type: "text",
|
|
103
|
+
text: answer.name || job.file.name,
|
|
104
|
+
marks: [{
|
|
105
|
+
type: "link",
|
|
106
|
+
attrs: {
|
|
107
|
+
href: answer.href,
|
|
108
|
+
target: "_blank",
|
|
109
|
+
rel: "noopener noreferrer"
|
|
110
|
+
}
|
|
111
|
+
}]
|
|
112
|
+
}, {
|
|
113
|
+
type: "text",
|
|
114
|
+
text: ` (${answer.contentType || "application/octet-stream"}, ${size}) `
|
|
115
|
+
}]).run();
|
|
116
|
+
editor.view.dispatch(closeHistory(editor.state.tr));
|
|
117
|
+
if (current()) finish(job);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (!current()) return;
|
|
120
|
+
job.failed = true;
|
|
121
|
+
state(false, null, job.file);
|
|
122
|
+
options.onError(error, job.file);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
59
125
|
return {
|
|
60
126
|
cancel() {
|
|
61
|
-
active
|
|
62
|
-
state(false);
|
|
127
|
+
cancel(active);
|
|
63
128
|
},
|
|
64
129
|
async insert(file) {
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
editor.on("transaction", map);
|
|
76
|
-
state(true);
|
|
77
|
-
try {
|
|
78
|
-
const answer = await upload(file, {
|
|
79
|
-
signal: controller.signal,
|
|
80
|
-
progress: (loaded, total) => {
|
|
81
|
-
if (!controller.signal.aborted) state(true, {
|
|
82
|
-
loaded,
|
|
83
|
-
total
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
if (!answer || controller.signal.aborted || editor.isDestroyed || !editor.isEditable) return;
|
|
88
|
-
if (!/^(?:https?:\/\/|\/(?!\/))/.test(answer.href) || !Number.isSafeInteger(answer.size) || answer.size < 0) throw new Error("Invalid file descriptor");
|
|
89
|
-
const size = answer.size < 1e3 ? `${answer.size} B` : answer.size < 1e6 ? `${Math.ceil(answer.size / 1e3)} KB` : `${Number((answer.size / 1e6).toFixed(1))} MB`;
|
|
90
|
-
editor.chain().focus().insertContentAt(position, [{
|
|
91
|
-
type: "text",
|
|
92
|
-
text: answer.name || file.name,
|
|
93
|
-
marks: [{
|
|
94
|
-
type: "link",
|
|
95
|
-
attrs: {
|
|
96
|
-
href: answer.href,
|
|
97
|
-
target: "_blank",
|
|
98
|
-
rel: "noopener noreferrer"
|
|
99
|
-
}
|
|
100
|
-
}]
|
|
101
|
-
}, {
|
|
102
|
-
type: "text",
|
|
103
|
-
text: ` (${answer.contentType || "application/octet-stream"}, ${size}) `
|
|
104
|
-
}]).run();
|
|
105
|
-
} catch (error) {
|
|
106
|
-
if (!controller.signal.aborted) options.onError(error, file);
|
|
107
|
-
} finally {
|
|
108
|
-
editor.off("transaction", map);
|
|
109
|
-
if (active === controller) {
|
|
110
|
-
active = void 0;
|
|
111
|
-
state(false);
|
|
130
|
+
cancel(active);
|
|
131
|
+
if (editor.isDestroyed || !editor.isEditable) return;
|
|
132
|
+
const job = {
|
|
133
|
+
file,
|
|
134
|
+
position: editor.state.selection.from,
|
|
135
|
+
failed: false,
|
|
136
|
+
map: ({ transaction }) => {
|
|
137
|
+
const mapped = transaction.mapping.mapResult(job.position);
|
|
138
|
+
if (mapped.deletedAcross) cancel(job);
|
|
139
|
+
else job.position = mapped.pos;
|
|
112
140
|
}
|
|
113
|
-
}
|
|
141
|
+
};
|
|
142
|
+
active = job;
|
|
143
|
+
editor.on("transaction", job.map);
|
|
144
|
+
await run(job);
|
|
145
|
+
},
|
|
146
|
+
async retry() {
|
|
147
|
+
if (active?.failed) await run(active);
|
|
114
148
|
}
|
|
115
149
|
};
|
|
116
150
|
}
|
|
@@ -15239,7 +15273,7 @@ var EMPTY_DOCUMENT = {
|
|
|
15239
15273
|
type: "doc",
|
|
15240
15274
|
content: []
|
|
15241
15275
|
};
|
|
15242
|
-
var uploadProgressText = (progress) => progress && progress.total > 0 ?
|
|
15276
|
+
var uploadProgressText = (progress, label = "Uploading image…") => progress && progress.total > 0 ? `${label} ${Math.round(Math.min(1, progress.loaded / progress.total) * 100)}%` : label;
|
|
15243
15277
|
var editorInstanceSequence = 0;
|
|
15244
15278
|
function slashMenuRows(items) {
|
|
15245
15279
|
const groups = [];
|
|
@@ -15444,7 +15478,8 @@ var LoomaEditor = defineComponent({
|
|
|
15444
15478
|
const attachmentInput = ref(null);
|
|
15445
15479
|
const fileUploadState = shallowRef({
|
|
15446
15480
|
uploading: false,
|
|
15447
|
-
progress: null
|
|
15481
|
+
progress: null,
|
|
15482
|
+
failed: null
|
|
15448
15483
|
});
|
|
15449
15484
|
let attachmentUploads;
|
|
15450
15485
|
const tablePickerAnchorId = `looma-editor-table-picker-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
@@ -16894,13 +16929,26 @@ var LoomaEditor = defineComponent({
|
|
|
16894
16929
|
onChange: onAttachmentChange
|
|
16895
16930
|
}),
|
|
16896
16931
|
fileUploadState.value.uploading ? h(StatusMessage, { kind: "loading" }, {
|
|
16897
|
-
default: () => "Attaching file…",
|
|
16932
|
+
default: () => uploadProgressText(fileUploadState.value.progress, "Attaching file…"),
|
|
16898
16933
|
action: () => h(Button, {
|
|
16899
16934
|
size: "sm",
|
|
16900
16935
|
variant: "ghost",
|
|
16901
16936
|
onClick: () => attachmentUploads?.cancel()
|
|
16902
16937
|
}, () => "Cancel")
|
|
16903
16938
|
}) : null,
|
|
16939
|
+
fileUploadState.value.failed ? h(StatusMessage, { kind: "error" }, {
|
|
16940
|
+
default: () => "Couldn’t attach file.",
|
|
16941
|
+
action: () => [h(Button, {
|
|
16942
|
+
size: "sm",
|
|
16943
|
+
variant: "ghost",
|
|
16944
|
+
onClick: () => attachmentUploads?.cancel()
|
|
16945
|
+
}, () => "Dismiss"), h(Button, {
|
|
16946
|
+
size: "sm",
|
|
16947
|
+
onClick: () => {
|
|
16948
|
+
attachmentUploads?.retry();
|
|
16949
|
+
}
|
|
16950
|
+
}, () => "Retry")]
|
|
16951
|
+
}) : null,
|
|
16904
16952
|
uploadState.value.uploading ? h(StatusMessage, { kind: "loading" }, {
|
|
16905
16953
|
default: () => uploadProgressText(uploadState.value.progress),
|
|
16906
16954
|
action: () => h(Button, {
|