@humandialog/forms.svelte 0.4.5 → 0.4.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.
@@ -0,0 +1,41 @@
1
+ <script>import { tick } from "svelte";
2
+ let x;
3
+ let y;
4
+ let visible = false;
5
+ let toolbar;
6
+ let root_element;
7
+ let invisible_button;
8
+ $:
9
+ display = visible ? "fixed" : "hidden";
10
+ export async function show(_x, _y, _toolbar) {
11
+ x = _x;
12
+ y = _y;
13
+ visible = true;
14
+ toolbar = _toolbar;
15
+ await tick();
16
+ focus_first_element();
17
+ }
18
+ export function hide() {
19
+ visible = false;
20
+ }
21
+ function focus_first_element() {
22
+ invisible_button.focus();
23
+ return;
24
+ let focusable = root_element.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
25
+ console.log(focusable);
26
+ focusable.focus();
27
+ }
28
+ function on_focus_out() {
29
+ hide();
30
+ }
31
+ </script>
32
+
33
+ <div id="__hd_svelte_floating_container"
34
+ class="p-2 bg-slate-100 dark:bg-slate-800 rounded-lg shadow {display}"
35
+ style="left:{x}px; top:{y}px"
36
+ on:focusout={on_focus_out}
37
+ bind:this={root_element}>
38
+ <button class="w-0 h-0 fixed bg-transparent " bind:this={invisible_button}></button>
39
+ <svelte:component this={toolbar}/>
40
+ </div>
41
+
@@ -0,0 +1,19 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ show?: ((_x: number, _y: number, _toolbar: any) => Promise<void>) | undefined;
5
+ hide?: (() => void) | undefined;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export type FloatingContainerProps = typeof __propDef.props;
13
+ export type FloatingContainerEvents = typeof __propDef.events;
14
+ export type FloatingContainerSlots = typeof __propDef.slots;
15
+ export default class FloatingContainer extends SvelteComponentTyped<FloatingContainerProps, FloatingContainerEvents, FloatingContainerSlots> {
16
+ get show(): (_x: number, _y: number, _toolbar: any) => Promise<void>;
17
+ get hide(): () => void;
18
+ }
19
+ export {};
@@ -1 +1,2 @@
1
1
  export declare function show_menu(x: number, y: number, operations: any): void;
2
+ export declare function show_floating_toolbar(x: number, y: number, toolbar: any): void;
@@ -1,5 +1,7 @@
1
1
  import Menu from './contextmenu.svelte';
2
+ import Floating_container from './Floating_container.svelte';
2
3
  let menu_comopnent = null;
4
+ let toolbar_component = null;
3
5
  export function show_menu(x, y, operations) {
4
6
  let menu_element = document.getElementById("__hd_svelte_contextmenu");
5
7
  if (!!!menu_element) {
@@ -14,3 +16,17 @@ export function show_menu(x, y, operations) {
14
16
  else
15
17
  console.error('what now?');
16
18
  }
19
+ export function show_floating_toolbar(x, y, toolbar) {
20
+ let floating_container = document.getElementById("__hd_svelte_floating_container");
21
+ if (!!!floating_container) {
22
+ toolbar_component = new Floating_container({
23
+ target: document.body,
24
+ props: {}
25
+ });
26
+ toolbar_component.show(x, y, toolbar);
27
+ }
28
+ else if (toolbar_component)
29
+ toolbar_component.show(x, y, toolbar);
30
+ else
31
+ console.error('what now?');
32
+ }
@@ -9,7 +9,8 @@
9
9
  import FaBars from 'svelte-icons/fa/FaBars.svelte'
10
10
  import FaToggleOn from 'svelte-icons/fa/FaToggleOn.svelte'
11
11
  import FaToggleOff from 'svelte-icons/fa/FaToggleOff.svelte'
12
- import Menu from './components/contextmenu.svelte'
12
+ import {show_menu} from './components/menu'
13
+ //import Menu from './components/contextmenu.svelte'
13
14
 
14
15
  import {
15
16
  dark_mode_store,
@@ -80,12 +81,9 @@
80
81
  }
81
82
  }
82
83
 
83
- let menu;
84
- let options_owner;
85
-
86
- function show_options()
84
+ function show_options(e)
87
85
  {
88
- let rect = options_owner.getBoundingClientRect();
86
+ let rect = e.target.getBoundingClientRect();
89
87
  let x = rect.left;
90
88
  let y = rect.bottom;
91
89
  let options = [];
@@ -151,7 +149,7 @@
151
149
  });
152
150
  }
153
151
 
154
- menu.show(x, y, options);
152
+ show_menu(x, y, options);
155
153
  }
156
154
 
157
155
  </script>
@@ -166,8 +164,7 @@
166
164
 
167
165
  <button
168
166
  class="h-full w-16 px-0 flex justify-center items-center text-slate-300 hover:text-slate-100"
169
- on:click={()=> {show_options()}}
170
- bind:this={options_owner}>
167
+ on:click={show_options}>
171
168
 
172
169
  <Icon size={6} component={FaEllipsisH} />
173
170
  </button>
@@ -184,4 +181,4 @@
184
181
  </div>
185
182
  {/if}
186
183
 
187
- <Menu bind:this={menu}/>
184
+ <!--Menu bind:this={menu}/-->
package/index.d.ts CHANGED
@@ -22,7 +22,6 @@ export { default as ComboSource } from './components/combo/combo.source.svelte';
22
22
  export { default as ComboItem } from './components/combo/combo.item.svelte';
23
23
  export { default as RichEdit } from './components/document/rich.edit.svelte';
24
24
  export { default as Spinner } from './components/delayed.spinner.svelte';
25
- export { default as Menu } from './components/contextmenu.svelte';
26
25
  export { show_menu } from './components/menu';
27
26
  export { default as Fab } from './components/Fab.svelte';
28
27
  export { data_tick_store, has_selected_item, has_data_item } from "./stores";
package/index.js CHANGED
@@ -26,7 +26,7 @@ export { default as ComboSource } from './components/combo/combo.source.svelte';
26
26
  export { default as ComboItem } from './components/combo/combo.item.svelte';
27
27
  export { default as RichEdit } from './components/document/rich.edit.svelte';
28
28
  export { default as Spinner } from './components/delayed.spinner.svelte';
29
- export { default as Menu } from './components/contextmenu.svelte';
29
+ //export { default as Menu } from './components/contextmenu.svelte'
30
30
  export { show_menu } from './components/menu';
31
31
  export { default as Fab } from './components/Fab.svelte';
32
32
  export { data_tick_store, has_selected_item, has_data_item } from "./stores";
package/operations.svelte CHANGED
@@ -1,4 +1,5 @@
1
- <script>import { context_toolbar_operations, page_toolbar_operations, context_items_store } from "./stores.js";
1
+ <script>import { show_floating_toolbar, show_menu } from "./components/menu.js";
2
+ import { context_toolbar_operations, page_toolbar_operations, context_items_store } from "./stores.js";
2
3
  $:
3
4
  update($page_toolbar_operations, $context_toolbar_operations);
4
5
  let operations = [];
@@ -8,15 +9,31 @@ function update(...args) {
8
9
  else
9
10
  operations = $page_toolbar_operations;
10
11
  }
11
- function on_click(operation) {
12
+ function on_click(e, operation) {
12
13
  if (!operation)
13
14
  return;
14
- if (!operation.action)
15
- return;
16
- let focused_item = null;
17
- if ($context_items_store.focused)
18
- focused_item = $context_items_store[$context_items_store.focused];
19
- operation.action(focused_item);
15
+ if (operation.menu) {
16
+ let owner = e.target;
17
+ while (owner && owner.tagName != "BUTTON")
18
+ owner = owner.parentElement;
19
+ if (!owner)
20
+ return;
21
+ let rect = owner.getBoundingClientRect();
22
+ show_menu(rect.left, rect.bottom, operation.menu);
23
+ } else if (operation.toolbar) {
24
+ let owner = e.target;
25
+ while (owner && owner.tagName != "BUTTON")
26
+ owner = owner.parentElement;
27
+ if (!owner)
28
+ return;
29
+ let rect = owner.getBoundingClientRect();
30
+ show_floating_toolbar(rect.left, rect.bottom, operation.toolbar);
31
+ } else if (operation.action) {
32
+ let focused_item = null;
33
+ if ($context_items_store.focused)
34
+ focused_item = $context_items_store[$context_items_store.focused];
35
+ operation.action(focused_item);
36
+ }
20
37
  }
21
38
  </script>
22
39
 
@@ -24,7 +41,7 @@ function on_click(operation) {
24
41
 
25
42
  {#each operations as operation}
26
43
  <button type="button" class="py-2.5 px-5 text-xs font-medium text-gray-900 bg-slate-100 hover:bg-slate-200 border-r border-gray-200 focus:outline-none dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 inline-flex items-center"
27
- on:click={(e) => {on_click(operation)}}>
44
+ on:click={(e) => {on_click(e, operation)}}>
28
45
  <div class="w-3 h-3"><svelte:component this={operation.icon}/></div>
29
46
  <span class="ml-1">{operation.caption}</span>
30
47
  </button>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humandialog/forms.svelte",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "Basic Svelte UI components for Object Reef applications",
5
5
  "devDependencies": {
6
6
  "@playwright/test": "^1.28.1",
@@ -69,6 +69,7 @@
69
69
  "./components/edit.field.svelte": "./components/edit.field.svelte",
70
70
  "./components/Fab.svelte": "./components/Fab.svelte",
71
71
  "./components/file.loader.svelte": "./components/file.loader.svelte",
72
+ "./components/Floating_container.svelte": "./components/Floating_container.svelte",
72
73
  "./components/icon.svelte": "./components/icon.svelte",
73
74
  "./components/input.text.svelte": "./components/input.text.svelte",
74
75
  "./components/inputbox.ltop.svelte": "./components/inputbox.ltop.svelte",
package/page.svelte CHANGED
@@ -18,7 +18,7 @@
18
18
  "w-full h-full flex flex-col dark:bg-slate-800 overflow-y-hidden overflow-x-hidden py-1 px-1 border-0" // border-green-500
19
19
  export let c = ''
20
20
 
21
- export let toolbar_operations = [];
21
+ export let toolbar_operations = undefined;
22
22
  export let clears_context = '';
23
23
 
24
24
 
@@ -34,8 +34,13 @@
34
34
  }
35
35
 
36
36
  onMount(() => {
37
- $page_toolbar_operations = [...toolbar_operations]
38
- return () => { $page_toolbar_operations = [] }
37
+ if(toolbar_operations != undefined && Array.isArray(toolbar_operations))
38
+ {
39
+ $page_toolbar_operations = [...toolbar_operations]
40
+ return () => { $page_toolbar_operations = [] }
41
+ }
42
+ else
43
+ return () => {}
39
44
  })
40
45
 
41
46
  setContext('ctx', context)
@@ -87,6 +92,7 @@
87
92
 
88
93
  function clear_selection(e)
89
94
  {
95
+ console.log(e, clears_context)
90
96
  if(!clears_context)
91
97
  return;
92
98
 
package/page.svelte.d.ts CHANGED
@@ -9,7 +9,7 @@ export default class Page extends SvelteComponentTyped<{
9
9
  typename?: string | undefined;
10
10
  focused_only?: boolean | undefined;
11
11
  in_context?: string | undefined;
12
- toolbar_operations?: any[] | undefined;
12
+ toolbar_operations?: any;
13
13
  clears_context?: string | undefined;
14
14
  }, {
15
15
  [evt: string]: CustomEvent<any>;
@@ -30,7 +30,7 @@ declare const __propDef: {
30
30
  typename?: string | undefined;
31
31
  focused_only?: boolean | undefined;
32
32
  in_context?: string | undefined;
33
- toolbar_operations?: any[] | undefined;
33
+ toolbar_operations?: any;
34
34
  clears_context?: string | undefined;
35
35
  };
36
36
  events: {
@@ -6,7 +6,7 @@
6
6
  import GoPrimitiveDot from 'svelte-icons/go/GoPrimitiveDot.svelte'
7
7
  import FaSignInAlt from 'svelte-icons/fa/FaSignInAlt.svelte'
8
8
  import FaSignOutAlt from 'svelte-icons/fa/FaSignOutAlt.svelte'
9
- import {show_menu} from './components/menu.js'
9
+ import {show_menu} from './components/menu'
10
10
  //import Menu from './components/contextmenu.svelte'
11
11
 
12
12
  import {dark_mode_store,
@@ -74,12 +74,9 @@
74
74
  show_sidebar(key);
75
75
  }
76
76
 
77
- //let menu;
78
- let options_owner;
79
-
80
- function show_options()
77
+ function show_options(e)
81
78
  {
82
- let rect = options_owner.getBoundingClientRect();
79
+ let rect = e.target.getBoundingClientRect();
83
80
  let x = rect.right;
84
81
  let y = rect.top;
85
82
  let options = [];
@@ -170,8 +167,7 @@
170
167
 
171
168
  <button
172
169
  class="h-16 px-0 flex justify-center items-center w-full text-slate-300 hover:text-slate-100"
173
- on:click={()=> {show_options()}}
174
- bind:this={options_owner}>
170
+ on:click={show_options}>
175
171
 
176
172
  <Icon size={6} component={FaEllipsisH} />
177
173
  </button>