@humandialog/forms.svelte 0.6.1 → 1.1.0

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.
@@ -44,12 +44,19 @@ function on_changed() {
44
44
  }
45
45
  </script>
46
46
 
47
- <div class="ml-1 h-6 text-sm font-medium {cs} {color_style} {additional_class} flex items-center">
47
+ <div class="ml-1 h-6 text-sm font-medium {cs} {additional_class} flex items-center"
48
+ class:text-stone-400={!disabled}
49
+ class:text-stone-900={disabled}
50
+ class:dark:text-stone-300={!disabled}
51
+ class:dark:text-stone-500={disabled}>
48
52
  <input type="checkbox"
49
53
  bind:checked={value}
50
54
  on:change={on_changed}
51
55
  {disabled}
52
- class="w-4 h-4 bg-stone-100 border-stone-300 dark:ring-offset-stone-800 focus:ring-2 mr-2 dark:bg-stone-700 dark:border-stone-600 rounded text-blue-600 focus:ring-blue-500 dark:focus:ring-blue-600"/>
56
+ class=" w-4 h-4
57
+ bg-stone-100 border-stone-300 dark:bg-stone-700 dark:border-stone-600
58
+ dark:ring-offset-stone-800
59
+ focus:ring-2 mr-2 rounded text-blue-600 focus:ring-blue-500 dark:focus:ring-blue-600"/>
53
60
  <span class="ml-1">
54
61
  <slot/>
55
62
  </span>
@@ -27,6 +27,7 @@ export let cached = false;
27
27
  export let filtered = false;
28
28
  export let pushChangesImmediately = true;
29
29
  export let hasNone = isAssociation;
30
+ let userClass = $$restProps.class ?? "";
30
31
  let is_compact = getContext("rIs-table-component") || compact;
31
32
  if (!definition) {
32
33
  definition = new rCombo_definition();
@@ -113,6 +114,7 @@ onMount(() => {
113
114
  get_source_collection(definition.collection_path, `${definition.collection_path}`).then((source) => source_fetched(source));
114
115
  else if (definition.collection)
115
116
  source_fetched(definition.collection);
117
+ tick_request_internal = tick_request_internal + 1;
116
118
  return () => {
117
119
  };
118
120
  });
@@ -188,6 +190,10 @@ export function show(event, hide_callback) {
188
190
  if (show_above)
189
191
  dropdown_position += " transform: translate(0, -100%);";
190
192
  }
193
+ console.log("dropdown_position", dropdown_position, rect, client_rect);
194
+ console.log("preferred_palette_height", preferred_palette_height);
195
+ console.log("bottom_space", bottom_space);
196
+ console.log("top_space", top_space);
191
197
  is_dropdown_open = true;
192
198
  if (filtered) {
193
199
  if (!textbox)
@@ -261,14 +267,20 @@ function get_combo_text() {
261
267
  }
262
268
  async function on_choose(itm) {
263
269
  hide();
270
+ let success = true;
264
271
  if (onSelect) {
265
- if (itm == new_item_option)
266
- await onNewItemCreated(itm.Key, itm.Name);
267
- else {
272
+ if (itm == new_item_option) {
273
+ let res = await onNewItemCreated(itm.Key, itm.Name);
274
+ if (res !== void 0)
275
+ success = !!res;
276
+ } else {
277
+ let res;
268
278
  if (itm)
269
- await onSelect(item, itm.Key, itm.Name);
279
+ res = await onSelect(item, itm.Key, itm.Name);
270
280
  else
271
- await onSelect(item, null, null);
281
+ res = await onSelect(item, null, null);
282
+ if (res !== void 0)
283
+ success = !!res;
272
284
  }
273
285
  tick_request_internal = tick_request_internal + 1;
274
286
  } else {
@@ -343,7 +355,7 @@ async function on_choose(itm) {
343
355
  }
344
356
  }
345
357
  }
346
- if (!!changed) {
358
+ if (!!changed && success) {
347
359
  if (itm)
348
360
  changed(itm.Key, itm.Name);
349
361
  else
@@ -544,7 +556,7 @@ function on_focus_out(e) {
544
556
  {#if true}
545
557
  {@const c = setup_view(item, a, tick_request_internal) }
546
558
 
547
- <div class="{cs} max-w-full inline-block"
559
+ <div class="{cs} max-w-full inline-block {userClass}"
548
560
  on:focusout={on_focus_out}
549
561
  bind:this={root_element}>
550
562
  {#if !is_compact && label.length > 0}
@@ -2,6 +2,7 @@ import { SvelteComponentTyped } from "svelte";
2
2
  import { rCombo_definition } from './combo';
3
3
  declare const __propDef: {
4
4
  props: {
5
+ [x: string]: any;
5
6
  label?: string | undefined;
6
7
  self?: null | undefined;
7
8
  a?: string | undefined;
@@ -61,7 +61,7 @@ export async function show(around, _operations) {
61
61
  }
62
62
  visible = true;
63
63
  operations = [..._operations];
64
- focused_index = 0;
64
+ focused_index = operations.findIndex((o) => !o.disabled);
65
65
  const is_root_menu = owner_menu_item == void 0;
66
66
  if (is_root_menu) {
67
67
  hide_window_indicator = 0;
@@ -170,6 +170,9 @@ function execute_action(operation, index) {
170
170
  operation.action(context_item);
171
171
  }
172
172
  function focus_menu_item(index) {
173
+ const operation = operations[index];
174
+ if (operation.disabled)
175
+ return;
173
176
  focused_index = index;
174
177
  let element = menu_items[focused_index];
175
178
  element.focus();
@@ -224,7 +227,11 @@ function mousedown(e) {
224
227
  {@const icon_placeholder_with_desc = mobile ? 14 : 12}
225
228
  {@const icon_placeholder_size = operation.description ? icon_placeholder_with_desc : icon_placeholder_without_desc}
226
229
  {@const menu_item_id = menu_items_id_prefix + index}
227
- {@const active = ((!mobile) && (focused_index == index)) ? 'bg-stone-200 dark:bg-stone-600' : ''}
230
+ {@const isTop = index==0}
231
+ {@const isBottom = index == operations.length-1}
232
+ {@const isFocused = index == focused_index}
233
+ {@const clipFocusedBorder = isFocused ? (isTop ? 'rounded-t-lg' : (isBottom ? 'rounded-b-lg' : '')) : ''}
234
+ {@const active = ((!mobile) && isFocused) ? `bg-stone-200 dark:bg-stone-600 ${clipFocusedBorder}` : ''}
228
235
  {@const has_submenu = operation.menu !== undefined && operation.menu.length > 0}
229
236
 
230
237
  <button class="font-medium m-0 py-2 pr-4 text-lg sm:text-sm w-full text-left flex flex-row cursor-context-menu {active} focus:outline-none"
@@ -233,7 +240,9 @@ function mousedown(e) {
233
240
  on:click|stopPropagation={(e) => { execute_action(operation, index) } }
234
241
  on:mouseenter = {(e) => {on_mouse_move(index)}}
235
242
  on:keydown|stopPropagation={(e) => on_keydown(e, operation, index)}
236
- on:mousedown={mousedown}>
243
+ on:mousedown={mousedown}
244
+ disabled={operation.disabled}
245
+ class:opacity-60={operation.disabled}>
237
246
 
238
247
  <div class="flex items-center justify-center mt-1 sm:mt-0.5" style:width={`${icon_placeholder_size*0.25}rem`}>
239
248
  {#if operation.icon}
@@ -243,7 +252,7 @@ function mousedown(e) {
243
252
  {/if}
244
253
  </div>
245
254
  <div class="">
246
- <p>{operation.caption}</p>
255
+ <p> {operation.caption}</p>
247
256
  {#if operation.description}
248
257
  {@const shortcut_width_px = operation.shortcut ? 80 : 0}
249
258
  <p class="text-sm font-normal text-stone-900 dark:text-stone-500 truncate inline-block"
@@ -2,9 +2,9 @@
2
2
  /** @typedef {typeof __propDef.events} InputEvents */
3
3
  /** @typedef {typeof __propDef.slots} InputSlots */
4
4
  export default class Input extends SvelteComponentTyped<{
5
+ i?: null | undefined;
5
6
  s?: string | undefined;
6
7
  placeholder?: string | undefined;
7
- i?: null | undefined;
8
8
  fld?: string | undefined;
9
9
  }, {
10
10
  [evt: string]: CustomEvent<any>;
@@ -16,9 +16,9 @@ export type InputSlots = typeof __propDef.slots;
16
16
  import { SvelteComponentTyped } from "svelte";
17
17
  declare const __propDef: {
18
18
  props: {
19
+ i?: null | undefined;
19
20
  s?: string | undefined;
20
21
  placeholder?: string | undefined;
21
- i?: null | undefined;
22
22
  fld?: string | undefined;
23
23
  };
24
24
  events: {
@@ -20,32 +20,42 @@
20
20
  export let placeholder = 'pl'
21
21
  export let pushChangesImmediately = true;
22
22
 
23
+ export let required = false;
24
+
23
25
  export let s = 'sm'
24
26
  export let c = ''
25
- export let validateCb = undefined;
27
+ export let validation = undefined;
26
28
  export function validate()
27
29
  {
28
- if(!validateCb)
30
+ if(!validation)
29
31
  {
30
- invalid = false;
31
- return true;
32
+ if(required)
33
+ {
34
+ invalid = !val;
35
+ return !invalid;
36
+ }
37
+ else
38
+ {
39
+ invalid = false;
40
+ return true;
41
+ }
32
42
  }
33
43
 
34
- invalid = !validateCb(val);
44
+ invalid = !validation(val);
35
45
  return !invalid;
36
46
  }
37
47
 
38
48
 
39
49
  let item = null
40
50
 
41
- let label_mb = 'mb-1' //
51
+ let labelMargins = 'mt-1 mb-0.5' //
42
52
  let input_pt = 'pt-0.5'
43
53
  let input_pb = 'pb-1'
44
54
 
45
55
  switch (s)
46
56
  {
47
57
  case 'md':
48
- label_mb = 'mb-2';
58
+ labelMargins = 'mt-1 mb-1';
49
59
  input_pt = 'pt-2.5'
50
60
  input_pb = 'pb-2.5';
51
61
  break;
@@ -111,7 +121,7 @@
111
121
  {#if itype == 'text'}
112
122
  {@const border_style = invalid ? "border-red-300 dark:border-red-600" : "border-stone-300 dark:border-stone-500" }
113
123
  <div class={cs}>
114
- <label for="name" class="block {label_mb} text-xs font-small text-stone-900 dark:text-white">{label}</label>
124
+ <label for="name" class="block {labelMargins} text-xs font-small text-stone-900 dark:text-white">{label}</label>
115
125
 
116
126
  <input type=text name="name" id="name"
117
127
  bind:value={val}
@@ -6,16 +6,17 @@ export default class Inputbox extends SvelteComponentTyped<{
6
6
  self?: null | undefined;
7
7
  invalid?: boolean | undefined;
8
8
  label?: string | undefined;
9
- context?: string | undefined;
10
- c?: string | undefined;
11
- typename?: string | undefined;
12
9
  a?: string | undefined;
13
- pushChangesImmediately?: boolean | undefined;
14
10
  s?: string | undefined;
15
11
  placeholder?: string | undefined;
12
+ context?: string | undefined;
13
+ typename?: string | undefined;
14
+ c?: string | undefined;
15
+ pushChangesImmediately?: boolean | undefined;
16
16
  itype?: string | undefined;
17
17
  val?: string | undefined;
18
- validateCb?: any;
18
+ required?: boolean | undefined;
19
+ validation?: any;
19
20
  validate?: (() => boolean) | undefined;
20
21
  }, {
21
22
  [evt: string]: CustomEvent<any>;
@@ -32,16 +33,17 @@ declare const __propDef: {
32
33
  self?: null | undefined;
33
34
  invalid?: boolean | undefined;
34
35
  label?: string | undefined;
35
- context?: string | undefined;
36
- c?: string | undefined;
37
- typename?: string | undefined;
38
36
  a?: string | undefined;
39
- pushChangesImmediately?: boolean | undefined;
40
37
  s?: string | undefined;
41
38
  placeholder?: string | undefined;
39
+ context?: string | undefined;
40
+ typename?: string | undefined;
41
+ c?: string | undefined;
42
+ pushChangesImmediately?: boolean | undefined;
42
43
  itype?: string | undefined;
43
44
  val?: string | undefined;
44
- validateCb?: any;
45
+ required?: boolean | undefined;
46
+ validation?: any;
45
47
  validate?: (() => boolean) | undefined;
46
48
  };
47
49
  events: {
@@ -57,6 +57,22 @@ if (!title)
57
57
  title = definition.title;
58
58
  if (!summary)
59
59
  summary = definition.summary;
60
+ let [name_w, props_w] = calc_horz_division();
61
+ function calc_horz_division() {
62
+ const props_no = definition.properties.length;
63
+ switch (props_no) {
64
+ case 0:
65
+ return ["w-full", ""];
66
+ case 1:
67
+ return ["w-2/3", "w-1/3"];
68
+ case 2:
69
+ return ["w-2/3", "w-1/3"];
70
+ case 3:
71
+ return ["w-1/2", "w-1/2"];
72
+ default:
73
+ return ["w-1/3", "w-2/3"];
74
+ }
75
+ }
60
76
  function calculate_active(...args) {
61
77
  return isActive("props", item);
62
78
  }
@@ -230,6 +246,8 @@ export function scrollToView() {
230
246
 
231
247
  <slot name="left" element={item}/>
232
248
 
249
+ <i class="hidden sm:w-1/2 sm:w-2/3 sm:w-1/3"></i> <!-- just to force tailwind classes including -->
250
+
233
251
  <div class="ml-3 w-full py-1"
234
252
  use:selectable={item}
235
253
  on:click={(e) => {activate_row(e, item)}}
@@ -242,7 +260,7 @@ export function scrollToView() {
242
260
  {#if is_link_like}
243
261
  <p class=" text-lg font-semibold min-h-[1.75rem]
244
262
  sm:text-sm sm:font-semibold sm:min-h-[1.25rem]
245
- whitespace-nowrap overflow-clip w-full sm:flex-none sm:w-2/3
263
+ whitespace-nowrap overflow-clip w-full sm:flex-none sm:{name_w}
246
264
  sm:hover:cursor-pointer underline"
247
265
  id="__hd_list_ctrl_{item[item_key]}_Title"
248
266
  on:click|stopPropagation={followDefinedHRef}
@@ -258,7 +276,7 @@ export function scrollToView() {
258
276
  {:else}
259
277
  <p class=" text-lg font-semibold min-h-[1.75rem]
260
278
  sm:text-sm sm:font-semibold sm:min-h-[1.25rem]
261
- whitespace-nowrap overflow-clip w-full sm:flex-none sm:w-2/3"
279
+ whitespace-nowrap overflow-clip w-full sm:flex-none sm:{name_w}"
262
280
  id="__hd_list_ctrl_{item[item_key]}_Title"
263
281
  use:editable={{
264
282
  action: (text) => {change_name(text)},
@@ -279,14 +297,14 @@ export function scrollToView() {
279
297
  {:else}
280
298
  <p class=" text-lg font-semibold min-h-[1.75rem]
281
299
  sm:text-sm sm:font-semibold sm:min-h-[1.25rem]
282
- whitespace-nowrap overflow-clip w-full sm:flex-none sm:w-2/3"
300
+ whitespace-nowrap overflow-clip w-full sm:flex-none sm:{name_w}"
283
301
  id="__hd_list_ctrl_{item[item_key]}_Title">
284
302
  {element_title}
285
303
  </p>
286
304
  {/if}
287
305
 
288
306
 
289
- <section class="hidden sm:block w-full sm:flex-none sm:w-1/3">
307
+ <section class="hidden sm:block w-full sm:flex-none sm:{props_w}">
290
308
  <Properties {definition} {item} {placeholder} bind:this={props_md}/>
291
309
  </section>
292
310
  </div>
@@ -286,33 +286,35 @@ async function insert(title2, summary, after) {
286
286
 
287
287
  <!--div class="w-full h-full overflow-y-auto"-->
288
288
 
289
- {#if items && items.length > 0 }
290
- {#each items as element, i (getItemKey(element))}
291
-
292
- <List_element item={element}
293
- {toolbarOperations}
294
- {contextMenu}
295
- bind:this={rows[i]}
296
- >
297
-
298
- <span slot="left" let:element>
299
- <slot name="left" {element}/>
300
- </span>
301
- </List_element>
302
-
303
- {#if show_insertion_row_after_element == element}
304
- <Inserter onInsert={async (title, summary) => {await insert(title, summary, show_insertion_row_after_element)}}
305
- icon={definition.inserter_icon}
306
- bind:this={inserter} />
307
- {/if}
308
- {/each}
309
- {/if}
310
289
 
311
- {#if show_insertion_row_after_element == END_OF_LIST}
312
- <Inserter onInsert={async (title, summary) => {await insert(title, summary, null)}}
313
- icon={definition.inserter_icon}
314
- bind:this={inserter} />
315
- {/if}
290
+ {#if items && items.length > 0 }
291
+ {#each items as element, i (getItemKey(element))}
292
+
293
+ <List_element item={element}
294
+ {toolbarOperations}
295
+ {contextMenu}
296
+ bind:this={rows[i]}
297
+ >
298
+
299
+ <span slot="left" let:element>
300
+ <slot name="left" {element}/>
301
+ </span>
302
+ </List_element>
303
+
304
+ {#if show_insertion_row_after_element == element}
305
+ <Inserter onInsert={async (title, summary) => {await insert(title, summary, show_insertion_row_after_element)}}
306
+ icon={definition.inserter_icon}
307
+ bind:this={inserter} />
308
+ {/if}
309
+ {/each}
310
+ {/if}
311
+
312
+ {#if show_insertion_row_after_element == END_OF_LIST}
313
+ <Inserter onInsert={async (title, summary) => {await insert(title, summary, null)}}
314
+ icon={definition.inserter_icon}
315
+ bind:this={inserter} />
316
+ {/if}
317
+
316
318
 
317
319
  <!--/div-->
318
320
 
@@ -7,8 +7,8 @@
7
7
 
8
8
  </script>
9
9
 
10
- <section class={user_class}>
11
- <a href={href} class="flex items-center pl-2.5 mb-5">
10
+ <section class="mb-5 {user_class}">
11
+ <a href={href} class="flex items-center pl-2.5 ">
12
12
  {#if img}
13
13
  <img src={img} class="h-6 mr-3 sm:h-7" alt="" />
14
14
  {/if}
@@ -17,4 +17,7 @@
17
17
  <slot/>
18
18
  </span>
19
19
  </a>
20
+ {#if $$slots.summary}
21
+ <slot name="summary"/>
22
+ {/if}
20
23
  </section>
@@ -9,6 +9,7 @@ export default class Sidebar extends SvelteComponentTyped<{
9
9
  [evt: string]: CustomEvent<any>;
10
10
  }, {
11
11
  default: {};
12
+ summary: {};
12
13
  }> {
13
14
  }
14
15
  export type SidebarProps = typeof __propDef.props;
@@ -26,6 +27,7 @@ declare const __propDef: {
26
27
  };
27
28
  slots: {
28
29
  default: {};
30
+ summary: {};
29
31
  };
30
32
  };
31
33
  export {};
@@ -5,8 +5,8 @@ export default class Simple extends SvelteComponentTyped<{
5
5
  focus?: boolean | undefined;
6
6
  select?: string | undefined;
7
7
  self?: null | undefined;
8
- context?: string | undefined;
9
8
  nav?: boolean | undefined;
9
+ context?: string | undefined;
10
10
  collection?: string | undefined;
11
11
  objects?: null | undefined;
12
12
  headers?: any[] | undefined;
@@ -25,8 +25,8 @@ declare const __propDef: {
25
25
  focus?: boolean | undefined;
26
26
  select?: string | undefined;
27
27
  self?: null | undefined;
28
- context?: string | undefined;
29
28
  nav?: boolean | undefined;
29
+ context?: string | undefined;
30
30
  collection?: string | undefined;
31
31
  objects?: null | undefined;
32
32
  headers?: any[] | undefined;
@@ -5,8 +5,8 @@ export default class Template extends SvelteComponentTyped<{
5
5
  focus?: boolean | undefined;
6
6
  select?: string | undefined;
7
7
  self?: null | undefined;
8
- context?: string | undefined;
9
8
  nav?: boolean | undefined;
9
+ context?: string | undefined;
10
10
  collection?: string | undefined;
11
11
  objects?: null | undefined;
12
12
  headers?: any[] | undefined;
@@ -33,8 +33,8 @@ declare const __propDef: {
33
33
  focus?: boolean | undefined;
34
34
  select?: string | undefined;
35
35
  self?: null | undefined;
36
- context?: string | undefined;
37
36
  nav?: boolean | undefined;
37
+ context?: string | undefined;
38
38
  collection?: string | undefined;
39
39
  objects?: null | undefined;
40
40
  headers?: any[] | undefined;
@@ -3,9 +3,9 @@
3
3
  /** @typedef {typeof __propDef.slots} TextareaSlots */
4
4
  export default class Textarea extends SvelteComponentTyped<{
5
5
  label?: string | undefined;
6
- c?: string | undefined;
7
6
  s?: string | undefined;
8
7
  placeholder?: string | undefined;
8
+ c?: string | undefined;
9
9
  val?: string | undefined;
10
10
  sy?: string | undefined;
11
11
  r?: number | undefined;
@@ -20,9 +20,9 @@ import { SvelteComponentTyped } from "svelte";
20
20
  declare const __propDef: {
21
21
  props: {
22
22
  label?: string | undefined;
23
- c?: string | undefined;
24
23
  s?: string | undefined;
25
24
  placeholder?: string | undefined;
25
+ c?: string | undefined;
26
26
  val?: string | undefined;
27
27
  sy?: string | undefined;
28
28
  r?: number | undefined;
@@ -4,8 +4,8 @@
4
4
  export default class Tile extends SvelteComponentTyped<{
5
5
  [x: string]: any;
6
6
  label?: string | undefined;
7
- c?: string | undefined;
8
7
  a?: string | undefined;
8
+ c?: string | undefined;
9
9
  }, {
10
10
  [evt: string]: CustomEvent<any>;
11
11
  }, {}> {
@@ -18,8 +18,8 @@ declare const __propDef: {
18
18
  props: {
19
19
  [x: string]: any;
20
20
  label?: string | undefined;
21
- c?: string | undefined;
22
21
  a?: string | undefined;
22
+ c?: string | undefined;
23
23
  };
24
24
  events: {
25
25
  [evt: string]: CustomEvent<any>;