@humandialog/forms.svelte 1.2.5 → 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";
@@ -356,7 +356,8 @@ function prepareFullImagePath(url) {
356
356
  } else {
357
357
  fullPath += "?";
358
358
  }
359
- }
359
+ } else
360
+ fullPath += "&";
360
361
  fullPath += param.key.toLowerCase();
361
362
  fullPath += "=" + param.value;
362
363
  }
@@ -381,11 +382,15 @@ function prepareFullImagePath(url) {
381
382
  }
382
383
  return fullPath;
383
384
  }
385
+ let downloadedImages = [];
384
386
  const CrossImage = Image.extend({
385
387
  addAttributes() {
386
388
  return {
387
- crossorigin: {
388
- default: "use-credentials"
389
+ //crossorigin: {
390
+ // default: 'use-credentials'
391
+ //},
392
+ loading: {
393
+ default: "lazy"
389
394
  },
390
395
  dataPath: {
391
396
  default: null,
@@ -395,9 +400,42 @@ const CrossImage = Image.extend({
395
400
  renderHTML: (attributes) => {
396
401
  const dataPath = attributes.dataPath;
397
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
+ }
398
434
  return {
399
435
  "data-path": dataPath,
400
- src: prepareFullImagePath(dataPath)
436
+ // src: prepareFullImagePath(dataPath)
437
+ // src: 'http://localhost/_hd_force_img_error'
438
+ src
401
439
  };
402
440
  } else {
403
441
  return {};
@@ -452,7 +490,7 @@ onMount(() => {
452
490
  onTransaction({ editor: editor2, transaction }) {
453
491
  hasChangedValue = true;
454
492
  changedValue = editor2.getHTML();
455
- handleImagesDeletions(transaction);
493
+ handleImagesChanges(transaction);
456
494
  },
457
495
  onFocus({ editor: editor2, event }) {
458
496
  if (onFocusCb)
@@ -465,6 +503,8 @@ onMount(() => {
465
503
  },
466
504
  onContentError({ editor: editor2, error, disableCollaboration }) {
467
505
  console.log("editor content error:", error);
506
+ },
507
+ onUpdate({ editor: editor2 }) {
468
508
  }
469
509
  });
470
510
  });
@@ -570,19 +610,16 @@ function show_command_palette(cursorRect) {
570
610
  else
571
611
  palette.show(x, y, show_above);
572
612
  }
573
- function onAddedImageReady(dataPath) {
574
- const imgFullPath = prepareFullImagePath(dataPath);
613
+ async function onAddedImageReady(dataPath) {
575
614
  editor.commands.insertContent({
576
615
  type: "image",
577
616
  attrs: {
578
- src: imgFullPath,
617
+ src: "",
579
618
  dataPath
580
619
  }
581
620
  });
582
621
  }
583
- function handleImagesDeletions(transaction) {
584
- if (!onRemoveImage)
585
- return;
622
+ function handleImagesChanges(transaction) {
586
623
  const getImageSrcs = (fragment) => {
587
624
  let srcs = /* @__PURE__ */ new Set();
588
625
  fragment.forEach((node) => {
@@ -598,7 +635,8 @@ function handleImagesDeletions(transaction) {
598
635
  return;
599
636
  }
600
637
  let deletedImageSrcs = [...previousSrcs].filter((src) => !currentSrcs.has(src));
601
- deletedImageSrcs.forEach((src) => onRemoveImage(src));
638
+ if (onRemoveImage)
639
+ deletedImageSrcs.forEach((src) => onRemoveImage(src));
602
640
  }
603
641
  let commands = [
604
642
  { caption: "Normal", description: "This is normal text style", tags: "text", icon: FaRemoveFormat, on_choice: (range) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humandialog/forms.svelte",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "Basic Svelte UI components for Object Reef applications",
5
5
  "devDependencies": {
6
6
  "@playwright/test": "^1.28.1",