@humandialog/forms.svelte 0.5.13 → 0.5.14

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.
@@ -244,7 +244,6 @@ function selected_item(itm, a2) {
244
244
  let found = definition.source.find((e) => e.Key == choosed_value);
245
245
  if (!found)
246
246
  found = definition.source.find((e) => e.Name == choosed_value);
247
- console.log("found: ", found);
248
247
  if (found)
249
248
  return found;
250
249
  else
@@ -18,11 +18,11 @@ let toolboxY;
18
18
  export function showAsToolbox(rect) {
19
19
  isToolbox = true;
20
20
  visible = true;
21
- const margin = 15;
21
+ const margin = 0;
22
22
  const windowWidth = window.innerWidth - 2 * margin;
23
23
  toolboxX = margin;
24
24
  toolboxY = rect.bottom + margin;
25
- css_style = `position: absolute; left:${toolboxX}px; top:${toolboxY}px;`;
25
+ css_style = `position: fixed; left:${toolboxX}px; top:${toolboxY}px;`;
26
26
  dispatch("palette_shown");
27
27
  }
28
28
  export function show(x, y, up = false) {
@@ -1,5 +1,5 @@
1
1
  <script>import { Selection_helper } from "./internal/Selection_helper";
2
- import { afterUpdate, getContext, onDestroy, onMount } from "svelte";
2
+ import { beforeUpdate, afterUpdate, getContext, onDestroy, onMount } from "svelte";
3
3
  import { Selection_range, Selection_edge } from "./internal/Selection_range";
4
4
  import { data_tick_store, contextItemsStore, contextTypesStore } from "../../stores.js";
5
5
  import { informModification, pushChanges } from "../../updates.js";
@@ -85,8 +85,6 @@ function setup_source() {
85
85
  if (!value)
86
86
  value = "<p>\u200B</p>";
87
87
  has_changed_value = false;
88
- if (stored_selection)
89
- set_selection(stored_selection);
90
88
  }
91
89
  onMount(() => {
92
90
  if (!editable_div)
@@ -114,6 +112,19 @@ onDestroy(() => {
114
112
  if (is_command_palette_visible)
115
113
  hide_command_palette();
116
114
  });
115
+ let storedSelection = null;
116
+ beforeUpdate(() => {
117
+ if (editable_div && document.activeElement == editable_div)
118
+ storedSelection = Selection_helper.get_selection(editable_div);
119
+ else
120
+ storedSelection = null;
121
+ });
122
+ afterUpdate(() => {
123
+ if (storedSelection) {
124
+ const range = Selection_helper.create_range(editable_div, storedSelection.begin.absolute_index, storedSelection.end.absolute_index);
125
+ set_selection(range);
126
+ }
127
+ });
117
128
  function content_changed(checkZeroWitdhSpaces) {
118
129
  if (document.activeElement != editable_div)
119
130
  return;
@@ -755,7 +766,7 @@ function set_tag_and_class_for_paragraph(node, tag, css_class) {
755
766
  function do_format(tag, css_class) {
756
767
  const elem = editable_div;
757
768
  const editableElem = editable_div;
758
- let stored_selection2 = Selection_helper.get_selection(elem);
769
+ let stored_selection = Selection_helper.get_selection(elem);
759
770
  let sel = window.getSelection();
760
771
  let should_restore_selection = false;
761
772
  if (sel.isCollapsed || sel.focusNode === sel.anchorNode) {
@@ -784,7 +795,7 @@ function do_format(tag, css_class) {
784
795
  } while (node);
785
796
  }
786
797
  if (should_restore_selection) {
787
- const range = Selection_helper.create_range(editableElem, stored_selection2.begin.absolute_index, stored_selection2.end.absolute_index);
798
+ const range = Selection_helper.create_range(editableElem, stored_selection.begin.absolute_index, stored_selection.end.absolute_index);
788
799
  set_selection(range);
789
800
  }
790
801
  }
@@ -941,10 +952,7 @@ function navigate_command_palette(key) {
941
952
  else if (key == "ArrowUp")
942
953
  palette.navigate_up();
943
954
  }
944
- let stored_selection = void 0;
945
955
  function on_selection_changed() {
946
- let active_range = Selection_helper.get_selection(editable_div);
947
- stored_selection = window.getSelection()?.getRangeAt(0);
948
956
  }
949
957
  let intervalId = 0;
950
958
  function on_focus() {
@@ -952,7 +960,7 @@ function on_focus() {
952
960
  function on_blur() {
953
961
  let active_range = Selection_helper.get_selection(editable_div);
954
962
  console.log("rich.edit: on_blur", active_range?.begin?.absolute_index);
955
- stored_selection = void 0;
963
+ storedSelection = null;
956
964
  if (onBlur) {
957
965
  onBlur();
958
966
  onBlur = void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humandialog/forms.svelte",
3
- "version": "0.5.13",
3
+ "version": "0.5.14",
4
4
  "description": "Basic Svelte UI components for Object Reef applications",
5
5
  "devDependencies": {
6
6
  "@playwright/test": "^1.28.1",