@humandialog/forms.svelte 0.4.13 → 0.4.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.
@@ -1,45 +1,78 @@
1
- <script>import { tick } from "svelte";
1
+ <script>import { tick, afterUpdate } from "svelte";
2
+ import { is_device_smaller_than } from "../utils";
2
3
  let x;
3
4
  let y;
4
5
  let visible = false;
5
6
  let toolbar;
6
7
  let props = {};
8
+ let around_rect;
7
9
  let root_element;
8
10
  let invisible_button;
9
11
  $:
10
12
  display = visible ? "fixed" : "hidden";
11
- export async function show(_x, _y, _toolbar, _props = {}) {
12
- x = _x;
13
- y = _y;
13
+ export async function show(around, _toolbar, _props = {}) {
14
+ if (around instanceof DOMRect) {
15
+ x = around.left;
16
+ y = around.bottom;
17
+ around_rect = around;
18
+ } else if (around instanceof DOMPoint) {
19
+ x = around.x;
20
+ y = around.y;
21
+ around_rect = new DOMRect(x, y, 0, 0);
22
+ }
14
23
  visible = true;
15
24
  toolbar = _toolbar;
16
25
  props = _props;
26
+ props.onhide = () => {
27
+ hide();
28
+ };
17
29
  await tick();
18
30
  focus_first_element();
19
31
  }
32
+ export function is_visible() {
33
+ return visible;
34
+ }
20
35
  export function hide() {
21
36
  visible = false;
22
37
  }
38
+ afterUpdate(() => {
39
+ if (!root_element)
40
+ return;
41
+ let rect = root_element.getBoundingClientRect();
42
+ if (rect.height == 0)
43
+ return;
44
+ let container_rect = new DOMRect(0, 0, window.innerWidth, window.innerHeight);
45
+ if (rect.right > container_rect.right)
46
+ x = container_rect.right - rect.width;
47
+ if (rect.bottom > container_rect.bottom)
48
+ y = container_rect.bottom - rect.height - around_rect.height;
49
+ if (rect.left < container_rect.left)
50
+ x = container_rect.left;
51
+ if (rect.top < container_rect.top)
52
+ y = container_rect.top;
53
+ });
23
54
  function focus_first_element() {
24
55
  invisible_button.focus();
25
56
  return;
26
57
  let focusable = root_element.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
27
- console.log(focusable);
28
58
  focusable.focus();
29
59
  }
30
60
  function on_focus_out(e) {
31
- if (e.relatedTarget && root_element?.contains(e.relatedTarget)) {
32
- } else
33
- hide();
61
+ if (!is_device_smaller_than("sm")) {
62
+ if (e.relatedTarget && root_element?.contains(e.relatedTarget)) {
63
+ } else
64
+ hide();
65
+ } else {
66
+ }
34
67
  }
35
68
  </script>
36
69
 
37
70
  <div id="__hd_svelte_floating_container"
38
71
  class="p-2 bg-slate-100 dark:bg-slate-800 rounded-lg shadow {display}"
39
- style="left:{x}px; top:{y}px"
72
+ style="left:{x}px; top:{y}px; width: max-content; height:max-content"
40
73
  on:focusout={on_focus_out}
41
74
  bind:this={root_element}>
42
75
  <button class="w-0 h-0 fixed bg-transparent " bind:this={invisible_button}></button>
43
- <svelte:component this={toolbar} {...props} hide={() => hide()}/>
76
+ <svelte:component this={toolbar} {...props} />
44
77
  </div>
45
78
 
@@ -1,7 +1,8 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- show?: ((_x: number, _y: number, _toolbar: any, _props?: {}) => Promise<void>) | undefined;
4
+ show?: ((around: DOMRect | DOMPoint, _toolbar: any, _props?: {}) => Promise<void>) | undefined;
5
+ is_visible?: (() => boolean) | undefined;
5
6
  hide?: (() => void) | undefined;
6
7
  };
7
8
  events: {
@@ -13,7 +14,8 @@ export type FloatingContainerProps = typeof __propDef.props;
13
14
  export type FloatingContainerEvents = typeof __propDef.events;
14
15
  export type FloatingContainerSlots = typeof __propDef.slots;
15
16
  export default class FloatingContainer extends SvelteComponentTyped<FloatingContainerProps, FloatingContainerEvents, FloatingContainerSlots> {
16
- get show(): (_x: number, _y: number, _toolbar: any, _props?: {}) => Promise<void>;
17
+ get show(): (around: DOMRect | DOMPoint, _toolbar: any, _props?: {}) => Promise<void>;
18
+ get is_visible(): () => boolean;
17
19
  get hide(): () => void;
18
20
  }
19
21
  export {};
@@ -2,7 +2,7 @@
2
2
  import {context_items_store} from '../stores.js'
3
3
 
4
4
  export let operations = []
5
- export let hide = undefined;
5
+ export let onhide = undefined;
6
6
 
7
7
  $: grid_cols = init(operations);
8
8
 
@@ -94,8 +94,8 @@
94
94
 
95
95
  function execute_action(e, operation)
96
96
  {
97
- if(hide != undefined)
98
- hide();
97
+ if(!!onhide)
98
+ onhide();
99
99
 
100
100
  if(!operation)
101
101
  return;
@@ -2,7 +2,7 @@
2
2
  /** @typedef {typeof __propDef.events} GridEvents */
3
3
  /** @typedef {typeof __propDef.slots} GridSlots */
4
4
  export default class Grid extends SvelteComponentTyped<{
5
- hide?: any;
5
+ onhide?: any;
6
6
  operations?: any[] | undefined;
7
7
  }, {
8
8
  [evt: string]: CustomEvent<any>;
@@ -14,7 +14,7 @@ export type GridSlots = typeof __propDef.slots;
14
14
  import { SvelteComponentTyped } from "svelte";
15
15
  declare const __propDef: {
16
16
  props: {
17
- hide?: any;
17
+ onhide?: any;
18
18
  operations?: any[] | undefined;
19
19
  };
20
20
  events: {
@@ -56,9 +56,7 @@ switch (s) {
56
56
  let background_class = is_compact && !icon ? "bg-slate-900/10 dark:bg-slate-100/10 rounded-lg" : "";
57
57
  let appearance_class;
58
58
  if (is_compact)
59
- appearance_class = ` text-gray-900 ${font_size}
60
- focus:ring-primary-600 block w-full ${input_pb} ${input_pt} px-2.5 dark:bg-gray-700
61
- dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 ${background_class}`;
59
+ appearance_class = `${font_size}`;
62
60
  else
63
61
  appearance_class = ` bg-gray-50 border border-gray-300 text-gray-900 ${font_size} rounded-lg
64
62
  focus:ring-primary-600 focus:border-primary-600 block w-full ${input_pb} ${input_pt} px-2.5 dark:bg-gray-700
@@ -454,7 +452,7 @@ function on_focus_out(e) {
454
452
  {#if true}
455
453
  {@const c = setup_view(item, a, tick_request_internal) }
456
454
 
457
- <div class={cs}
455
+ <div class="{cs} max-w-full inline-block"
458
456
  on:focusout={on_focus_out}
459
457
  bind:this={root_element}>
460
458
  {#if !is_compact}
@@ -462,12 +460,12 @@ function on_focus_out(e) {
462
460
  {/if}
463
461
  <!-- svelte-ignore a11y-click-events-have-key-events -->
464
462
  <div bind:this={combo}
465
- on:click={show}
466
- class="{appearance_class} flex flex-row content-between items-center"
463
+ on:click={(e) => { show(e, undefined) }}
467
464
  class:cursor-pointer={can_be_activated && is_compact}
465
+ class="max-w-full {appearance_class} flex flex-row content-between items-center"
468
466
  >
469
467
 
470
- <div class="flex-1 flex flex-row items-center">
468
+ <div class="max-w-full flex-1 flex flex-row items-center">
471
469
  {#if !is_dropdown_open}
472
470
  {#if icon && sel_item}
473
471
  {#if sel_item.Color}
@@ -480,7 +478,7 @@ function on_focus_out(e) {
480
478
 
481
479
 
482
480
  <p bind:this={textbox}
483
- class="dark:text-white {line_h}"
481
+ class="dark:text-white {line_h} truncate px-2.5 {background_class}"
484
482
  class:ml-2={icon}
485
483
  class:text-gray-400={ (!is_dropdown_open) && (!sel_item)}
486
484
  class:text-gray-700={ is_dropdown_open || sel_item }
@@ -1,6 +1,7 @@
1
1
  <script>import { afterUpdate, tick } from "svelte";
2
2
  import Icon from "./icon.svelte";
3
3
  import { context_items_store } from "../stores";
4
+ import { is_device_smaller_than } from "../utils";
4
5
  export let width_px = 400;
5
6
  export let menu_items_id_prefix = "__hd_svelte_menuitem_";
6
7
  export let owner_menu_item = void 0;
@@ -13,6 +14,7 @@ let min_width_px = 200;
13
14
  let focused_index = 0;
14
15
  let menu_items = [];
15
16
  let submenus = [];
17
+ let around_rect;
16
18
  $:
17
19
  display = visible ? "block" : "none";
18
20
  afterUpdate(() => {
@@ -23,15 +25,22 @@ afterUpdate(() => {
23
25
  if (rect.right > container_rect.right)
24
26
  x = container_rect.right - rect.width;
25
27
  if (rect.bottom > container_rect.bottom)
26
- y = container_rect.bottom - rect.height;
28
+ y = container_rect.bottom - rect.height - around_rect.height;
27
29
  if (rect.left < container_rect.left)
28
30
  x = container_rect.left;
29
31
  if (rect.top < container_rect.top)
30
32
  y = container_rect.top;
31
33
  });
32
- export async function show(_x, _y, _operations) {
33
- x = _x;
34
- y = _y;
34
+ export async function show(around, _operations) {
35
+ if (around instanceof DOMRect) {
36
+ x = around.left;
37
+ y = around.bottom;
38
+ around_rect = around;
39
+ } else if (around instanceof DOMPoint) {
40
+ x = around.x;
41
+ y = around.y;
42
+ around_rect = new DOMRect(x, y, 0, 0);
43
+ }
35
44
  visible = true;
36
45
  operations = [..._operations];
37
46
  focused_index = 0;
@@ -39,6 +48,9 @@ export async function show(_x, _y, _operations) {
39
48
  if (menu_items.length)
40
49
  focus_menu_item(focused_index);
41
50
  }
51
+ export function is_visible() {
52
+ return visible;
53
+ }
42
54
  export function hide() {
43
55
  visible = false;
44
56
  }
@@ -91,10 +103,12 @@ function navigate_down() {
91
103
  }
92
104
  }
93
105
  function on_change_focus(e) {
94
- if (e.relatedTarget && e.relatedTarget.id.startsWith(menu_items_id_prefix))
95
- return;
96
- else
97
- hide();
106
+ if (!is_device_smaller_than("sm")) {
107
+ if (e.relatedTarget && e.relatedTarget.id.startsWith(menu_items_id_prefix))
108
+ return;
109
+ else
110
+ hide();
111
+ }
98
112
  }
99
113
  function on_mouse_move(index) {
100
114
  focus_menu_item(index);
@@ -142,7 +156,7 @@ function hide_submenu() {
142
156
  </script>
143
157
 
144
158
  <div id="__hd_svelte_contextmenu"
145
- class="bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400 rounded-lg border border-gray-200 dark:border-gray-700 shadow-md z-20 fixed min-w-[{min_width_px}px]"
159
+ class="bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400 rounded-lg border border-gray-200 dark:border-gray-700 shadow-md z-20 fixed min-w-[{min_width_px}px] w-max"
146
160
  style={`left:${x}px; top:${y}px; display:${display}`}
147
161
  bind:this={menu_root}
148
162
  on:focusout={on_change_focus}>
@@ -4,7 +4,8 @@ declare const __propDef: {
4
4
  width_px?: number | undefined;
5
5
  menu_items_id_prefix?: string | undefined;
6
6
  owner_menu_item?: HTMLElement | undefined;
7
- show?: ((_x: number, _y: number, _operations: any) => Promise<void>) | undefined;
7
+ show?: ((around: DOMRect | DOMPoint, _operations: any) => Promise<void>) | undefined;
8
+ is_visible?: (() => boolean) | undefined;
8
9
  hide?: (() => void) | undefined;
9
10
  get_rendered_rect?: (() => DOMRect | undefined) | undefined;
10
11
  };
@@ -17,7 +18,8 @@ export type ContextmenuProps = typeof __propDef.props;
17
18
  export type ContextmenuEvents = typeof __propDef.events;
18
19
  export type ContextmenuSlots = typeof __propDef.slots;
19
20
  export default class Contextmenu extends SvelteComponentTyped<ContextmenuProps, ContextmenuEvents, ContextmenuSlots> {
20
- get show(): (_x: number, _y: number, _operations: any) => Promise<void>;
21
+ get show(): (around: DOMRect | DOMPoint, _operations: any) => Promise<void>;
22
+ get is_visible(): () => boolean;
21
23
  get hide(): () => void;
22
24
  get get_rendered_rect(): () => DOMRect | undefined;
23
25
  }
@@ -1,45 +1,80 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import { data_tick_store, context_items_store, context_types_store } from "../stores.js";
3
3
  import { inform_modification, push_changes } from "../updates.js";
4
- import { parse_width_directive } from "../utils.js";
4
+ import { parse_width_directive, is_device_smaller_than } from "../utils.js";
5
5
  export let self = null;
6
6
  export let a = "";
7
7
  export let context = "";
8
8
  export let typename = "";
9
9
  export let date = null;
10
+ export let on_select = void 0;
11
+ export let type = "date";
12
+ export let changed = void 0;
10
13
  export let s = "sm";
11
14
  export let c = "";
12
- let is_table_component = getContext("rIs-table-component");
15
+ export let compact = false;
16
+ export let in_context = "sel";
17
+ let on_hide_callback = void 0;
18
+ export function show(event, hide_callback) {
19
+ if (event) {
20
+ event.stopPropagation();
21
+ event.preventDefault();
22
+ }
23
+ if (!!hide_callback)
24
+ on_hide_callback = hide_callback;
25
+ else
26
+ on_hide_callback = void 0;
27
+ if (input_element) {
28
+ input_element.focus();
29
+ if (is_device_smaller_than("sm")) {
30
+ input_element.click();
31
+ }
32
+ if ("showPicker" in HTMLInputElement.prototype) {
33
+ input_element.showPicker();
34
+ }
35
+ }
36
+ }
37
+ let is_compact = getContext("rIs-table-component") || compact;
13
38
  let input_pt = "pt-0.5";
14
39
  let input_pb = "pb-1";
40
+ let font_size = "text-sm";
41
+ let line_h = "h-4";
15
42
  switch (s) {
16
43
  case "md":
17
44
  input_pt = "pt-2.5";
18
45
  input_pb = "pb-2.5";
46
+ font_size = "text-sm";
47
+ line_h = "h-5";
48
+ break;
49
+ case "xs":
50
+ input_pt = "pt-0.5";
51
+ input_pb = "pb-0.5";
52
+ font_size = "text-xs";
53
+ line_h = "h-4";
19
54
  break;
20
55
  }
21
56
  let item = null;
22
- let additional_class = $$restProps.class ?? "";
57
+ let user_class = $$restProps.class ?? "";
23
58
  let value = null;
24
59
  let rValue = "";
25
60
  let ctx = context ? context : getContext("ctx");
26
61
  let cs = parse_width_directive(c);
27
62
  let style;
28
- if (!is_table_component) {
63
+ let input_element = void 0;
64
+ let background_class = is_compact ? "bg-slate-900/10 dark:bg-slate-100/10 rounded-lg" : "";
65
+ if (!is_compact) {
29
66
  style = `bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg
30
67
  focus:ring-primary-600 focus:border-primary-600 block w-full ${input_pb} ${input_pt} px-2.5 dark:bg-gray-700
31
68
  dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500`;
32
69
  } else {
33
- style = `bg-transparent text-sm block w-full ${input_pb} ${input_pt} px-2.5`;
70
+ style = `${font_size}`;
34
71
  }
35
72
  let can_be_activated = true;
36
73
  let last_tick = -1;
37
74
  $:
38
- setup($data_tick_store);
39
- function setup(data_tick_store2) {
40
- if (data_tick_store2 <= last_tick)
41
- return;
42
- last_tick = data_tick_store2;
75
+ setup($data_tick_store, $context_items_store);
76
+ function setup(...args) {
77
+ last_tick = data_tick_store;
43
78
  if (!date) {
44
79
  item = self ?? $context_items_store[ctx];
45
80
  if (!typename)
@@ -50,8 +85,8 @@ function setup(data_tick_store2) {
50
85
  value = new Date(item[a]);
51
86
  } else
52
87
  value = date;
53
- if (is_table_component) {
54
- if ($context_items_store["sel"] != self)
88
+ if (is_compact) {
89
+ if ($context_items_store[in_context] != self)
55
90
  can_be_activated = false;
56
91
  else
57
92
  can_be_activated = true;
@@ -75,14 +110,20 @@ function get_formatted_date(d) {
75
110
  hour = "0" + hour;
76
111
  if (minutes.length < 2)
77
112
  minutes = "0" + minutes;
78
- return `${year}-${month}-${day} ${hour}:${minutes}`;
113
+ if (type == "datetime-local")
114
+ return `${year}-${month}-${day} ${hour}:${minutes}`;
115
+ else
116
+ return `${year}-${month}-${day}`;
79
117
  }
80
- function on_changed() {
118
+ async function on_changed() {
81
119
  if (!rValue)
82
120
  value = null;
83
121
  else
84
122
  value = new Date(rValue);
85
- if (item != null) {
123
+ console.log("rValue", rValue, "value", value);
124
+ if (on_select) {
125
+ await on_select(value);
126
+ } else if (item != null) {
86
127
  if (value)
87
128
  item[a] = value.toISOString();
88
129
  else
@@ -92,22 +133,89 @@ function on_changed() {
92
133
  $data_tick_store = $data_tick_store + 1;
93
134
  push_changes();
94
135
  }
136
+ if (!!changed)
137
+ changed(value);
95
138
  }
96
139
  }
140
+ function blur(e) {
141
+ if (!!on_hide_callback)
142
+ on_hide_callback();
143
+ }
97
144
  </script>
98
145
 
99
- {#if !can_be_activated}
100
- <span class="{style} ml-0.5 h-7" >{rValue}</span>
146
+ {#if is_compact}
147
+ <div class="inline-block relative {line_h}">
148
+ <span class="dark:text-white {font_size} truncate px-2.5 {background_class}
149
+ absolute left-0 top-0 h-full" >
150
+ {rValue}
151
+
152
+ {#if can_be_activated}
153
+ {#if type == "datetime-local"}
154
+ <input type="datetime-local"
155
+ class="datepicker-input"
156
+ on:change={on_changed}
157
+ bind:value={rValue}
158
+ bind:this={input_element}>
159
+ {:else}
160
+ <input type="date"
161
+ class="datepicker-input"
162
+ on:change={on_changed}
163
+ bind:value={rValue}
164
+ bind:this={input_element}
165
+ on:blur={blur}>
166
+ {/if}
167
+ {/if}
168
+ </span>
169
+ </div>
170
+
101
171
  {:else}
102
- <input class=" {cs} {style} {additional_class}"
103
- type="datetime-local"
104
- on:change={on_changed}
105
- bind:value={rValue}/>
172
+ {#if type == "datetime-local"}
173
+ <input class=" dark:text-white {cs} {style} {line_h} px-2.5 {background_class} {user_class}"
174
+ type="datetime-local"
175
+ on:change={on_changed}
176
+ bind:value={rValue}
177
+ bind:this={input_element}
178
+ />
179
+ {:else}
180
+ <input class=" dark:text-white {cs} {style} {line_h} px-2.5 {background_class} {user_class}"
181
+ type="date"
182
+ on:change={on_changed}
183
+ bind:value={rValue}
184
+ bind:this={input_element}
185
+ />
186
+ {/if}
106
187
  {/if}
107
188
 
108
189
 
190
+
191
+
192
+
109
193
  <style>
110
194
  input:focus {
111
195
  outline: 0px solid transparent;
112
196
  }
113
- </style>
197
+
198
+ .datepicker-input{
199
+ position: absolute;
200
+ left: 0;
201
+ top: 0;
202
+ width: 100%;
203
+ height: 100%;
204
+ opacity: 0;
205
+ cursor: pointer;
206
+ box-sizing: border-box;
207
+ }
208
+
209
+ .datepicker-input::-webkit-calendar-picker-indicator {
210
+ position: absolute;
211
+ left: 0;
212
+ top: 0;
213
+ width: 100%;
214
+ height: 100%;
215
+ margin: 0;
216
+ padding: 0;
217
+ cursor: pointer;
218
+ }
219
+
220
+ </style>
221
+
@@ -7,8 +7,14 @@ declare const __propDef: {
7
7
  context?: string | undefined;
8
8
  typename?: string | undefined;
9
9
  date?: Date | undefined;
10
+ on_select?: undefined;
11
+ type?: string | undefined;
12
+ changed?: undefined;
10
13
  s?: string | undefined;
11
14
  c?: string | undefined;
15
+ compact?: boolean | undefined;
16
+ in_context?: string | undefined;
17
+ show?: ((event: any, hide_callback: any) => void) | undefined;
12
18
  };
13
19
  events: {
14
20
  [evt: string]: CustomEvent<any>;
@@ -19,5 +25,6 @@ export type DateProps = typeof __propDef.props;
19
25
  export type DateEvents = typeof __propDef.events;
20
26
  export type DateSlots = typeof __propDef.slots;
21
27
  export default class Date extends SvelteComponentTyped<DateProps, DateEvents, DateSlots> {
28
+ get show(): (event: any, hide_callback: any) => void;
22
29
  }
23
30
  export {};
@@ -1,3 +1,3 @@
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, props?: {}): void;
3
- export declare function show_grid_menu(x: number, y: number, operations: any): void;
1
+ export declare function show_menu(around: DOMRect | DOMPoint, operations: any): void;
2
+ export declare function show_floating_toolbar(around: DOMRect | DOMPoint, toolbar: any, props?: {}): void;
3
+ export declare function show_grid_menu(around: DOMRect | DOMPoint, operations: any): void;
@@ -3,7 +3,7 @@ import Floating_container from './Floating_container.svelte';
3
3
  import Grid from './Grid.menu.svelte';
4
4
  let menu_comopnent = null;
5
5
  let toolbar_component = null;
6
- export function show_menu(x, y, operations) {
6
+ export function show_menu(around, operations) {
7
7
  let menu_element = document.getElementById("__hd_svelte_contextmenu");
8
8
  if (!!!menu_element) {
9
9
  let app_div = document.getElementById("__hd_svelte_layout_root");
@@ -11,14 +11,18 @@ export function show_menu(x, y, operations) {
11
11
  target: app_div,
12
12
  props: {}
13
13
  });
14
- menu_comopnent.show(x, y, operations);
14
+ menu_comopnent.show(around, operations);
15
+ }
16
+ else if (menu_comopnent) {
17
+ if (menu_comopnent.is_visible())
18
+ menu_comopnent.hide();
19
+ else
20
+ menu_comopnent.show(around, operations);
15
21
  }
16
- else if (menu_comopnent)
17
- menu_comopnent.show(x, y, operations);
18
22
  else
19
23
  console.error('what now?');
20
24
  }
21
- export function show_floating_toolbar(x, y, toolbar, props = {}) {
25
+ export function show_floating_toolbar(around, toolbar, props = {}) {
22
26
  let floating_container = document.getElementById("__hd_svelte_floating_container");
23
27
  if (!!!floating_container) {
24
28
  let app_div = document.getElementById("__hd_svelte_layout_root");
@@ -26,13 +30,19 @@ export function show_floating_toolbar(x, y, toolbar, props = {}) {
26
30
  target: app_div,
27
31
  props: {}
28
32
  });
29
- toolbar_component.show(x, y, toolbar, props);
33
+ toolbar_component.show(around, toolbar, props);
34
+ }
35
+ else if (toolbar_component) {
36
+ if (toolbar_component.is_visible()) {
37
+ toolbar_component.hide();
38
+ }
39
+ else {
40
+ toolbar_component.show(around, toolbar, props);
41
+ }
30
42
  }
31
- else if (toolbar_component)
32
- toolbar_component.show(x, y, toolbar, props);
33
43
  else
34
44
  console.error('what now?');
35
45
  }
36
- export function show_grid_menu(x, y, operations) {
37
- show_floating_toolbar(x, y, Grid, { operations: operations });
46
+ export function show_grid_menu(around, operations) {
47
+ show_floating_toolbar(around, Grid, { operations: operations });
38
48
  }
@@ -86,7 +86,7 @@ function show_context_menu(e, itm, cinfo2) {
86
86
  return;
87
87
  e.stopPropagation();
88
88
  e.preventDefault();
89
- show_menu(e.clientX, e.clientY, menu_operations);
89
+ show_menu(new DOMPoint(e.clientX, e.clientY), menu_operations);
90
90
  }
91
91
  </script>
92
92
 
package/desk.svelte CHANGED
@@ -16,10 +16,30 @@
16
16
  set_dark_mode_default } from './stores.js'
17
17
 
18
18
  import {session, AuthorizedView, Authorized, NotAuthorized, Auth} from '@humandialog/auth.svelte'
19
- import { handle_select } from './utils'
19
+ import { handle_select, is_device_smaller_than } from './utils'
20
20
 
21
21
  export let layout;
22
22
 
23
+ const sizes = {
24
+ bottom: 240,
25
+ toolbar: 40,
26
+ operations: 40,
27
+ sidebar: 320
28
+ }
29
+
30
+ $: outerWidth = 0
31
+ $: innerWidth = 0
32
+ $: outerHeight = 0
33
+ $: innerHeight = 0
34
+
35
+ const media_break_sm = 640; //px @media (min-width: 640px) { ... }
36
+ const media_break_md = 768; //px @media (min-width: 768px) { ... }
37
+ const media_break_lg = 1024; //px @media (min-width: 1024px) { ... }
38
+ const media_break_xl = 1280; //px @media (min-width: 1280px) { ... }
39
+ const media_break_2xl = 1536; //px
40
+ let test = "ala\n ma\n\tkota"
41
+
42
+ $: is_small = is_device_smaller_than("sm")
23
43
 
24
44
  let main_side_panel_visibility = "hidden"
25
45
  let lg_content_area_horizontal_dim = ""
@@ -54,7 +74,7 @@
54
74
  else
55
75
  {
56
76
  main_side_panel_visibility = "lg:block"
57
- lg_content_area_horizontal_dim = "lg:left-[360px] lg:w-[calc(100vw-360px)]"
77
+ lg_content_area_horizontal_dim = `lg:left-[360px] lg:w-[calc(100vw-360px)]`
58
78
  }
59
79
  }
60
80
 
@@ -63,7 +83,6 @@
63
83
  let bottom_bar_visibility = "hidden"
64
84
  let bottom_bar_visible = false
65
85
  let lg_main_sidebar_height = ""
66
- let lg_main_side_panel_height = "lg:h-[calc(100vh-240px)]"
67
86
  let fab_bottom = "bottom-0"
68
87
 
69
88
  let content_top = ""
@@ -75,34 +94,39 @@
75
94
 
76
95
  if(!has_selected_item())
77
96
  bottom_bar_visible = false;
78
-
97
+
79
98
  if(tools_visible)
80
99
  {
81
100
  tools_visibility = "fixed"
82
- content_top = "top-20 sm:top-10"
101
+
102
+ if(is_small)
103
+ content_top = `top-[80px] sm:top-[40px]`
104
+ else
105
+ content_top = `top-[80px] sm:top-[40px]`
106
+
83
107
  if(bottom_bar_visible)
84
- content_height = "h-[calc(100vh-320px)] sm:h-[calc(100vh-280px)]"
108
+ content_height = `h-[calc(100vh-320px)] sm:h-[calc(100vh-280px)]`
85
109
  else
86
- content_height = "h-[calc(100vh-80px)] sm:h-[calc(100vh-40px)]"
110
+ content_height = `h-[calc(100vh-80px)] sm:h-[calc(100vh-40px)]`
87
111
 
88
112
  }
89
113
  else
90
114
  {
91
115
  tools_visibility = "hidden"
92
- content_top = "top-10 sm:top-0"
116
+ content_top = `top-[40px] sm:top-0`
93
117
  if(bottom_bar_visible)
94
- content_height = "h-[calc(100vh-280px)] sm:h-[calc(100vh-240px)]"
118
+ content_height = `h-[calc(100vh-280px)] sm:h-[calc(100vh-240px)]`
95
119
  else
96
- content_height = "h-[calc(100vh-40px)] sm:h-screen"
120
+ content_height = `h-[calc(100vh-40px)] sm:h-screen`
97
121
  }
98
122
 
99
123
 
100
124
 
101
125
  if(bottom_bar_visible)
102
126
  {
103
- lg_main_sidebar_height = "lg:h-[calc(100vh-240px)]"
127
+ lg_main_sidebar_height = `lg:h-[calc(100vh-240px)]`
104
128
  bottom_bar_visibility = "fixed"
105
- fab_bottom = "bottom-[240px]";
129
+ fab_bottom = `bottom-[240px]`;
106
130
  }
107
131
  else
108
132
  {
@@ -113,20 +137,10 @@
113
137
 
114
138
  }
115
139
 
116
- let sm_main_side_panel_width = "sm:w-[320px]"
117
- let lg_main_content_height = "lg:h-[calc(100vh-280px)]"
118
-
119
- $: outerWidth = 0;
120
- $: innerWidth = 0;
121
- $: outerHeight = 0;
122
- $: innerHeight = 0;
123
- const media_break_sm = 640; //px @media (min-width: 640px) { ... }
124
- const media_break_md = 768; //px @media (min-width: 768px) { ... }
125
- const media_break_lg = 1024; //px @media (min-width: 1024px) { ... }
126
- const media_break_xl = 1280; //px @media (min-width: 1280px) { ... }
127
- const media_break_2xl = 1536; //px
128
- let test = "ala\n ma\n\tkota"
129
-
140
+
141
+
142
+
143
+
130
144
  //$: screen.width = innerWidth;
131
145
  </script>
132
146
 
@@ -164,9 +178,12 @@
164
178
  <!--#######################################################-->
165
179
  <!--## MAIN SIDE BAR ##################-->
166
180
  <!--#######################################################-->
167
- <div class="{main_side_panel_visibility} fixed left-0 top-10 w-screen h-[calc(100vh-40px)] z-10 overflow-x-hidden
168
- sm:left-10 sm:top-0 {sm_main_side_panel_width} sm:h-full
169
- {lg_main_sidebar_height}" >
181
+ <div class="{main_side_panel_visibility} fixed
182
+ left-0 sm:left-[40px]
183
+ top-[40px] sm:top-0
184
+ h-[calc(100vh-40px)] sm:h-full {lg_main_sidebar_height}
185
+ w-screen sm:w-[320px]
186
+ z-10 overflow-x-hidden">
170
187
 
171
188
  <div class=" bg-slate-50 w-full h-full dark:bg-slate-800 overflow-y-auto py-4 px-0">
172
189
  <Configurable config={layout.sidebar[visible_sidebar]}>
@@ -178,15 +195,18 @@
178
195
  <!--## HORIZONTAL TOOLS ######################-->
179
196
  <!--###########################################################-->
180
197
 
181
- <div class=" {tools_visibility} left-0 top-10 w-screen h-[40px]
182
- sm:left-[40px] sm:top-0 sm:w-[calc(100vw-40px)]
198
+ <div class=" {tools_visibility}
199
+ w-screen sm:w-[calc(100vw-40px)]
200
+ h-[40px]
201
+ left-0 sm:left-[40px]
202
+ top-[40px] sm:top-0
183
203
  {lg_content_area_horizontal_dim}
184
204
  z-0 overflow-hidden " >
185
205
 
186
206
  <Operations/>
187
207
  </div>
188
208
 
189
- <div class="{tools_visibility} right-3 {fab_bottom} mb-1 cursor-pointer z-20">
209
+ <div class="!hidden {tools_visibility} right-3 {fab_bottom} mb-1 cursor-pointer z-20">
190
210
  <Fab/>
191
211
  </div>
192
212
 
@@ -71,7 +71,7 @@
71
71
  let sidebar = $main_sidebar_visible_store;
72
72
  if(sidebar == "*")
73
73
  {
74
- if(!previously_visible_sidebar)
74
+ if((!previously_visible_sidebar) || previously_visible_sidebar === '*')
75
75
  sidebar = Object.keys(app_config.sidebar)[0];
76
76
  else
77
77
  sidebar = previously_visible_sidebar;
@@ -83,9 +83,14 @@
83
83
 
84
84
  function show_options(e)
85
85
  {
86
- let rect = e.target.getBoundingClientRect();
87
- let x = rect.left;
88
- let y = rect.bottom;
86
+ let owner = e.target;
87
+ while(owner && owner.tagName != 'BUTTON')
88
+ owner = owner.parentElement
89
+
90
+ if(!owner)
91
+ return;
92
+
93
+ let rect = owner.getBoundingClientRect();
89
94
  let options = [];
90
95
 
91
96
  if(show_sign_in_out_icons)
@@ -149,7 +154,8 @@
149
154
  });
150
155
  }
151
156
 
152
- show_menu(x, y, options);
157
+ let pt = new DOMPoint(rect.left, rect.bottom)
158
+ show_menu(pt, options);
153
159
  }
154
160
 
155
161
  </script>
package/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { default as Layout } from './desk.svelte';
7
7
  export { default as Icon } from "./components/icon.svelte";
8
8
  export { default as Button } from './components/button.svelte';
9
9
  export { default as Checkbox } from './components/checkbox.svelte';
10
- export { default as Date } from './components/date.svelte';
10
+ export { default as DatePicker } from './components/date.svelte';
11
11
  export { default as Edit } from './components/edit.field.svelte';
12
12
  export { default as FileLoader } from './components/file.loader.svelte';
13
13
  export { default as Input } from './components/inputbox.ltop.svelte';
package/index.js CHANGED
@@ -11,7 +11,7 @@ export { default as Layout } from './desk.svelte';
11
11
  export { default as Icon } from "./components/icon.svelte";
12
12
  export { default as Button } from './components/button.svelte';
13
13
  export { default as Checkbox } from './components/checkbox.svelte';
14
- export { default as Date } from './components/date.svelte';
14
+ export { default as DatePicker } from './components/date.svelte';
15
15
  export { default as Edit } from './components/edit.field.svelte';
16
16
  export { default as FileLoader } from './components/file.loader.svelte';
17
17
  export { default as Input } from './components/inputbox.ltop.svelte';
package/operations.svelte CHANGED
@@ -1,5 +1,6 @@
1
1
  <script>import { show_floating_toolbar, show_menu, show_grid_menu } from "./components/menu.js";
2
2
  import { context_toolbar_operations, page_toolbar_operations, context_items_store } from "./stores.js";
3
+ export let mobile = false;
3
4
  $:
4
5
  update($page_toolbar_operations, $context_toolbar_operations);
5
6
  let operations = [];
@@ -25,24 +26,29 @@ function on_click(e, operation) {
25
26
  if (!owner)
26
27
  return;
27
28
  let rect = owner.getBoundingClientRect();
29
+ let x = rect.left;
30
+ let y = mobile ? rect.top : rect.bottom;
28
31
  if (operation.menu)
29
- show_menu(rect.left, rect.bottom, operation.menu);
32
+ show_menu(rect, operation.menu);
30
33
  else if (operation.toolbar)
31
- show_floating_toolbar(rect.left, rect.bottom, operation.toolbar);
34
+ show_floating_toolbar(rect, operation.toolbar);
32
35
  else if (operation.grid)
33
- show_grid_menu(rect.left, rect.bottom, operation.grid);
36
+ show_grid_menu(rect, operation.grid);
34
37
  }
35
38
  </script>
36
39
 
37
- <div class="bg-slate-100 w-full h-10 dark:bg-slate-800 overflow-x-clip overflow-y-hidden py-0 text-xs flex flex-row">
40
+ <div class="bg-slate-100 w-full h-10 dark:bg-slate-800 overflow-x-clip overflow-y-hidden py-0 text-xs flex flex-row"
41
+ class:flex-row-reverse={mobile}>
38
42
 
39
43
  {#each operations as operation}
40
44
  <button type="button"
41
45
  class="py-2.5 px-5
42
46
  text-xs font-medium text-gray-900 dark:text-gray-400 dark:hover:text-white
43
47
  bg-slate-100 hover:bg-slate-200 dark:bg-gray-800 dark:hover:bg-gray-700 active:bg-slate-300 dark:active:bg-gray-600
44
- border-r border-gray-200 focus:outline-none dark:border-gray-600
48
+ border-gray-200 focus:outline-none dark:border-gray-600
45
49
  inline-flex items-center"
50
+ class:border-r={!mobile}
51
+ class:border-l={mobile}
46
52
  on:click={(e) => {on_click(e, operation)}}>
47
53
  <div class="w-3 h-3"><svelte:component this={operation.icon}/></div>
48
54
  <span class="ml-1">{operation.caption}</span>
@@ -1,6 +1,8 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
- props: Record<string, never>;
3
+ props: {
4
+ mobile?: boolean | undefined;
5
+ };
4
6
  events: {
5
7
  [evt: string]: CustomEvent<any>;
6
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humandialog/forms.svelte",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "description": "Basic Svelte UI components for Object Reef applications",
5
5
  "devDependencies": {
6
6
  "@playwright/test": "^1.28.1",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "type": "module",
28
28
  "dependencies": {
29
- "@humandialog/auth.svelte": "^1.0.2",
29
+ "@humandialog/auth.svelte": "^1.0.4",
30
30
  "flowbite-svelte": "^0.29.13",
31
31
  "svelte-icons": "^2.1.0",
32
32
  "svelte-spa-router": "^3.3.0"
package/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export function is_device_smaller_than(br: any): boolean;
1
2
  export function select_item(itm: any): void;
2
3
  export function activate_item(context_level: any, itm: any, operations?: null): void;
3
4
  export function clear_active_item(context_level: any): void;
@@ -16,3 +17,9 @@ export function should_be_comapact(): boolean;
16
17
  export namespace icons {
17
18
  const symbols: null;
18
19
  }
20
+ export namespace SCREEN_SIZES {
21
+ const sm: number;
22
+ const md: number;
23
+ const lg: number;
24
+ const xl: number;
25
+ }
package/utils.js CHANGED
@@ -4,6 +4,18 @@ import { context_items_store, context_toolbar_operations } from "./stores";
4
4
 
5
5
  export let icons = {symbols :null}
6
6
 
7
+ export const SCREEN_SIZES = {
8
+ sm: 640, //px @media (min-width: 640px) { ... }
9
+ md: 768, //px @media (min-width: 768px) { ... }
10
+ lg: 1024, //px @media (min-width: 1024px) { ... }
11
+ xl: 1280, //px @media (min-width: 1280px) { ... }
12
+ }
13
+
14
+ export function is_device_smaller_than(br)
15
+ {
16
+ return window.innerWidth < SCREEN_SIZES[br]
17
+ }
18
+
7
19
  export function select_item(itm)
8
20
  {
9
21
  let data_context = get(context_items_store);
@@ -178,8 +190,7 @@ export function selectable(node, itm)
178
190
  }
179
191
  catch(err)
180
192
  {
181
- console.error(err);
182
- console.log(node);
193
+ console.error(err, node);
183
194
  }
184
195
  }};
185
196
  }
@@ -76,9 +76,15 @@
76
76
 
77
77
  function show_options(e)
78
78
  {
79
- let rect = e.target.getBoundingClientRect();
80
- let x = rect.right;
81
- let y = rect.top;
79
+
80
+ let owner = e.target;
81
+ while(owner && owner.tagName != 'BUTTON')
82
+ owner = owner.parentElement
83
+
84
+ if(!owner)
85
+ return;
86
+
87
+ let rect = owner.getBoundingClientRect();
82
88
  let options = [];
83
89
 
84
90
  if(show_sign_in_out_icons)
@@ -142,7 +148,8 @@
142
148
  });
143
149
  }
144
150
 
145
- show_menu(x, y, options);
151
+ let pt = new DOMPoint(rect.right, rect.top)
152
+ show_menu(pt, options);
146
153
  }
147
154
 
148
155
  </script>