@humandialog/forms.svelte 0.3.3 → 0.3.4
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/button.svelte +80 -0
- package/components/button.svelte.d.ts +24 -0
- package/components/checkbox.svelte +55 -0
- package/components/checkbox.svelte.d.ts +25 -0
- package/components/combo/combo.d.ts +15 -0
- package/components/combo/combo.item.svelte +14 -0
- package/components/combo/combo.item.svelte.d.ts +19 -0
- package/components/combo/combo.js +15 -0
- package/components/combo/combo.source.svelte +13 -0
- package/components/combo/combo.source.svelte.d.ts +20 -0
- package/components/combo/combo.svelte +527 -0
- package/components/combo/combo.svelte.d.ts +28 -0
- package/components/date.svelte +113 -0
- package/components/date.svelte.d.ts +23 -0
- package/components/document/internal/Document_command.d.ts +9 -0
- package/components/document/internal/Document_command.js +9 -0
- package/components/document/internal/Selection_helper.d.ts +7 -0
- package/components/document/internal/Selection_helper.js +133 -0
- package/components/document/internal/Selection_range.d.ts +26 -0
- package/components/document/internal/Selection_range.js +58 -0
- package/components/document/internal/palette.row.svelte +34 -0
- package/components/document/internal/palette.row.svelte.d.ts +36 -0
- package/components/document/internal/palette.svelte +123 -0
- package/components/document/internal/palette.svelte.d.ts +67 -0
- package/components/document/rich.edit.svelte +733 -0
- package/components/document/rich.edit.svelte.d.ts +23 -0
- package/components/edit.field.svelte +134 -0
- package/components/edit.field.svelte.d.ts +27 -0
- package/components/file.loader.svelte +90 -0
- package/components/file.loader.svelte.d.ts +25 -0
- package/components/input.text.svelte +37 -0
- package/components/input.text.svelte.d.ts +29 -0
- package/components/inputbox.ltop.svelte +110 -0
- package/components/inputbox.ltop.svelte.d.ts +44 -0
- package/components/radio.svelte +53 -0
- package/components/radio.svelte.d.ts +25 -0
- package/components/simple.table.svelte +106 -0
- package/components/simple.table.svelte.d.ts +41 -0
- package/components/table/_template.table.svelte +111 -0
- package/components/table/_template.table.svelte.d.ts +57 -0
- package/components/table/column.svelte +17 -0
- package/components/table/column.svelte.d.ts +19 -0
- package/components/table/item.svelte +10 -0
- package/components/table/item.svelte.d.ts +17 -0
- package/components/table/table.d.ts +11 -0
- package/components/table/table.js +11 -0
- package/components/table/table.svelte +150 -0
- package/components/table/table.svelte.d.ts +73 -0
- package/components/textarea.ltop.svelte +55 -0
- package/components/textarea.ltop.svelte.d.ts +35 -0
- package/components/tile.title.svelte +54 -0
- package/components/tile.title.svelte.d.ts +29 -0
- package/form.box.svelte +60 -0
- package/form.box.svelte.d.ts +35 -0
- package/global.d.ts +1 -0
- package/icon.svelte +105 -0
- package/icon.svelte.d.ts +62 -0
- package/index.d.ts +21 -0
- package/index.js +25 -0
- package/package.json +42 -48
- package/page.row.svelte +31 -0
- package/page.row.svelte.d.ts +31 -0
- package/page.svelte +83 -0
- package/page.svelte.d.ts +39 -0
- package/stores.d.ts +15 -0
- package/stores.js +7 -0
- package/tile.svelte +41 -0
- package/tile.svelte.d.ts +33 -0
- package/tiles.row.svelte +35 -0
- package/tiles.row.svelte.d.ts +31 -0
- package/tiles.vertical.row.svelte +25 -0
- package/tiles.vertical.row.svelte.d.ts +29 -0
- package/updates.d.ts +3 -0
- package/updates.js +95 -0
- package/utils.d.ts +5 -0
- package/utils.js +51 -0
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
<script>import { data_tick_store, context_items_store, context_types_store } from "../../stores.js";
|
|
2
|
+
import { inform_modification, push_changes } from "../../updates.js";
|
|
3
|
+
import { parse_width_directive, should_be_comapact } from "../../utils.js";
|
|
4
|
+
import { afterUpdate, getContext, setContext } from "svelte";
|
|
5
|
+
import { rCombo_definition, rCombo_item, cached_sources } from "./combo";
|
|
6
|
+
import FaChevronDown from "svelte-icons/fa/FaChevronDown.svelte";
|
|
7
|
+
import Icon from "../../icon.svelte";
|
|
8
|
+
import { Auth } from "@humandialog/auth.svelte/dist/index.js";
|
|
9
|
+
export let label = "";
|
|
10
|
+
export let self = null;
|
|
11
|
+
export let a = "";
|
|
12
|
+
export let context = "";
|
|
13
|
+
export let typename = "";
|
|
14
|
+
export let choice_callback = "";
|
|
15
|
+
export let on_select = void 0;
|
|
16
|
+
export let icon = false;
|
|
17
|
+
export let placeholder = "Choose wisely...";
|
|
18
|
+
export let s = "sm";
|
|
19
|
+
export let c = "";
|
|
20
|
+
let is_table_component = getContext("rIs-table-component");
|
|
21
|
+
let definition = new rCombo_definition();
|
|
22
|
+
setContext("rCombo-definition", definition);
|
|
23
|
+
let is_dropdown_open = false;
|
|
24
|
+
let dropdown_position = "";
|
|
25
|
+
let combo;
|
|
26
|
+
let textbox;
|
|
27
|
+
let dropdown_height;
|
|
28
|
+
let filtered_source = null;
|
|
29
|
+
let mutation_observer = null;
|
|
30
|
+
let highlighted_option = null;
|
|
31
|
+
let item = null;
|
|
32
|
+
let label_mb = "mb-1";
|
|
33
|
+
let input_pt = "pt-0.5";
|
|
34
|
+
let input_pb = "pb-1";
|
|
35
|
+
switch (s) {
|
|
36
|
+
case "md":
|
|
37
|
+
label_mb = "mb-2";
|
|
38
|
+
input_pt = "pt-2.5";
|
|
39
|
+
input_pb = "pb-2.5";
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
let appearance_class;
|
|
43
|
+
if (is_table_component)
|
|
44
|
+
appearance_class = ` text-gray-900 text-sm
|
|
45
|
+
focus:ring-primary-600 block w-full ${input_pb} ${input_pt} px-2.5 dark:bg-gray-700
|
|
46
|
+
dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500`;
|
|
47
|
+
else
|
|
48
|
+
appearance_class = ` bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg
|
|
49
|
+
focus:ring-primary-600 focus:border-primary-600 block w-full ${input_pb} ${input_pt} px-2.5 dark:bg-gray-700
|
|
50
|
+
dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500`;
|
|
51
|
+
let cs = c ? parse_width_directive(c) : "col-span-1";
|
|
52
|
+
let ctx = context ? context : getContext("ctx");
|
|
53
|
+
let can_be_activated = true;
|
|
54
|
+
let last_tick = -1;
|
|
55
|
+
$:
|
|
56
|
+
setup($data_tick_store);
|
|
57
|
+
function setup(...args) {
|
|
58
|
+
if ($data_tick_store <= last_tick)
|
|
59
|
+
return;
|
|
60
|
+
last_tick = $data_tick_store;
|
|
61
|
+
item = self ?? $context_items_store[ctx];
|
|
62
|
+
if (!typename)
|
|
63
|
+
typename = $context_types_store[ctx];
|
|
64
|
+
if (!label)
|
|
65
|
+
label = a;
|
|
66
|
+
tick_request_internal = tick_request_internal + 1;
|
|
67
|
+
if (is_table_component) {
|
|
68
|
+
if ($context_items_store["sel"] != self)
|
|
69
|
+
can_be_activated = false;
|
|
70
|
+
else
|
|
71
|
+
can_be_activated = true;
|
|
72
|
+
} else
|
|
73
|
+
can_be_activated = true;
|
|
74
|
+
}
|
|
75
|
+
afterUpdate(() => {
|
|
76
|
+
if (is_dropdown_open && textbox && document.activeElement != textbox)
|
|
77
|
+
textbox.focus();
|
|
78
|
+
});
|
|
79
|
+
function toggle() {
|
|
80
|
+
if (is_dropdown_open)
|
|
81
|
+
hide();
|
|
82
|
+
else
|
|
83
|
+
show();
|
|
84
|
+
}
|
|
85
|
+
function dropdown_action(node) {
|
|
86
|
+
if (is_dropdown_open)
|
|
87
|
+
dropdown_height = node.getBoundingClientRect().height;
|
|
88
|
+
return {
|
|
89
|
+
update() {
|
|
90
|
+
if (is_dropdown_open)
|
|
91
|
+
dropdown_height = node.getBoundingClientRect().height;
|
|
92
|
+
},
|
|
93
|
+
destroy() {
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function show() {
|
|
98
|
+
if (!can_be_activated)
|
|
99
|
+
return;
|
|
100
|
+
if (!combo)
|
|
101
|
+
return;
|
|
102
|
+
if (is_dropdown_open)
|
|
103
|
+
return;
|
|
104
|
+
let client_rect;
|
|
105
|
+
client_rect = new DOMRect();
|
|
106
|
+
client_rect.x = 0;
|
|
107
|
+
client_rect.y = 0;
|
|
108
|
+
client_rect.width = window.innerWidth;
|
|
109
|
+
client_rect.height = window.innerHeight;
|
|
110
|
+
let rect = combo.getBoundingClientRect();
|
|
111
|
+
let top_space = rect.y;
|
|
112
|
+
let bottom_space = client_rect.height - (rect.y + rect.height);
|
|
113
|
+
let palette_max_height_px = 500;
|
|
114
|
+
let palette_width_px = rect.width;
|
|
115
|
+
let preferred_palette_height = dropdown_height > 0 ? dropdown_height : palette_max_height_px;
|
|
116
|
+
let preferred_palette_width = palette_width_px;
|
|
117
|
+
let x = 0, y = 0;
|
|
118
|
+
let show_above = false;
|
|
119
|
+
let show_fullscreen = false;
|
|
120
|
+
if (client_rect.width < preferred_palette_width)
|
|
121
|
+
show_fullscreen = true;
|
|
122
|
+
else if (rect.x + preferred_palette_width > client_rect.width)
|
|
123
|
+
x = client_rect.width - preferred_palette_width;
|
|
124
|
+
else
|
|
125
|
+
x = rect.x;
|
|
126
|
+
if (client_rect.height < preferred_palette_height)
|
|
127
|
+
show_fullscreen = true;
|
|
128
|
+
else if (bottom_space >= preferred_palette_height)
|
|
129
|
+
y = rect.y + rect.height;
|
|
130
|
+
else if (top_space >= preferred_palette_height) {
|
|
131
|
+
y = rect.y;
|
|
132
|
+
show_above = true;
|
|
133
|
+
} else
|
|
134
|
+
show_fullscreen = true;
|
|
135
|
+
if (false) {
|
|
136
|
+
dropdown_position = `position: fixed; left: 0px; top: 0px; width: ${client_rect.width}px; height: ${client_rect.height}px;`;
|
|
137
|
+
} else {
|
|
138
|
+
dropdown_position = `width: ${rect.width}px; max-height:${palette_max_height_px}px; position: fixed; left:${x}px; top:${y}px;`;
|
|
139
|
+
if (show_above)
|
|
140
|
+
dropdown_position += " transform: translate(0, -100%);";
|
|
141
|
+
}
|
|
142
|
+
is_dropdown_open = true;
|
|
143
|
+
if (!textbox)
|
|
144
|
+
return;
|
|
145
|
+
textbox.innerHTML = "";
|
|
146
|
+
tick_request_internal = tick_request_internal + 1;
|
|
147
|
+
if (!mutation_observer)
|
|
148
|
+
mutation_observer = new MutationObserver(() => {
|
|
149
|
+
on_input_change();
|
|
150
|
+
});
|
|
151
|
+
mutation_observer.observe(textbox, {
|
|
152
|
+
childList: true,
|
|
153
|
+
attributes: true,
|
|
154
|
+
characterData: true,
|
|
155
|
+
subtree: true
|
|
156
|
+
});
|
|
157
|
+
if (definition.collection_expr)
|
|
158
|
+
fetch_source().then((source) => source_fetched(source));
|
|
159
|
+
else if (definition.on_collect) {
|
|
160
|
+
definition.on_collect().then((source) => source_fetched(source));
|
|
161
|
+
} else {
|
|
162
|
+
filtered_source = definition.source.map((e) => e);
|
|
163
|
+
highlighted_option = filtered_source.length > 0 ? filtered_source[0] : null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function hide() {
|
|
167
|
+
if (mutation_observer)
|
|
168
|
+
mutation_observer.disconnect();
|
|
169
|
+
is_dropdown_open = false;
|
|
170
|
+
combo_text = get_combo_text();
|
|
171
|
+
textbox.innerHtml = combo_text;
|
|
172
|
+
tick_request_internal = tick_request_internal + 1;
|
|
173
|
+
}
|
|
174
|
+
function selected_item(itm, a2) {
|
|
175
|
+
let choosed_value = itm[a2];
|
|
176
|
+
if (typeof choosed_value === "object") {
|
|
177
|
+
if (choosed_value) {
|
|
178
|
+
let itm2 = new rCombo_item();
|
|
179
|
+
if (definition.element_key)
|
|
180
|
+
itm2.Key = choosed_value[definition.element_key];
|
|
181
|
+
else
|
|
182
|
+
itm2.Key = choosed_value.$ref;
|
|
183
|
+
if (definition.element_name)
|
|
184
|
+
itm2.Name = choosed_value[definition.element_name];
|
|
185
|
+
else
|
|
186
|
+
itm2.Name = choosed_value.$display;
|
|
187
|
+
if (icon) {
|
|
188
|
+
if (definition.element_avatar)
|
|
189
|
+
itm2.Avatar = choosed_value[definition.element_avatar];
|
|
190
|
+
else
|
|
191
|
+
itm2.Avatar = choosed_value.$icon;
|
|
192
|
+
}
|
|
193
|
+
return itm2;
|
|
194
|
+
} else
|
|
195
|
+
return null;
|
|
196
|
+
} else {
|
|
197
|
+
let found = definition.source.find((e) => e.Key == choosed_value);
|
|
198
|
+
if (!found)
|
|
199
|
+
found = definition.source.find((e) => e.Name == choosed_value);
|
|
200
|
+
if (found)
|
|
201
|
+
return found;
|
|
202
|
+
else
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function get_combo_text() {
|
|
207
|
+
if (!is_dropdown_open) {
|
|
208
|
+
let found = selected_item(item, a);
|
|
209
|
+
if (found)
|
|
210
|
+
return found.Name ?? found.Key;
|
|
211
|
+
else
|
|
212
|
+
return !is_table_component ? placeholder : "";
|
|
213
|
+
} else
|
|
214
|
+
return textbox.innerHTML;
|
|
215
|
+
}
|
|
216
|
+
async function on_choose(itm) {
|
|
217
|
+
hide();
|
|
218
|
+
if (choice_callback) {
|
|
219
|
+
let body = {
|
|
220
|
+
choice: {
|
|
221
|
+
$ref: itm.Key
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
let path = `${typename}/${item.Id}/${choice_callback}`;
|
|
225
|
+
let fields = calc_path_fields_param();
|
|
226
|
+
if (fields)
|
|
227
|
+
path += fields;
|
|
228
|
+
let res = await Auth.fetch(
|
|
229
|
+
`json/yav1/${path}`,
|
|
230
|
+
{
|
|
231
|
+
method: "POST",
|
|
232
|
+
body: JSON.stringify(body)
|
|
233
|
+
}
|
|
234
|
+
);
|
|
235
|
+
if (res.ok) {
|
|
236
|
+
let result_item = await res.json();
|
|
237
|
+
let result_typename = Object.keys(result_item)[0];
|
|
238
|
+
item[a] = result_item[result_typename];
|
|
239
|
+
tick_request_internal = tick_request_internal + 1;
|
|
240
|
+
} else
|
|
241
|
+
console.error(res);
|
|
242
|
+
} else if (on_select) {
|
|
243
|
+
await on_select(item, itm.Key, itm.Name);
|
|
244
|
+
tick_request_internal = tick_request_internal + 1;
|
|
245
|
+
} else {
|
|
246
|
+
item[a] = itm.Key ?? itm.Name;
|
|
247
|
+
tick_request_internal = tick_request_internal + 1;
|
|
248
|
+
if (item && a && typename) {
|
|
249
|
+
inform_modification(item, a, typename);
|
|
250
|
+
push_changes();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function on_keydown(e) {
|
|
255
|
+
switch (e.key) {
|
|
256
|
+
case "Esc":
|
|
257
|
+
case "Escape":
|
|
258
|
+
hide();
|
|
259
|
+
break;
|
|
260
|
+
case "ArrowDown":
|
|
261
|
+
{
|
|
262
|
+
e.cancelBubble = true;
|
|
263
|
+
e.preventDefault();
|
|
264
|
+
const _filtered_source = filtered_source ? filtered_source : definition.source;
|
|
265
|
+
let idx = _filtered_source.findIndex((e2) => e2 == highlighted_option);
|
|
266
|
+
if (idx < 0)
|
|
267
|
+
idx = 0;
|
|
268
|
+
else if (idx < _filtered_source.length - 1)
|
|
269
|
+
idx++;
|
|
270
|
+
highlighted_option = _filtered_source[idx];
|
|
271
|
+
}
|
|
272
|
+
break;
|
|
273
|
+
case "ArrowUp":
|
|
274
|
+
{
|
|
275
|
+
e.cancelBubble = true;
|
|
276
|
+
e.preventDefault();
|
|
277
|
+
const _filtered_source = filtered_source ? filtered_source : definition.source;
|
|
278
|
+
let idx = _filtered_source.findIndex((e2) => e2 == highlighted_option);
|
|
279
|
+
if (idx < 0)
|
|
280
|
+
idx = _filtered_source.length - 1;
|
|
281
|
+
else if (idx > 0)
|
|
282
|
+
idx--;
|
|
283
|
+
highlighted_option = _filtered_source[idx];
|
|
284
|
+
}
|
|
285
|
+
break;
|
|
286
|
+
case "Enter":
|
|
287
|
+
{
|
|
288
|
+
e.cancelBubble = true;
|
|
289
|
+
e.preventDefault();
|
|
290
|
+
if (highlighted_option)
|
|
291
|
+
on_choose(highlighted_option);
|
|
292
|
+
}
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function on_input_change() {
|
|
297
|
+
if (!is_dropdown_open)
|
|
298
|
+
return;
|
|
299
|
+
filtered_source = get_filtered_source();
|
|
300
|
+
highlighted_option = filtered_source.length > 0 ? filtered_source[0] : null;
|
|
301
|
+
}
|
|
302
|
+
function get_filtered_source() {
|
|
303
|
+
if (!textbox)
|
|
304
|
+
return definition.source;
|
|
305
|
+
else if (textbox.innerHTML) {
|
|
306
|
+
return definition.source.filter((e) => {
|
|
307
|
+
return e.Name && e.Name.toLowerCase().includes(textbox.innerHTML.toLowerCase()) || e.Key && e.Key.toString().toLowerCase().includes(textbox.innerHTML.toLowerCase());
|
|
308
|
+
});
|
|
309
|
+
} else
|
|
310
|
+
return definition.source;
|
|
311
|
+
}
|
|
312
|
+
let sel_item = null;
|
|
313
|
+
let combo_text = placeholder;
|
|
314
|
+
let tick_request_internal = 0;
|
|
315
|
+
let last_tick_internal = -1;
|
|
316
|
+
function on_mouse_move(over) {
|
|
317
|
+
highlighted_option = over;
|
|
318
|
+
}
|
|
319
|
+
async function fetch_source() {
|
|
320
|
+
if (item.hasOwnProperty(definition.collection_expr)) {
|
|
321
|
+
let prop = item[definition.collection_expr];
|
|
322
|
+
if (!prop)
|
|
323
|
+
return null;
|
|
324
|
+
else if (Array.isArray(prop))
|
|
325
|
+
return prop;
|
|
326
|
+
else if (typeof prop === "object") {
|
|
327
|
+
if (!prop.$ref)
|
|
328
|
+
return null;
|
|
329
|
+
if (!prop.$col)
|
|
330
|
+
return null;
|
|
331
|
+
return await get_source_collection(prop.$ref, `${typename}_${definition.collection_expr}`);
|
|
332
|
+
} else
|
|
333
|
+
return null;
|
|
334
|
+
} else {
|
|
335
|
+
let path = `${typename}/${item.Id}/${definition.collection_expr}`;
|
|
336
|
+
return await get_source_collection(path, `${typename}_${definition.collection_expr}`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function calc_path_fields_param() {
|
|
340
|
+
let fields = "?fields=";
|
|
341
|
+
if (definition.element_key)
|
|
342
|
+
fields += definition.element_key;
|
|
343
|
+
else
|
|
344
|
+
fields += "$ref";
|
|
345
|
+
if (definition.element_name)
|
|
346
|
+
fields += "," + definition.element_name;
|
|
347
|
+
else
|
|
348
|
+
fields += ",$display";
|
|
349
|
+
if (icon) {
|
|
350
|
+
if (definition.element_avatar)
|
|
351
|
+
fields += "," + definition.element_avatar;
|
|
352
|
+
else
|
|
353
|
+
fields += ",$icon";
|
|
354
|
+
}
|
|
355
|
+
return fields;
|
|
356
|
+
}
|
|
357
|
+
async function get_source_collection(path, cache_key) {
|
|
358
|
+
if (!cached_sources.has(cache_key)) {
|
|
359
|
+
let promise2 = new Promise(async (resolve, fail) => {
|
|
360
|
+
try {
|
|
361
|
+
let fields = calc_path_fields_param();
|
|
362
|
+
if (fields)
|
|
363
|
+
path += fields;
|
|
364
|
+
let res = await Auth.fetch(`json/yav1/${path}`, {
|
|
365
|
+
method: "POST"
|
|
366
|
+
});
|
|
367
|
+
if (res.ok)
|
|
368
|
+
resolve(await res.json());
|
|
369
|
+
else
|
|
370
|
+
resolve(null);
|
|
371
|
+
} catch (err) {
|
|
372
|
+
console.error(err);
|
|
373
|
+
resolve(null);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
cached_sources.set(cache_key, promise2);
|
|
377
|
+
}
|
|
378
|
+
let promise = cached_sources.get(cache_key);
|
|
379
|
+
return await promise;
|
|
380
|
+
}
|
|
381
|
+
function source_fetched(source) {
|
|
382
|
+
if (!source)
|
|
383
|
+
return;
|
|
384
|
+
let array;
|
|
385
|
+
if (Array.isArray(source))
|
|
386
|
+
array = source;
|
|
387
|
+
else {
|
|
388
|
+
let type = Object.keys(source)[0];
|
|
389
|
+
array = source[type];
|
|
390
|
+
}
|
|
391
|
+
item[definition.collection_expr] = [...array];
|
|
392
|
+
definition.source = [];
|
|
393
|
+
array.forEach((e) => {
|
|
394
|
+
let el = new rCombo_item();
|
|
395
|
+
if (definition.element_name)
|
|
396
|
+
el.Name = e[definition.element_name];
|
|
397
|
+
else
|
|
398
|
+
el.Name = e.$display;
|
|
399
|
+
if (definition.element_key)
|
|
400
|
+
el.Key = e[definition.element_key];
|
|
401
|
+
else
|
|
402
|
+
el.Key = e.$ref;
|
|
403
|
+
if (icon) {
|
|
404
|
+
if (definition.element_avatar)
|
|
405
|
+
el.Avatar = e[definition.element_avatar];
|
|
406
|
+
else
|
|
407
|
+
el.Avatar = e.$icon;
|
|
408
|
+
}
|
|
409
|
+
definition.source.push(el);
|
|
410
|
+
});
|
|
411
|
+
filtered_source = definition.source.map((e) => e);
|
|
412
|
+
highlighted_option = filtered_source.length > 0 ? filtered_source[0] : null;
|
|
413
|
+
}
|
|
414
|
+
function setup_view(...args) {
|
|
415
|
+
if (tick_request_internal <= last_tick_internal)
|
|
416
|
+
return;
|
|
417
|
+
last_tick_internal = tick_request_internal;
|
|
418
|
+
sel_item = selected_item(item, a);
|
|
419
|
+
combo_text = get_combo_text();
|
|
420
|
+
if (textbox)
|
|
421
|
+
textbox.innerHTML = combo_text;
|
|
422
|
+
}
|
|
423
|
+
</script>
|
|
424
|
+
|
|
425
|
+
<slot/> <!-- definition slot first -->
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
{#if true}
|
|
429
|
+
{@const c = setup_view(item, a, tick_request_internal) }
|
|
430
|
+
|
|
431
|
+
<div class={cs}
|
|
432
|
+
on:focusout={(e) => setTimeout(() => {hide()}, 100)}>
|
|
433
|
+
{#if !is_table_component}
|
|
434
|
+
<label for="name" class="block {label_mb} text-xs font-small text-gray-900 dark:text-white">{label}</label>
|
|
435
|
+
{/if}
|
|
436
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
437
|
+
<div bind:this={combo}
|
|
438
|
+
on:click|preventDefault|stopPropagation={show}
|
|
439
|
+
class="{appearance_class} flex flex-row content-between items-center"
|
|
440
|
+
>
|
|
441
|
+
|
|
442
|
+
<div class="flex-1 flex flex-row items-center">
|
|
443
|
+
{#if !is_dropdown_open}
|
|
444
|
+
{#if icon && sel_item}
|
|
445
|
+
{#if sel_item.Color}
|
|
446
|
+
<Icon size={5} circle={true} color={sel_item.Color}/>
|
|
447
|
+
{:else}
|
|
448
|
+
<Icon size={5} circle={true} symbol={sel_item.Avatar} label={sel_item.Name}/>
|
|
449
|
+
{/if}
|
|
450
|
+
{/if}
|
|
451
|
+
{/if}
|
|
452
|
+
|
|
453
|
+
<p bind:this={textbox}
|
|
454
|
+
class="ml-2 dark:text-white"
|
|
455
|
+
class:text-gray-400={ (!is_dropdown_open) && (!sel_item)}
|
|
456
|
+
class:text-gray-700={ is_dropdown_open || sel_item }
|
|
457
|
+
contenteditable={is_dropdown_open}
|
|
458
|
+
on:keydown={on_keydown}>
|
|
459
|
+
{combo_text}</p>
|
|
460
|
+
</div>
|
|
461
|
+
|
|
462
|
+
{#if can_be_activated }
|
|
463
|
+
<Icon size={3} component={FaChevronDown} class="flex-none text-gray-700 dark:text-gray-200"/>
|
|
464
|
+
{/if}
|
|
465
|
+
</div>
|
|
466
|
+
|
|
467
|
+
<div hidden={!is_dropdown_open}
|
|
468
|
+
class="{cs} 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 overflow-y-auto cursor-pointer z-20"
|
|
469
|
+
style={dropdown_position}
|
|
470
|
+
use:dropdown_action>
|
|
471
|
+
<ul class="py-1">
|
|
472
|
+
<!-- {#if is_dropdown_open && definition.collection_expr}
|
|
473
|
+
{#await fetch_source()}
|
|
474
|
+
<p>Loading...</p>
|
|
475
|
+
{:then source}
|
|
476
|
+
{@const c = source_fetched(source)}
|
|
477
|
+
{/await}
|
|
478
|
+
{/if} -->
|
|
479
|
+
|
|
480
|
+
{#if definition.source && definition.source.length}
|
|
481
|
+
{@const _filtered_source = filtered_source ? filtered_source : definition.source}
|
|
482
|
+
{#if _filtered_source.length > 0}
|
|
483
|
+
{#each _filtered_source as item (item.Key)}
|
|
484
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
485
|
+
<li class="rounded p-2 flex flex-row items-center"
|
|
486
|
+
class:bg-gray-100={highlighted_option == item}
|
|
487
|
+
class:dark:bg-gray-700={highlighted_option == item}
|
|
488
|
+
class:dark:hover:bg-gray-700={highlighted_option == item}
|
|
489
|
+
on:mousemove={() => on_mouse_move(item)}
|
|
490
|
+
on:click|preventDefault|stopPropagation={async () => await on_choose(item)}>
|
|
491
|
+
|
|
492
|
+
{#if icon}
|
|
493
|
+
{#if item.Color}
|
|
494
|
+
<Icon size={5} circle={true} color={item.Color}/>
|
|
495
|
+
{:else if item.Avatar}
|
|
496
|
+
<Icon size={5} circle={true} symbol={item.Avatar}/>
|
|
497
|
+
{:else if item.Name}
|
|
498
|
+
<Icon size={5} circle={true} label={item.Name}/>
|
|
499
|
+
{:else}
|
|
500
|
+
<Icon size={5} circle={true}/>
|
|
501
|
+
{/if}
|
|
502
|
+
{/if}
|
|
503
|
+
<div class="ml-2">
|
|
504
|
+
{#if item.Name}
|
|
505
|
+
{item.Name}
|
|
506
|
+
{:else if item.Key}
|
|
507
|
+
{item.Key}
|
|
508
|
+
{/if}
|
|
509
|
+
</div>
|
|
510
|
+
</li>
|
|
511
|
+
{/each}
|
|
512
|
+
{:else}
|
|
513
|
+
<li class="rounded p-2">No options</li>
|
|
514
|
+
{/if}
|
|
515
|
+
{/if}
|
|
516
|
+
</ul>
|
|
517
|
+
</div>
|
|
518
|
+
</div>
|
|
519
|
+
{/if}
|
|
520
|
+
|
|
521
|
+
<style>
|
|
522
|
+
|
|
523
|
+
[contenteditable]:focus {
|
|
524
|
+
outline: 0px solid transparent;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
</style>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
label?: string | undefined;
|
|
5
|
+
self?: null | undefined;
|
|
6
|
+
a?: string | undefined;
|
|
7
|
+
context?: string | undefined;
|
|
8
|
+
typename?: string | undefined;
|
|
9
|
+
choice_callback?: string | undefined;
|
|
10
|
+
on_select?: undefined;
|
|
11
|
+
icon?: boolean | undefined;
|
|
12
|
+
placeholder?: string | undefined;
|
|
13
|
+
s?: string | undefined;
|
|
14
|
+
c?: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
events: {
|
|
17
|
+
[evt: string]: CustomEvent<any>;
|
|
18
|
+
};
|
|
19
|
+
slots: {
|
|
20
|
+
default: {};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export type ComboProps = typeof __propDef.props;
|
|
24
|
+
export type ComboEvents = typeof __propDef.events;
|
|
25
|
+
export type ComboSlots = typeof __propDef.slots;
|
|
26
|
+
export default class Combo extends SvelteComponentTyped<ComboProps, ComboEvents, ComboSlots> {
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<script>import { getContext } from "svelte";
|
|
2
|
+
import { data_tick_store, context_items_store, context_types_store } from "../stores.js";
|
|
3
|
+
import { inform_modification, push_changes } from "../updates.js";
|
|
4
|
+
import { parse_width_directive } from "../utils.js";
|
|
5
|
+
export let self = null;
|
|
6
|
+
export let a = "";
|
|
7
|
+
export let context = "";
|
|
8
|
+
export let typename = "";
|
|
9
|
+
export let date = null;
|
|
10
|
+
export let s = "sm";
|
|
11
|
+
export let c = "";
|
|
12
|
+
let is_table_component = getContext("rIs-table-component");
|
|
13
|
+
let input_pt = "pt-0.5";
|
|
14
|
+
let input_pb = "pb-1";
|
|
15
|
+
switch (s) {
|
|
16
|
+
case "md":
|
|
17
|
+
input_pt = "pt-2.5";
|
|
18
|
+
input_pb = "pb-2.5";
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
let item = null;
|
|
22
|
+
let additional_class = $$restProps.class ?? "";
|
|
23
|
+
let value = null;
|
|
24
|
+
let rValue = "";
|
|
25
|
+
let ctx = context ? context : getContext("ctx");
|
|
26
|
+
let cs = parse_width_directive(c);
|
|
27
|
+
let style;
|
|
28
|
+
if (!is_table_component) {
|
|
29
|
+
style = `bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg
|
|
30
|
+
focus:ring-primary-600 focus:border-primary-600 block w-full ${input_pb} ${input_pt} px-2.5 dark:bg-gray-700
|
|
31
|
+
dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500`;
|
|
32
|
+
} else {
|
|
33
|
+
style = `bg-transparent text-sm block w-full ${input_pb} ${input_pt} px-2.5`;
|
|
34
|
+
}
|
|
35
|
+
let can_be_activated = true;
|
|
36
|
+
let last_tick = -1;
|
|
37
|
+
$:
|
|
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;
|
|
43
|
+
if (!date) {
|
|
44
|
+
item = self ?? $context_items_store[ctx];
|
|
45
|
+
if (!typename)
|
|
46
|
+
typename = $context_types_store[ctx];
|
|
47
|
+
if (!item[a])
|
|
48
|
+
value = null;
|
|
49
|
+
else
|
|
50
|
+
value = new Date(item[a]);
|
|
51
|
+
} else
|
|
52
|
+
value = date;
|
|
53
|
+
if (is_table_component) {
|
|
54
|
+
if ($context_items_store["sel"] != self)
|
|
55
|
+
can_be_activated = false;
|
|
56
|
+
else
|
|
57
|
+
can_be_activated = true;
|
|
58
|
+
} else
|
|
59
|
+
can_be_activated = true;
|
|
60
|
+
rValue = get_formatted_date(value);
|
|
61
|
+
}
|
|
62
|
+
function get_formatted_date(d) {
|
|
63
|
+
if (!d)
|
|
64
|
+
return "";
|
|
65
|
+
let month = "" + (d.getMonth() + 1);
|
|
66
|
+
let day = "" + d.getDate();
|
|
67
|
+
let year = d.getFullYear();
|
|
68
|
+
let hour = "" + d.getHours();
|
|
69
|
+
let minutes = "" + d.getMinutes();
|
|
70
|
+
if (day.length < 2)
|
|
71
|
+
day = "0" + day;
|
|
72
|
+
if (month.length < 2)
|
|
73
|
+
month = "0" + month;
|
|
74
|
+
if (hour.length < 2)
|
|
75
|
+
hour = "0" + hour;
|
|
76
|
+
if (minutes.length < 2)
|
|
77
|
+
minutes = "0" + minutes;
|
|
78
|
+
return `${year}-${month}-${day} ${hour}:${minutes}`;
|
|
79
|
+
}
|
|
80
|
+
function on_changed() {
|
|
81
|
+
if (!rValue)
|
|
82
|
+
value = null;
|
|
83
|
+
else
|
|
84
|
+
value = new Date(rValue);
|
|
85
|
+
if (item != null) {
|
|
86
|
+
if (value)
|
|
87
|
+
item[a] = value.toISOString();
|
|
88
|
+
else
|
|
89
|
+
item[a] = null;
|
|
90
|
+
if (typename) {
|
|
91
|
+
inform_modification(item, a, typename);
|
|
92
|
+
$data_tick_store = $data_tick_store + 1;
|
|
93
|
+
push_changes();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
{#if !can_be_activated}
|
|
100
|
+
<span class="{style} ml-0.5 h-7" >{rValue}</span>
|
|
101
|
+
{:else}
|
|
102
|
+
<input class=" {cs} {style} {additional_class}"
|
|
103
|
+
type="datetime-local"
|
|
104
|
+
on:change={on_changed}
|
|
105
|
+
bind:value={rValue}/>
|
|
106
|
+
{/if}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
<style>
|
|
110
|
+
input:focus {
|
|
111
|
+
outline: 0px solid transparent;
|
|
112
|
+
}
|
|
113
|
+
</style>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
self?: null | undefined;
|
|
6
|
+
a?: string | undefined;
|
|
7
|
+
context?: string | undefined;
|
|
8
|
+
typename?: string | undefined;
|
|
9
|
+
date?: Date | undefined;
|
|
10
|
+
s?: string | undefined;
|
|
11
|
+
c?: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
[evt: string]: CustomEvent<any>;
|
|
15
|
+
};
|
|
16
|
+
slots: {};
|
|
17
|
+
};
|
|
18
|
+
export type DateProps = typeof __propDef.props;
|
|
19
|
+
export type DateEvents = typeof __propDef.events;
|
|
20
|
+
export type DateSlots = typeof __propDef.slots;
|
|
21
|
+
export default class Date extends SvelteComponentTyped<DateProps, DateEvents, DateSlots> {
|
|
22
|
+
}
|
|
23
|
+
export {};
|