@humandialog/forms.svelte 0.4.11 → 0.4.13
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.
- package/components/Grid.menu.svelte +1 -1
- package/components/combo/combo.svelte +53 -21
- package/components/combo/combo.svelte.d.ts +4 -0
- package/components/delayed.spinner.svelte +51 -1
- package/components/delayed.spinner.svelte.d.ts +3 -0
- package/components/inputbox.ltop.svelte.d.ts +2 -2
- package/components/sidebar/sidebar.brand.svelte +16 -0
- package/components/sidebar/sidebar.brand.svelte.d.ts +29 -0
- package/components/sidebar/sidebar.group.svelte +21 -0
- package/components/sidebar/sidebar.group.svelte.d.ts +31 -0
- package/components/sidebar/sidebar.item.svelte +60 -0
- package/components/sidebar/sidebar.item.svelte.d.ts +25 -0
- package/components/sidebar/sidebar.svelte +9 -0
- package/components/sidebar/sidebar.svelte.d.ts +27 -0
- package/components/simple.table.svelte.d.ts +2 -2
- package/components/table/_template.table.svelte.d.ts +2 -2
- package/desk.svelte +7 -3
- package/form.box.svelte.d.ts +2 -2
- package/index.d.ts +5 -0
- package/index.js +5 -0
- package/package.json +5 -1
- package/page.row.svelte.d.ts +2 -2
- package/page.svelte +8 -2
- package/page.svelte.d.ts +4 -4
- package/tile.svelte.d.ts +2 -2
- package/tiles.row.svelte.d.ts +2 -2
- package/tiles.vertical.row.svelte.d.ts +2 -2
- package/utils.d.ts +13 -0
- package/utils.js +213 -1
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
135
|
-
if (
|
|
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: ${
|
|
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
|
|
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={
|
|
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
|
|
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="
|
|
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
|
-
<
|
|
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}
|
|
@@ -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;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
<script>
|
|
3
|
+
export let href = "/";
|
|
4
|
+
export let img = "";
|
|
5
|
+
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<a href={href} class="flex items-center pl-2.5 mb-5">
|
|
9
|
+
{#if img}
|
|
10
|
+
<img src={img} class="h-6 mr-3 sm:h-7" alt="" />
|
|
11
|
+
{/if}
|
|
12
|
+
|
|
13
|
+
<span class="self-center text-2xl font-semibold whitespace-nowrap dark:text-white">
|
|
14
|
+
<slot/>
|
|
15
|
+
</span>
|
|
16
|
+
</a>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** @typedef {typeof __propDef.props} SidebarProps */
|
|
2
|
+
/** @typedef {typeof __propDef.events} SidebarEvents */
|
|
3
|
+
/** @typedef {typeof __propDef.slots} SidebarSlots */
|
|
4
|
+
export default class Sidebar extends SvelteComponentTyped<{
|
|
5
|
+
img?: string | undefined;
|
|
6
|
+
href?: string | undefined;
|
|
7
|
+
}, {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
}, {
|
|
10
|
+
default: {};
|
|
11
|
+
}> {
|
|
12
|
+
}
|
|
13
|
+
export type SidebarProps = typeof __propDef.props;
|
|
14
|
+
export type SidebarEvents = typeof __propDef.events;
|
|
15
|
+
export type SidebarSlots = typeof __propDef.slots;
|
|
16
|
+
import { SvelteComponentTyped } from "svelte";
|
|
17
|
+
declare const __propDef: {
|
|
18
|
+
props: {
|
|
19
|
+
img?: string | undefined;
|
|
20
|
+
href?: string | undefined;
|
|
21
|
+
};
|
|
22
|
+
events: {
|
|
23
|
+
[evt: string]: CustomEvent<any>;
|
|
24
|
+
};
|
|
25
|
+
slots: {
|
|
26
|
+
default: {};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Icon from '../icon.svelte'
|
|
3
|
+
import Edit from '../edit.field.svelte'
|
|
4
|
+
import {FaPlus} from 'svelte-icons/fa'
|
|
5
|
+
|
|
6
|
+
export let border = false;
|
|
7
|
+
export let inserter = undefined;
|
|
8
|
+
export let inserter_placeholder = 'New'
|
|
9
|
+
|
|
10
|
+
let border_class = border ? " pt-4 mt-4 border-t border-gray-200 dark:border-gray-700" : ""
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<ul class="space-y-2 {border_class}">
|
|
14
|
+
<slot/>
|
|
15
|
+
|
|
16
|
+
{#if inserter}
|
|
17
|
+
<Edit class="p-2 text-base font-normal text-gray-500 rounded-lg dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700" on_enter={inserter} placeholder={inserter_placeholder} inserter={true}>
|
|
18
|
+
<Icon size={5} component={FaPlus} class="mr-3"/>
|
|
19
|
+
</Edit>
|
|
20
|
+
{/if}
|
|
21
|
+
</ul>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** @typedef {typeof __propDef.props} SidebarProps */
|
|
2
|
+
/** @typedef {typeof __propDef.events} SidebarEvents */
|
|
3
|
+
/** @typedef {typeof __propDef.slots} SidebarSlots */
|
|
4
|
+
export default class Sidebar extends SvelteComponentTyped<{
|
|
5
|
+
inserter?: any;
|
|
6
|
+
border?: boolean | undefined;
|
|
7
|
+
inserter_placeholder?: string | undefined;
|
|
8
|
+
}, {
|
|
9
|
+
[evt: string]: CustomEvent<any>;
|
|
10
|
+
}, {
|
|
11
|
+
default: {};
|
|
12
|
+
}> {
|
|
13
|
+
}
|
|
14
|
+
export type SidebarProps = typeof __propDef.props;
|
|
15
|
+
export type SidebarEvents = typeof __propDef.events;
|
|
16
|
+
export type SidebarSlots = typeof __propDef.slots;
|
|
17
|
+
import { SvelteComponentTyped } from "svelte";
|
|
18
|
+
declare const __propDef: {
|
|
19
|
+
props: {
|
|
20
|
+
inserter?: any;
|
|
21
|
+
border?: boolean | undefined;
|
|
22
|
+
inserter_placeholder?: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
events: {
|
|
25
|
+
[evt: string]: CustomEvent<any>;
|
|
26
|
+
};
|
|
27
|
+
slots: {
|
|
28
|
+
default: {};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script>import Icon from "../icon.svelte";
|
|
2
|
+
import { context_items_store, auto_hide_sidebar } from "../../stores";
|
|
3
|
+
import {
|
|
4
|
+
selectable as _selectable,
|
|
5
|
+
is_selected,
|
|
6
|
+
editable as _editable
|
|
7
|
+
} from "../../utils";
|
|
8
|
+
export let href;
|
|
9
|
+
export let icon = void 0;
|
|
10
|
+
export let active = false;
|
|
11
|
+
export let selectable = void 0;
|
|
12
|
+
export let editable = void 0;
|
|
13
|
+
$:
|
|
14
|
+
context_data = $context_items_store;
|
|
15
|
+
let user_class = $$props.class ?? "";
|
|
16
|
+
function selectable_if_needed(node, selectable2) {
|
|
17
|
+
if (selectable2)
|
|
18
|
+
_selectable(node, selectable2);
|
|
19
|
+
}
|
|
20
|
+
function selected(itm, context_data2) {
|
|
21
|
+
if (is_selected(itm))
|
|
22
|
+
return true;
|
|
23
|
+
else
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
function editable_if_needed(node, editable2) {
|
|
27
|
+
if (editable2)
|
|
28
|
+
_editable(node, editable2);
|
|
29
|
+
}
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<li>
|
|
33
|
+
<a
|
|
34
|
+
href={href}
|
|
35
|
+
on:click={ (e) => auto_hide_sidebar() }
|
|
36
|
+
on:contextmenu
|
|
37
|
+
class="flex items-center p-2 text-base font-normal text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 border-2 border-transparent {user_class}"
|
|
38
|
+
class:bg-gray-200={active}
|
|
39
|
+
class:dark:bg-gray-700={active}
|
|
40
|
+
use:selectable_if_needed={selectable}
|
|
41
|
+
class:selected={selected(selectable, context_data)}
|
|
42
|
+
>
|
|
43
|
+
{#if icon}
|
|
44
|
+
<Icon size={5} component={icon}/>
|
|
45
|
+
{/if}
|
|
46
|
+
<span class="ml-3"
|
|
47
|
+
use:editable_if_needed={editable}>
|
|
48
|
+
<slot/>
|
|
49
|
+
</span>
|
|
50
|
+
</a>
|
|
51
|
+
</li>
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
<style>
|
|
55
|
+
.selected {
|
|
56
|
+
border-width: 2px;
|
|
57
|
+
--tw-border-opacity: 1 !important;
|
|
58
|
+
border-color: rgb(147 197 253 / var(--tw-border-opacity)) !important
|
|
59
|
+
}
|
|
60
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
href: string;
|
|
6
|
+
icon?: any | undefined;
|
|
7
|
+
active?: boolean | undefined;
|
|
8
|
+
selectable?: any | undefined;
|
|
9
|
+
editable?: any | undefined;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
contextmenu: MouseEvent;
|
|
13
|
+
} & {
|
|
14
|
+
[evt: string]: CustomEvent<any>;
|
|
15
|
+
};
|
|
16
|
+
slots: {
|
|
17
|
+
default: {};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type SidebarProps = typeof __propDef.props;
|
|
21
|
+
export type SidebarEvents = typeof __propDef.events;
|
|
22
|
+
export type SidebarSlots = typeof __propDef.slots;
|
|
23
|
+
export default class Sidebar extends SvelteComponentTyped<SidebarProps, SidebarEvents, SidebarSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** @typedef {typeof __propDef.props} SidebarProps */
|
|
2
|
+
/** @typedef {typeof __propDef.events} SidebarEvents */
|
|
3
|
+
/** @typedef {typeof __propDef.slots} SidebarSlots */
|
|
4
|
+
export default class Sidebar extends SvelteComponentTyped<{
|
|
5
|
+
[x: string]: never;
|
|
6
|
+
}, {
|
|
7
|
+
[evt: string]: CustomEvent<any>;
|
|
8
|
+
}, {
|
|
9
|
+
default: {};
|
|
10
|
+
}> {
|
|
11
|
+
}
|
|
12
|
+
export type SidebarProps = typeof __propDef.props;
|
|
13
|
+
export type SidebarEvents = typeof __propDef.events;
|
|
14
|
+
export type SidebarSlots = typeof __propDef.slots;
|
|
15
|
+
import { SvelteComponentTyped } from "svelte";
|
|
16
|
+
declare const __propDef: {
|
|
17
|
+
props: {
|
|
18
|
+
[x: string]: never;
|
|
19
|
+
};
|
|
20
|
+
events: {
|
|
21
|
+
[evt: string]: CustomEvent<any>;
|
|
22
|
+
};
|
|
23
|
+
slots: {
|
|
24
|
+
default: {};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} SimpleEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} SimpleSlots */
|
|
4
4
|
export default class Simple extends SvelteComponentTyped<{
|
|
5
|
-
focus?: boolean | undefined;
|
|
6
5
|
select?: string | undefined;
|
|
6
|
+
focus?: boolean | undefined;
|
|
7
7
|
context?: string | undefined;
|
|
8
8
|
self?: null | undefined;
|
|
9
9
|
nav?: boolean | undefined;
|
|
@@ -22,8 +22,8 @@ export type SimpleSlots = typeof __propDef.slots;
|
|
|
22
22
|
import { SvelteComponentTyped } from "svelte";
|
|
23
23
|
declare const __propDef: {
|
|
24
24
|
props: {
|
|
25
|
-
focus?: boolean | undefined;
|
|
26
25
|
select?: string | undefined;
|
|
26
|
+
focus?: boolean | undefined;
|
|
27
27
|
context?: string | undefined;
|
|
28
28
|
self?: null | undefined;
|
|
29
29
|
nav?: boolean | undefined;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} TemplateEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} TemplateSlots */
|
|
4
4
|
export default class Template extends SvelteComponentTyped<{
|
|
5
|
-
focus?: boolean | undefined;
|
|
6
5
|
select?: string | undefined;
|
|
6
|
+
focus?: boolean | undefined;
|
|
7
7
|
context?: string | undefined;
|
|
8
8
|
self?: null | undefined;
|
|
9
9
|
nav?: boolean | undefined;
|
|
@@ -30,8 +30,8 @@ export type TemplateSlots = typeof __propDef.slots;
|
|
|
30
30
|
import { SvelteComponentTyped } from "svelte";
|
|
31
31
|
declare const __propDef: {
|
|
32
32
|
props: {
|
|
33
|
-
focus?: boolean | undefined;
|
|
34
33
|
select?: string | undefined;
|
|
34
|
+
focus?: boolean | undefined;
|
|
35
35
|
context?: string | undefined;
|
|
36
36
|
self?: null | undefined;
|
|
37
37
|
nav?: boolean | undefined;
|
package/desk.svelte
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
set_dark_mode_default } from './stores.js'
|
|
17
17
|
|
|
18
18
|
import {session, AuthorizedView, Authorized, NotAuthorized, Auth} from '@humandialog/auth.svelte'
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
import { handle_select } from './utils'
|
|
20
|
+
|
|
21
21
|
export let layout;
|
|
22
22
|
|
|
23
23
|
|
|
@@ -133,7 +133,11 @@
|
|
|
133
133
|
<svelte:window bind:innerWidth bind:outerWidth bind:innerHeight bind:outerHeight />
|
|
134
134
|
|
|
135
135
|
<AuthorizedView>
|
|
136
|
-
|
|
136
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
137
|
+
<div id="__hd_svelte_layout_root" class="{$dark_mode_store}"
|
|
138
|
+
on:click={handle_select}
|
|
139
|
+
on:contextmenu={handle_select}>
|
|
140
|
+
|
|
137
141
|
<div class="bg-white dark:bg-gray-900 dark:text-white min-h-screen h-screen">
|
|
138
142
|
<!--###########################################################-->
|
|
139
143
|
<!--## HORIZONTAL TOOLBAR (FOR PHONES) ######################-->
|
package/form.box.svelte.d.ts
CHANGED
|
@@ -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/index.d.ts
CHANGED
|
@@ -24,5 +24,10 @@ export { default as RichEdit } from './components/document/rich.edit.svelte';
|
|
|
24
24
|
export { default as Spinner } from './components/delayed.spinner.svelte';
|
|
25
25
|
export { show_menu, show_grid_menu, show_floating_toolbar } from './components/menu';
|
|
26
26
|
export { default as Fab } from './components/Fab.svelte';
|
|
27
|
+
export { default as Sidebar } from './components/sidebar/sidebar.svelte';
|
|
28
|
+
export { default as SidebarBrand } from './components/sidebar/sidebar.brand.svelte';
|
|
29
|
+
export { default as SidebarGroup } from './components/sidebar/sidebar.group.svelte';
|
|
30
|
+
export { default as SidebarItem } from './components/sidebar/sidebar.item.svelte';
|
|
31
|
+
export { select_item, activate_item, clear_active_item, is_active, is_selected, editable, start_editing, selectable, handle_select } from './utils';
|
|
27
32
|
export { data_tick_store, has_selected_item, has_data_item } from "./stores";
|
|
28
33
|
export { context_toolbar_operations, page_toolbar_operations, context_items_store } from './stores';
|
package/index.js
CHANGED
|
@@ -29,5 +29,10 @@ export { default as Spinner } from './components/delayed.spinner.svelte';
|
|
|
29
29
|
//export { default as Menu } from './components/contextmenu.svelte'
|
|
30
30
|
export { show_menu, show_grid_menu, show_floating_toolbar } from './components/menu';
|
|
31
31
|
export { default as Fab } from './components/Fab.svelte';
|
|
32
|
+
export { default as Sidebar } from './components/sidebar/sidebar.svelte';
|
|
33
|
+
export { default as SidebarBrand } from './components/sidebar/sidebar.brand.svelte';
|
|
34
|
+
export { default as SidebarGroup } from './components/sidebar/sidebar.group.svelte';
|
|
35
|
+
export { default as SidebarItem } from './components/sidebar/sidebar.item.svelte';
|
|
36
|
+
export { select_item, activate_item, clear_active_item, is_active, is_selected, editable, start_editing, selectable, handle_select } from './utils';
|
|
32
37
|
export { data_tick_store, has_selected_item, has_data_item } from "./stores";
|
|
33
38
|
export { context_toolbar_operations, page_toolbar_operations, context_items_store } from './stores'; // tmp
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humandialog/forms.svelte",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"description": "Basic Svelte UI components for Object Reef applications",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@playwright/test": "^1.28.1",
|
|
@@ -76,6 +76,10 @@
|
|
|
76
76
|
"./components/inputbox.ltop.svelte": "./components/inputbox.ltop.svelte",
|
|
77
77
|
"./components/menu": "./components/menu.js",
|
|
78
78
|
"./components/radio.svelte": "./components/radio.svelte",
|
|
79
|
+
"./components/sidebar/sidebar.brand.svelte": "./components/sidebar/sidebar.brand.svelte",
|
|
80
|
+
"./components/sidebar/sidebar.group.svelte": "./components/sidebar/sidebar.group.svelte",
|
|
81
|
+
"./components/sidebar/sidebar.item.svelte": "./components/sidebar/sidebar.item.svelte",
|
|
82
|
+
"./components/sidebar/sidebar.svelte": "./components/sidebar/sidebar.svelte",
|
|
79
83
|
"./components/simple.table.svelte": "./components/simple.table.svelte",
|
|
80
84
|
"./components/table/column.svelte": "./components/table/column.svelte",
|
|
81
85
|
"./components/table/item.svelte": "./components/table/item.svelte",
|
package/page.row.svelte.d.ts
CHANGED
|
@@ -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
|
-
|
|
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>;
|
package/tiles.row.svelte.d.ts
CHANGED
|
@@ -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>;
|
package/utils.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
export function select_item(itm: any): void;
|
|
2
|
+
export function activate_item(context_level: any, itm: any, operations?: null): void;
|
|
3
|
+
export function clear_active_item(context_level: any): void;
|
|
4
|
+
export function is_selected(itm: any): boolean;
|
|
5
|
+
export function is_active(context_level: any, itm: any): boolean;
|
|
6
|
+
export function editable(node: any, action: any): {
|
|
7
|
+
destroy(): void;
|
|
8
|
+
};
|
|
9
|
+
export function start_editing(element: any, finish_callback: any): void;
|
|
10
|
+
export function selectable(node: any, itm: any): {
|
|
11
|
+
destroy(): void;
|
|
12
|
+
};
|
|
13
|
+
export function handle_select(e: any): void;
|
|
1
14
|
export function parse_width_directive(c: any): string;
|
|
2
15
|
export function should_be_comapact(): boolean;
|
|
3
16
|
export namespace icons {
|
package/utils.js
CHANGED
|
@@ -1,7 +1,219 @@
|
|
|
1
|
-
import { getContext } from "svelte";
|
|
1
|
+
import { getContext, tick } from "svelte";
|
|
2
|
+
import {get} from 'svelte/store'
|
|
3
|
+
import { context_items_store, context_toolbar_operations } from "./stores";
|
|
2
4
|
|
|
3
5
|
export let icons = {symbols :null}
|
|
4
6
|
|
|
7
|
+
export function select_item(itm)
|
|
8
|
+
{
|
|
9
|
+
let data_context = get(context_items_store);
|
|
10
|
+
data_context['sel'] = itm;
|
|
11
|
+
data_context.focused = 'sel';
|
|
12
|
+
context_items_store.set( {...data_context} )
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function activate_item(context_level, itm, operations=null)
|
|
16
|
+
{
|
|
17
|
+
let data_context = get(context_items_store);
|
|
18
|
+
data_context['sel'] = itm; //null;
|
|
19
|
+
data_context[context_level] = itm;
|
|
20
|
+
data_context.focused = context_level;
|
|
21
|
+
context_items_store.set( {...data_context} )
|
|
22
|
+
|
|
23
|
+
if(operations && Array.isArray(operations))
|
|
24
|
+
context_toolbar_operations.set( [...operations] )
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function clear_active_item(context_level)
|
|
28
|
+
{
|
|
29
|
+
let data_context = get(context_items_store);
|
|
30
|
+
data_context[context_level] = null;
|
|
31
|
+
data_context.focused = context_level;
|
|
32
|
+
context_items_store.set( {...data_context} )
|
|
33
|
+
|
|
34
|
+
context_toolbar_operations.set( [] )
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function is_selected(itm)
|
|
38
|
+
{
|
|
39
|
+
let data_context = get(context_items_store);
|
|
40
|
+
if(!!data_context && !!data_context['sel'] && data_context['sel'] == itm)
|
|
41
|
+
return true;
|
|
42
|
+
else
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
export function is_active(context_level, itm)
|
|
48
|
+
{
|
|
49
|
+
let data_context = get(context_items_store);
|
|
50
|
+
if(data_context != undefined && data_context[context_level] != undefined && data_context[context_level] == itm)
|
|
51
|
+
return true;
|
|
52
|
+
else
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export function editable(node, action)
|
|
58
|
+
{
|
|
59
|
+
const org_text = node.textContent;
|
|
60
|
+
const blur_listener = async (e) =>
|
|
61
|
+
{
|
|
62
|
+
await finish_editing(true);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const key_listener = async (e) =>
|
|
66
|
+
{
|
|
67
|
+
switch(e.key)
|
|
68
|
+
{
|
|
69
|
+
case 'Esc':
|
|
70
|
+
case 'Escape':
|
|
71
|
+
await finish_editing(true);
|
|
72
|
+
e.stopPropagation();
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
case 'Enter':
|
|
77
|
+
await finish_editing(false);
|
|
78
|
+
e.stopPropagation();
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const finish_editing = async (cancel) =>
|
|
85
|
+
{
|
|
86
|
+
node.removeEventListener("blur", blur_listener);
|
|
87
|
+
node.removeEventListener("keydown", key_listener);
|
|
88
|
+
node.contentEditable = "false"
|
|
89
|
+
|
|
90
|
+
let sel = window.getSelection();
|
|
91
|
+
sel.removeAllRanges();
|
|
92
|
+
|
|
93
|
+
if(cancel)
|
|
94
|
+
{
|
|
95
|
+
node.innerHTML = org_text;
|
|
96
|
+
}
|
|
97
|
+
else if(action)
|
|
98
|
+
{
|
|
99
|
+
await action(node.textContent)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
node.dispatchEvent(new Event("finish"))
|
|
103
|
+
node.removeEventListener("finish", (e) => {});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const edit_listener = async (e) =>
|
|
107
|
+
{
|
|
108
|
+
//console.log('Edit event fired:', itm, "node", node)
|
|
109
|
+
node.contentEditable = "true"
|
|
110
|
+
node.addEventListener("blur", blur_listener);
|
|
111
|
+
node.addEventListener("keydown", key_listener);
|
|
112
|
+
|
|
113
|
+
node.focus();
|
|
114
|
+
|
|
115
|
+
await tick();
|
|
116
|
+
let range = document.createRange();
|
|
117
|
+
range.selectNodeContents(node);
|
|
118
|
+
let sel = window.getSelection();
|
|
119
|
+
sel.removeAllRanges();
|
|
120
|
+
sel.addRange(range);
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
node.addEventListener("edit", edit_listener);
|
|
125
|
+
node.classList.add("editable")
|
|
126
|
+
node.classList.add("focus:outline-none")
|
|
127
|
+
return {
|
|
128
|
+
destroy() {
|
|
129
|
+
node.removeEventListener("edit", edit_listener)
|
|
130
|
+
node.classList.remove("editable")
|
|
131
|
+
node.contentEditable = "false"
|
|
132
|
+
}};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function start_editing(element, finish_callback)
|
|
136
|
+
{
|
|
137
|
+
let editable_node = null;
|
|
138
|
+
|
|
139
|
+
if(element.classList.contains("editable"))
|
|
140
|
+
editable_node = element;
|
|
141
|
+
else
|
|
142
|
+
{
|
|
143
|
+
let editables = element.getElementsByClassName("editable");
|
|
144
|
+
if(editables && editables.length > 0)
|
|
145
|
+
editable_node = editables[0];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if(editable_node)
|
|
149
|
+
{
|
|
150
|
+
if(editable_node.contentEditable == "true")
|
|
151
|
+
return;
|
|
152
|
+
|
|
153
|
+
if(finish_callback)
|
|
154
|
+
{
|
|
155
|
+
editable_node.addEventListener("finish", (e) => {finish_callback()})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const edit_event = new Event("edit")
|
|
159
|
+
editable_node.dispatchEvent(edit_event)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function selectable(node, itm)
|
|
164
|
+
{
|
|
165
|
+
const select_listener = (e) =>
|
|
166
|
+
{
|
|
167
|
+
select_item(itm);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
node.setAttribute("selectable", "true")
|
|
171
|
+
node.addEventListener("select", select_listener);
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
destroy() {
|
|
175
|
+
node.removeEventListener("select", select_listener)
|
|
176
|
+
try{
|
|
177
|
+
node.removeAttribute("selectable")
|
|
178
|
+
}
|
|
179
|
+
catch(err)
|
|
180
|
+
{
|
|
181
|
+
console.error(err);
|
|
182
|
+
console.log(node);
|
|
183
|
+
}
|
|
184
|
+
}};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function handle_select(e)
|
|
188
|
+
{
|
|
189
|
+
let node = e.target;
|
|
190
|
+
if(!node)
|
|
191
|
+
{
|
|
192
|
+
select_item(null);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let selection_node = null;
|
|
197
|
+
|
|
198
|
+
while(!!node)
|
|
199
|
+
{
|
|
200
|
+
if(node.hasAttribute("selectable"))
|
|
201
|
+
{
|
|
202
|
+
selection_node = node;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
node = node.parentElement;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if(selection_node)
|
|
210
|
+
selection_node.dispatchEvent(new Event("select"))
|
|
211
|
+
else
|
|
212
|
+
select_item(null);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
5
217
|
export function parse_width_directive(c)
|
|
6
218
|
{
|
|
7
219
|
let cs = '';
|