@humandialog/forms.svelte 1.2.4 → 1.2.7
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,5 +1,5 @@
|
|
|
1
|
-
<script>import { onMount, onDestroy, getContext } from "svelte";
|
|
2
|
-
import { session } from "@humandialog/auth.svelte";
|
|
1
|
+
<script>import { onMount, onDestroy, getContext, afterUpdate } from "svelte";
|
|
2
|
+
import { reef, session } from "@humandialog/auth.svelte";
|
|
3
3
|
import { Editor } from "@tiptap/core";
|
|
4
4
|
import StarterKit from "@tiptap/starter-kit";
|
|
5
5
|
import Document from "@tiptap/extension-document";
|
|
@@ -17,7 +17,7 @@ import Strike from "@tiptap/extension-strike";
|
|
|
17
17
|
import Dropcursor from "@tiptap/extension-dropcursor";
|
|
18
18
|
import Gapcursor from "@tiptap/extension-gapcursor";
|
|
19
19
|
import History from "@tiptap/extension-history";
|
|
20
|
-
import { data_tick_store, contextItemsStore, contextTypesStore } from "../../stores.js";
|
|
20
|
+
import { data_tick_store, contextItemsStore, contextTypesStore, onErrorShowAlert } from "../../stores.js";
|
|
21
21
|
import { informModification, pushChanges } from "../../updates.js";
|
|
22
22
|
import { isDeviceSmallerThan, parseWidthDirective } from "../../utils.js";
|
|
23
23
|
import Palette from "./internal/palette.svelte";
|
|
@@ -133,7 +133,8 @@ const suggestion = {
|
|
|
133
133
|
if (!props.clientRect) {
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
const cursorRect = props.clientRect();
|
|
137
|
+
show_command_palette(cursorRect);
|
|
137
138
|
palette.set_current_editor_range(props.range);
|
|
138
139
|
palette.filter("");
|
|
139
140
|
},
|
|
@@ -355,7 +356,8 @@ function prepareFullImagePath(url) {
|
|
|
355
356
|
} else {
|
|
356
357
|
fullPath += "?";
|
|
357
358
|
}
|
|
358
|
-
}
|
|
359
|
+
} else
|
|
360
|
+
fullPath += "&";
|
|
359
361
|
fullPath += param.key.toLowerCase();
|
|
360
362
|
fullPath += "=" + param.value;
|
|
361
363
|
}
|
|
@@ -380,11 +382,15 @@ function prepareFullImagePath(url) {
|
|
|
380
382
|
}
|
|
381
383
|
return fullPath;
|
|
382
384
|
}
|
|
385
|
+
let downloadedImages = [];
|
|
383
386
|
const CrossImage = Image.extend({
|
|
384
387
|
addAttributes() {
|
|
385
388
|
return {
|
|
386
|
-
crossorigin: {
|
|
387
|
-
|
|
389
|
+
//crossorigin: {
|
|
390
|
+
// default: 'use-credentials'
|
|
391
|
+
//},
|
|
392
|
+
loading: {
|
|
393
|
+
default: "lazy"
|
|
388
394
|
},
|
|
389
395
|
dataPath: {
|
|
390
396
|
default: null,
|
|
@@ -394,9 +400,42 @@ const CrossImage = Image.extend({
|
|
|
394
400
|
renderHTML: (attributes) => {
|
|
395
401
|
const dataPath = attributes.dataPath;
|
|
396
402
|
if (dataPath) {
|
|
403
|
+
let src = "";
|
|
404
|
+
let found = downloadedImages.find((e) => e.dataPath == dataPath);
|
|
405
|
+
if (found) {
|
|
406
|
+
if (found.url)
|
|
407
|
+
src = found.url;
|
|
408
|
+
} else {
|
|
409
|
+
const newEntry = {
|
|
410
|
+
dataPath,
|
|
411
|
+
url: ""
|
|
412
|
+
};
|
|
413
|
+
downloadedImages.push(newEntry);
|
|
414
|
+
reef.fetch(`/json/anyv/${dataPath}`).then(
|
|
415
|
+
(res) => {
|
|
416
|
+
if (res.ok) {
|
|
417
|
+
res.blob().then((blob) => {
|
|
418
|
+
newEntry.url = URL.createObjectURL(blob);
|
|
419
|
+
console.log("image loaded: ", dataPath, newEntry.url);
|
|
420
|
+
editorElement.querySelectorAll("img").forEach((img) => {
|
|
421
|
+
if (img.getAttribute("data-path") == dataPath)
|
|
422
|
+
img.src = newEntry.url;
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
} else {
|
|
426
|
+
res.text().then((err) => onErrorShowAlert(err));
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
(err) => {
|
|
430
|
+
onErrorShowAlert(err);
|
|
431
|
+
}
|
|
432
|
+
);
|
|
433
|
+
}
|
|
397
434
|
return {
|
|
398
435
|
"data-path": dataPath,
|
|
399
|
-
src: prepareFullImagePath(dataPath)
|
|
436
|
+
// src: prepareFullImagePath(dataPath)
|
|
437
|
+
// src: 'http://localhost/_hd_force_img_error'
|
|
438
|
+
src
|
|
400
439
|
};
|
|
401
440
|
} else {
|
|
402
441
|
return {};
|
|
@@ -451,7 +490,7 @@ onMount(() => {
|
|
|
451
490
|
onTransaction({ editor: editor2, transaction }) {
|
|
452
491
|
hasChangedValue = true;
|
|
453
492
|
changedValue = editor2.getHTML();
|
|
454
|
-
|
|
493
|
+
handleImagesChanges(transaction);
|
|
455
494
|
},
|
|
456
495
|
onFocus({ editor: editor2, event }) {
|
|
457
496
|
if (onFocusCb)
|
|
@@ -464,6 +503,8 @@ onMount(() => {
|
|
|
464
503
|
},
|
|
465
504
|
onContentError({ editor: editor2, error, disableCollaboration }) {
|
|
466
505
|
console.log("editor content error:", error);
|
|
506
|
+
},
|
|
507
|
+
onUpdate({ editor: editor2 }) {
|
|
467
508
|
}
|
|
468
509
|
});
|
|
469
510
|
});
|
|
@@ -528,8 +569,8 @@ function on_palette_shown() {
|
|
|
528
569
|
function on_palette_hidden() {
|
|
529
570
|
is_command_palette_visible = false;
|
|
530
571
|
}
|
|
531
|
-
function show_command_palette() {
|
|
532
|
-
let rect =
|
|
572
|
+
function show_command_palette(cursorRect) {
|
|
573
|
+
let rect = cursorRect;
|
|
533
574
|
let client_rect = get_window_box();
|
|
534
575
|
let top_space = rect.y;
|
|
535
576
|
let bottom_space = client_rect.height - (rect.y + rect.height);
|
|
@@ -569,19 +610,16 @@ function show_command_palette() {
|
|
|
569
610
|
else
|
|
570
611
|
palette.show(x, y, show_above);
|
|
571
612
|
}
|
|
572
|
-
function onAddedImageReady(dataPath) {
|
|
573
|
-
const imgFullPath = prepareFullImagePath(dataPath);
|
|
613
|
+
async function onAddedImageReady(dataPath) {
|
|
574
614
|
editor.commands.insertContent({
|
|
575
615
|
type: "image",
|
|
576
616
|
attrs: {
|
|
577
|
-
src:
|
|
617
|
+
src: "",
|
|
578
618
|
dataPath
|
|
579
619
|
}
|
|
580
620
|
});
|
|
581
621
|
}
|
|
582
|
-
function
|
|
583
|
-
if (!onRemoveImage)
|
|
584
|
-
return;
|
|
622
|
+
function handleImagesChanges(transaction) {
|
|
585
623
|
const getImageSrcs = (fragment) => {
|
|
586
624
|
let srcs = /* @__PURE__ */ new Set();
|
|
587
625
|
fragment.forEach((node) => {
|
|
@@ -597,7 +635,8 @@ function handleImagesDeletions(transaction) {
|
|
|
597
635
|
return;
|
|
598
636
|
}
|
|
599
637
|
let deletedImageSrcs = [...previousSrcs].filter((src) => !currentSrcs.has(src));
|
|
600
|
-
|
|
638
|
+
if (onRemoveImage)
|
|
639
|
+
deletedImageSrcs.forEach((src) => onRemoveImage(src));
|
|
601
640
|
}
|
|
602
641
|
let commands = [
|
|
603
642
|
{ caption: "Normal", description: "This is normal text style", tags: "text", icon: FaRemoveFormat, on_choice: (range) => {
|
|
@@ -26,19 +26,21 @@ export function showAsToolbox(rect) {
|
|
|
26
26
|
const windowWidth = window.innerWidth - 2 * margin;
|
|
27
27
|
toolboxX = margin;
|
|
28
28
|
toolboxY = rect.bottom + margin;
|
|
29
|
-
const mainContentDiv = document.getElementById("__hd_svelte_main_content_container");
|
|
30
29
|
toolboxY += window.scrollY;
|
|
31
30
|
css_style = `position: absolute; left:${toolboxX}px; top:${toolboxY}px;`;
|
|
32
31
|
dispatch("palette_shown");
|
|
33
32
|
}
|
|
34
|
-
let
|
|
33
|
+
let paletteElement;
|
|
35
34
|
afterUpdate(
|
|
36
35
|
async () => {
|
|
37
|
-
if (
|
|
36
|
+
if (
|
|
37
|
+
/*isToolbox && */
|
|
38
|
+
visible && paletteElement
|
|
39
|
+
) {
|
|
38
40
|
let layoutRoot = document.getElementById("__hd_svelte_layout_root");
|
|
39
|
-
if (!!layoutRoot &&
|
|
41
|
+
if (!!layoutRoot && paletteElement.parentElement != layoutRoot) {
|
|
40
42
|
await tick();
|
|
41
|
-
layoutRoot.appendChild(
|
|
43
|
+
layoutRoot.appendChild(paletteElement);
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -181,7 +183,7 @@ function mouseup(e) {
|
|
|
181
183
|
on:touchstart={mousedown}
|
|
182
184
|
on:touchmove={mousemove}
|
|
183
185
|
on:touchend={mouseup}
|
|
184
|
-
bind:this={
|
|
186
|
+
bind:this={paletteElement}>
|
|
185
187
|
{#if filtered_commands && filtered_commands.length}
|
|
186
188
|
{#each filtered_commands as cmd, idx (cmd.caption)}
|
|
187
189
|
{@const id = "cpi_" + idx}
|
|
@@ -208,7 +210,8 @@ function mouseup(e) {
|
|
|
208
210
|
{:else}
|
|
209
211
|
<div class="not-prose bg-white dark:bg-stone-800 text-stone-500 dark:text-stone-400 rounded-lg border border-stone-200 dark:border-stone-700 shadow-md z-30"
|
|
210
212
|
hidden={!visible}
|
|
211
|
-
style={css_style}
|
|
213
|
+
style={css_style}
|
|
214
|
+
bind:this={paletteElement}>
|
|
212
215
|
{#if filtered_commands && filtered_commands.length}
|
|
213
216
|
{#each filtered_commands as cmd, idx (cmd.caption)}
|
|
214
217
|
{@const id = "cpi_" + idx}
|