@humandialog/forms.svelte 0.4.11 → 0.4.12

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
1
  <script>
2
- import {context_items_store} from '..'
2
+ import {context_items_store} from '../stores.js'
3
3
 
4
4
  export let operations = []
5
5
  export let hide = undefined;
@@ -31,23 +31,36 @@ let filtered_source = null;
31
31
  let mutation_observer = null;
32
32
  let highlighted_option = null;
33
33
  let item = null;
34
+ let root_element;
34
35
  let label_mb = "mb-1";
35
36
  let input_pt = "pt-0.5";
36
37
  let input_pb = "pb-1";
38
+ let font_size = "text-sm";
39
+ let line_h = "h-5";
37
40
  switch (s) {
38
41
  case "md":
39
42
  label_mb = "mb-2";
40
43
  input_pt = "pt-2.5";
41
44
  input_pb = "pb-2.5";
45
+ font_size = "text-sm";
46
+ line_h = "h-5";
47
+ break;
48
+ case "xs":
49
+ label_mb = "mb-0.5";
50
+ input_pt = "pt-0.5";
51
+ input_pb = "pb-0.5";
52
+ font_size = "text-xs";
53
+ line_h = "h-4";
42
54
  break;
43
55
  }
56
+ let background_class = is_compact && !icon ? "bg-slate-900/10 dark:bg-slate-100/10 rounded-lg" : "";
44
57
  let appearance_class;
45
58
  if (is_compact)
46
- appearance_class = ` text-gray-900 text-sm
59
+ appearance_class = ` text-gray-900 ${font_size}
47
60
  focus:ring-primary-600 block w-full ${input_pb} ${input_pt} px-2.5 dark:bg-gray-700
48
- dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500`;
61
+ dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 ${background_class}`;
49
62
  else
50
- appearance_class = ` bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg
63
+ appearance_class = ` bg-gray-50 border border-gray-300 text-gray-900 ${font_size} rounded-lg
51
64
  focus:ring-primary-600 focus:border-primary-600 block w-full ${input_pb} ${input_pt} px-2.5 dark:bg-gray-700
52
65
  dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500`;
53
66
  let cs = c ? parse_width_directive(c) : "col-span-1";
@@ -76,12 +89,6 @@ afterUpdate(() => {
76
89
  if (is_dropdown_open && textbox && document.activeElement != textbox)
77
90
  textbox.focus();
78
91
  });
79
- function toggle() {
80
- if (is_dropdown_open)
81
- hide();
82
- else
83
- show();
84
- }
85
92
  function dropdown_action(node) {
86
93
  if (is_dropdown_open)
87
94
  dropdown_height = node.getBoundingClientRect().height;
@@ -94,13 +101,22 @@ function dropdown_action(node) {
94
101
  }
95
102
  };
96
103
  }
97
- function show() {
104
+ let on_hide_callback = void 0;
105
+ export function show(event, hide_callback) {
98
106
  if (!can_be_activated)
99
107
  return;
100
108
  if (!combo)
101
109
  return;
102
110
  if (is_dropdown_open)
103
111
  return;
112
+ if (event) {
113
+ event.stopPropagation();
114
+ event.preventDefault();
115
+ }
116
+ if (!!hide_callback)
117
+ on_hide_callback = hide_callback;
118
+ else
119
+ on_hide_callback = void 0;
104
120
  let client_rect;
105
121
  client_rect = new DOMRect();
106
122
  client_rect.x = 0;
@@ -112,6 +128,8 @@ function show() {
112
128
  let bottom_space = client_rect.height - (rect.y + rect.height);
113
129
  let palette_max_height_px = 500;
114
130
  let palette_width_px = rect.width;
131
+ if (palette_width_px < 120)
132
+ palette_width_px = 120;
115
133
  let preferred_palette_height = dropdown_height > 0 ? dropdown_height : palette_max_height_px;
116
134
  let preferred_palette_width = palette_width_px;
117
135
  let x = 0, y = 0;
@@ -131,11 +149,11 @@ function show() {
131
149
  y = rect.y;
132
150
  show_above = true;
133
151
  } else
134
- show_fullscreen = true;
135
- if (false) {
152
+ y = rect.y + rect.height;
153
+ if (show_fullscreen) {
136
154
  dropdown_position = `position: fixed; left: 0px; top: 0px; width: ${client_rect.width}px; height: ${client_rect.height}px;`;
137
155
  } else {
138
- dropdown_position = `width: ${rect.width}px; max-height:${palette_max_height_px}px; position: fixed; left:${x}px; top:${y}px;`;
156
+ dropdown_position = `min-width: ${palette_width_px}px; max-height:${palette_max_height_px}px; position: fixed; left:${x}px; top:${y}px;`;
139
157
  if (show_above)
140
158
  dropdown_position += " transform: translate(0, -100%);";
141
159
  }
@@ -163,12 +181,15 @@ function show() {
163
181
  highlighted_option = filtered_source.length > 0 ? filtered_source[0] : null;
164
182
  }
165
183
  }
166
- function hide() {
184
+ export function hide() {
167
185
  if (mutation_observer)
168
186
  mutation_observer.disconnect();
169
187
  is_dropdown_open = false;
170
188
  combo_text = get_combo_text();
171
- textbox.innerHtml = combo_text;
189
+ if (!!textbox)
190
+ textbox.innerHtml = combo_text;
191
+ if (!!on_hide_callback)
192
+ on_hide_callback();
172
193
  tick_request_internal = tick_request_internal + 1;
173
194
  }
174
195
  function selected_item(itm, a2) {
@@ -420,6 +441,11 @@ function setup_view(...args) {
420
441
  if (textbox)
421
442
  textbox.innerHTML = combo_text;
422
443
  }
444
+ function on_focus_out(e) {
445
+ if (e.relatedTarget && root_element?.contains(e.relatedTarget)) {
446
+ } else
447
+ hide();
448
+ }
423
449
  </script>
424
450
 
425
451
  <slot/> <!-- definition slot first -->
@@ -427,16 +453,18 @@ function setup_view(...args) {
427
453
 
428
454
  {#if true}
429
455
  {@const c = setup_view(item, a, tick_request_internal) }
430
-
456
+
431
457
  <div class={cs}
432
- on:focusout={(e) => setTimeout(() => {hide()}, 100)}>
458
+ on:focusout={on_focus_out}
459
+ bind:this={root_element}>
433
460
  {#if !is_compact}
434
461
  <label for="name" class="block {label_mb} text-xs font-small text-gray-900 dark:text-white">{label}</label>
435
462
  {/if}
436
463
  <!-- svelte-ignore a11y-click-events-have-key-events -->
437
464
  <div bind:this={combo}
438
- on:click|preventDefault|stopPropagation={show}
465
+ on:click={show}
439
466
  class="{appearance_class} flex flex-row content-between items-center"
467
+ class:cursor-pointer={can_be_activated && is_compact}
440
468
  >
441
469
 
442
470
  <div class="flex-1 flex flex-row items-center">
@@ -450,16 +478,19 @@ function setup_view(...args) {
450
478
  {/if}
451
479
  {/if}
452
480
 
481
+
453
482
  <p bind:this={textbox}
454
- class="ml-2 dark:text-white"
483
+ class="dark:text-white {line_h}"
484
+ class:ml-2={icon}
455
485
  class:text-gray-400={ (!is_dropdown_open) && (!sel_item)}
456
486
  class:text-gray-700={ is_dropdown_open || sel_item }
487
+ class:w-10={!combo_text}
457
488
  contenteditable={is_dropdown_open}
458
489
  on:keydown={on_keydown}>
459
490
  {combo_text}</p>
460
491
  </div>
461
492
 
462
- {#if can_be_activated }
493
+ {#if can_be_activated && !is_compact }
463
494
  <Icon size={3} component={FaChevronDown} class="flex-none text-gray-700 dark:text-gray-200"/>
464
495
  {/if}
465
496
  </div>
@@ -487,7 +518,8 @@ function setup_view(...args) {
487
518
  class:dark:bg-gray-700={highlighted_option == item}
488
519
  class:dark:hover:bg-gray-700={highlighted_option == item}
489
520
  on:mousemove={() => on_mouse_move(item)}
490
- on:click|preventDefault|stopPropagation={async () => await on_choose(item)}>
521
+ on:click|preventDefault|stopPropagation={async () => await on_choose(item)}
522
+ tabindex="-1">
491
523
 
492
524
  {#if icon}
493
525
  {#if item.Color}
@@ -14,6 +14,8 @@ declare const __propDef: {
14
14
  c?: string | undefined;
15
15
  compact?: boolean | undefined;
16
16
  in_context?: string | undefined;
17
+ show?: ((event: any, hide_callback: any) => void) | undefined;
18
+ hide?: (() => void) | undefined;
17
19
  };
18
20
  events: {
19
21
  [evt: string]: CustomEvent<any>;
@@ -26,5 +28,7 @@ export type ComboProps = typeof __propDef.props;
26
28
  export type ComboEvents = typeof __propDef.events;
27
29
  export type ComboSlots = typeof __propDef.slots;
28
30
  export default class Combo extends SvelteComponentTyped<ComboProps, ComboEvents, ComboSlots> {
31
+ get show(): (event: any, hide_callback: any) => void;
32
+ get hide(): () => void;
29
33
  }
30
34
  export {};
@@ -1,6 +1,43 @@
1
1
  <script>import { Spinner } from "flowbite-svelte";
2
2
  import { onMount } from "svelte";
3
+ export let color = "blue";
4
+ export let size = 8;
3
5
  export let delay = 100;
6
+ let user_class = $$props.class ?? "";
7
+ const sizes = {
8
+ 1: "w-1 h-1",
9
+ 2: "w-2 h-2",
10
+ 3: "w-3 h-3",
11
+ 4: "w-4 h-4",
12
+ 5: "w-5 h-5",
13
+ 6: "w-6 h-6",
14
+ 7: "w-7 h-7",
15
+ 8: "w-8 h-8",
16
+ 9: "w-9 h-9",
17
+ 10: "w-10 h-10",
18
+ 11: "w-11 h-11",
19
+ 12: "w-12 h-12",
20
+ 14: "w-14 h-14",
21
+ 16: "w-16 h-16",
22
+ 20: "w-20 h-20",
23
+ 24: "w-24 h-24",
24
+ 28: "w-28 h-28",
25
+ 32: "w-32 h-32",
26
+ 36: "w-36 h-36",
27
+ 40: "w-40 h-40"
28
+ };
29
+ let iconsize = sizes[size];
30
+ const colors = {
31
+ blue: "fill-blue-600",
32
+ gray: "fill-gray-600 dark:fill-gray-300",
33
+ green: "fill-green-500",
34
+ red: "fill-red-600",
35
+ yellow: "fill-yellow-400",
36
+ pink: "fill-pink-600",
37
+ purple: "fill-purple-600",
38
+ white: "fill-white"
39
+ };
40
+ let fillColorClass = colors[color];
4
41
  let visible = false;
5
42
  onMount(() => {
6
43
  visible = false;
@@ -14,5 +51,18 @@ onMount(() => {
14
51
 
15
52
 
16
53
  {#if visible}
17
- <Spinner/>
54
+ <svg
55
+ role="status"
56
+ class='inline -mt-px animate-spin dark:text-gray-600 {iconsize} text-gray-300 {fillColorClass} {user_class}'
57
+ viewBox="0 0 100 101"
58
+ fill="none"
59
+ xmlns="http://www.w3.org/2000/svg">
60
+
61
+ <path
62
+ d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
63
+ fill="currentColor" />
64
+ <path
65
+ d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
66
+ fill="currentFill" />
67
+ </svg>
18
68
  {/if}
@@ -1,6 +1,9 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
+ [x: string]: any;
5
+ color?: string | undefined;
6
+ size?: number | undefined;
4
7
  delay?: number | undefined;
5
8
  };
6
9
  events: {
@@ -6,8 +6,8 @@ export default class Inputbox extends SvelteComponentTyped<{
6
6
  label?: string | undefined;
7
7
  context?: string | undefined;
8
8
  self?: null | undefined;
9
- typename?: string | undefined;
10
9
  c?: string | undefined;
10
+ typename?: string | undefined;
11
11
  a?: string | undefined;
12
12
  s?: string | undefined;
13
13
  placeholder?: string | undefined;
@@ -28,8 +28,8 @@ declare const __propDef: {
28
28
  label?: string | undefined;
29
29
  context?: string | undefined;
30
30
  self?: null | undefined;
31
- typename?: string | undefined;
32
31
  c?: string | undefined;
32
+ typename?: string | undefined;
33
33
  a?: string | undefined;
34
34
  s?: string | undefined;
35
35
  placeholder?: string | undefined;
@@ -4,8 +4,8 @@
4
4
  export default class Form extends SvelteComponentTyped<{
5
5
  context?: string | undefined;
6
6
  self?: null | undefined;
7
- cl?: string | undefined;
8
7
  c?: string | undefined;
8
+ cl?: string | undefined;
9
9
  fit?: boolean | undefined;
10
10
  }, {
11
11
  [evt: string]: CustomEvent<any>;
@@ -21,8 +21,8 @@ declare const __propDef: {
21
21
  props: {
22
22
  context?: string | undefined;
23
23
  self?: null | undefined;
24
- cl?: string | undefined;
25
24
  c?: string | undefined;
25
+ cl?: string | undefined;
26
26
  fit?: boolean | undefined;
27
27
  };
28
28
  events: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humandialog/forms.svelte",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "description": "Basic Svelte UI components for Object Reef applications",
5
5
  "devDependencies": {
6
6
  "@playwright/test": "^1.28.1",
@@ -2,8 +2,8 @@
2
2
  /** @typedef {typeof __propDef.events} PageEvents */
3
3
  /** @typedef {typeof __propDef.slots} PageSlots */
4
4
  export default class Page extends SvelteComponentTyped<{
5
- cl?: string | undefined;
6
5
  c?: string | undefined;
6
+ cl?: string | undefined;
7
7
  w?: string | undefined;
8
8
  }, {
9
9
  [evt: string]: CustomEvent<any>;
@@ -17,8 +17,8 @@ export type PageSlots = typeof __propDef.slots;
17
17
  import { SvelteComponentTyped } from "svelte";
18
18
  declare const __propDef: {
19
19
  props: {
20
- cl?: string | undefined;
21
20
  c?: string | undefined;
21
+ cl?: string | undefined;
22
22
  w?: string | undefined;
23
23
  };
24
24
  events: {
package/page.svelte CHANGED
@@ -95,9 +95,15 @@
95
95
  if(!clears_context)
96
96
  return;
97
97
 
98
+ let contexts = clears_context.split(' ');
99
+ contexts.forEach(c =>
100
+ {
101
+ $context_items_store[c] = null;
102
+ $context_info_store[c] = '';
103
+ })
104
+
98
105
  e.stopPropagation();
99
- $context_items_store[clears_context] = null;
100
- $context_info_store[clears_context] = '';
106
+
101
107
  $context_toolbar_operations = [];
102
108
  $data_tick_store = $data_tick_store + 1;
103
109
  }
package/page.svelte.d.ts CHANGED
@@ -4,11 +4,11 @@
4
4
  export default class Page extends SvelteComponentTyped<{
5
5
  context?: string | undefined;
6
6
  self?: null | undefined;
7
+ c?: string | undefined;
8
+ cl?: string | undefined;
7
9
  typename?: string | undefined;
8
10
  focused_only?: boolean | undefined;
9
11
  in_context?: string | undefined;
10
- cl?: string | undefined;
11
- c?: string | undefined;
12
12
  toolbar_operations?: any;
13
13
  clears_context?: string | undefined;
14
14
  }, {
@@ -25,11 +25,11 @@ declare const __propDef: {
25
25
  props: {
26
26
  context?: string | undefined;
27
27
  self?: null | undefined;
28
+ c?: string | undefined;
29
+ cl?: string | undefined;
28
30
  typename?: string | undefined;
29
31
  focused_only?: boolean | undefined;
30
32
  in_context?: string | undefined;
31
- cl?: string | undefined;
32
- c?: string | undefined;
33
33
  toolbar_operations?: any;
34
34
  clears_context?: string | undefined;
35
35
  };
package/tile.svelte.d.ts CHANGED
@@ -4,8 +4,8 @@
4
4
  export default class Tile extends SvelteComponentTyped<{
5
5
  context?: string | undefined;
6
6
  self?: null | undefined;
7
- cl?: string | undefined;
8
7
  c?: string | undefined;
8
+ cl?: string | undefined;
9
9
  }, {
10
10
  [evt: string]: CustomEvent<any>;
11
11
  }, {
@@ -20,8 +20,8 @@ declare const __propDef: {
20
20
  props: {
21
21
  context?: string | undefined;
22
22
  self?: null | undefined;
23
- cl?: string | undefined;
24
23
  c?: string | undefined;
24
+ cl?: string | undefined;
25
25
  };
26
26
  events: {
27
27
  [evt: string]: CustomEvent<any>;
@@ -2,8 +2,8 @@
2
2
  /** @typedef {typeof __propDef.events} TilesEvents */
3
3
  /** @typedef {typeof __propDef.slots} TilesSlots */
4
4
  export default class Tiles extends SvelteComponentTyped<{
5
- cl?: string | undefined;
6
5
  c?: string | undefined;
6
+ cl?: string | undefined;
7
7
  w?: string | undefined;
8
8
  }, {
9
9
  [evt: string]: CustomEvent<any>;
@@ -17,8 +17,8 @@ export type TilesSlots = typeof __propDef.slots;
17
17
  import { SvelteComponentTyped } from "svelte";
18
18
  declare const __propDef: {
19
19
  props: {
20
- cl?: string | undefined;
21
20
  c?: string | undefined;
21
+ cl?: string | undefined;
22
22
  w?: string | undefined;
23
23
  };
24
24
  events: {
@@ -2,8 +2,8 @@
2
2
  /** @typedef {typeof __propDef.events} TilesEvents */
3
3
  /** @typedef {typeof __propDef.slots} TilesSlots */
4
4
  export default class Tiles extends SvelteComponentTyped<{
5
- cl?: string | undefined;
6
5
  c?: string | undefined;
6
+ cl?: string | undefined;
7
7
  }, {
8
8
  [evt: string]: CustomEvent<any>;
9
9
  }, {
@@ -16,8 +16,8 @@ export type TilesSlots = typeof __propDef.slots;
16
16
  import { SvelteComponentTyped } from "svelte";
17
17
  declare const __propDef: {
18
18
  props: {
19
- cl?: string | undefined;
20
19
  c?: string | undefined;
20
+ cl?: string | undefined;
21
21
  };
22
22
  events: {
23
23
  [evt: string]: CustomEvent<any>;