@stubber/form-fields 1.6.0 → 1.6.2
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/dist/fields2/Form.svelte +3 -3
- package/dist/fields2/Form.svelte.d.ts +3 -2
- package/dist/fields2/sub/contact-selector-field.svelte +44 -46
- package/dist/fields2/sub/contact-selector-field.svelte.d.ts +2 -3
- package/dist/fields2/sub/field-builder-field.svelte +1 -0
- package/dist/fields2/sub/select-field.svelte +6 -6
- package/dist/fields2/sub/select-field.svelte.d.ts +1 -1
- package/dist/fields2/sub/selectresource-field.svelte +1 -4
- package/package.json +1 -1
package/dist/fields2/Form.svelte
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
<script>import { get as getStoreValue } from "svelte/store";
|
|
1
|
+
<script>import { get as getStoreValue, writable } from "svelte/store";
|
|
2
2
|
import FormField from "./form-field.svelte";
|
|
3
3
|
import { build_fields } from "./utils";
|
|
4
4
|
import { validate_field } from "./validations/validate_field";
|
|
5
5
|
export let initial_form;
|
|
6
6
|
export let form;
|
|
7
|
-
export let attachments;
|
|
7
|
+
export let attachments = writable([]);
|
|
8
8
|
export let dependencies = void 0;
|
|
9
|
-
export let form_valid;
|
|
9
|
+
export let form_valid = false;
|
|
10
10
|
if (initial_form.data) {
|
|
11
11
|
form.update((data) => {
|
|
12
12
|
return { ...data, ...initial_form.data };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
import { type Writable } from "svelte/store";
|
|
3
3
|
import type { IFormDependencies, IInitialForm } from "./interfaces";
|
|
4
|
+
import type { UploadedFile } from "./fileserver";
|
|
4
5
|
declare const __propDef: {
|
|
5
6
|
props: {
|
|
6
7
|
initial_form: IInitialForm;
|
|
7
8
|
form: Writable<any>;
|
|
8
|
-
attachments
|
|
9
|
+
attachments?: Writable<UploadedFile[]>;
|
|
9
10
|
dependencies?: IFormDependencies | undefined;
|
|
10
|
-
form_valid
|
|
11
|
+
form_valid?: boolean;
|
|
11
12
|
};
|
|
12
13
|
events: {
|
|
13
14
|
[evt: string]: CustomEvent<any>;
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
<script>import { Button } from "@stubber/ui/button";
|
|
18
|
-
import SelectField, {
|
|
18
|
+
import SelectField, {
|
|
19
|
+
} from "./select-field.svelte";
|
|
19
20
|
export let fieldStore;
|
|
20
21
|
const params = $fieldStore.params || {};
|
|
21
22
|
const dependencies = $fieldStore.formDependencies;
|
|
@@ -25,54 +26,51 @@ const show_create_contact_modal = () => {
|
|
|
25
26
|
const orguuid = dependencies?.stubber?.orguuid;
|
|
26
27
|
createWantToModal("_create_new_contact", stubref, orguuid);
|
|
27
28
|
};
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const details = {
|
|
39
|
-
resource_name: "contacts"
|
|
40
|
-
};
|
|
41
|
-
details.params = $fieldStore.params || {};
|
|
42
|
-
details.params.orguuid = orguuid;
|
|
43
|
-
details.params.stubref = stubref;
|
|
44
|
-
details.params.input = search_term;
|
|
45
|
-
if (details.params.limit === void 0) {
|
|
46
|
-
details.params.limit = 50;
|
|
47
|
-
}
|
|
48
|
-
console.log("Loading contacts with details:", details);
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
socket.emit("request", { type: "resource", details }, (res) => {
|
|
51
|
-
if (res.success) {
|
|
52
|
-
console.log("Contacts loaded:", res);
|
|
53
|
-
const contacts = res.payload?.contacts || [];
|
|
54
|
-
const result = contacts.map((contact) => {
|
|
55
|
-
let label = contact._default_label;
|
|
56
|
-
if (params.label && contact[params.label]) {
|
|
57
|
-
label = contact[params.label];
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
value: contact,
|
|
61
|
-
label
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
resolve(result);
|
|
65
|
-
} else {
|
|
66
|
-
console.error("Failed to load contacts:", res);
|
|
67
|
-
resolve([]);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
29
|
+
const load_options = async (search_term) => {
|
|
30
|
+
const socket = dependencies?.clienthub?.socket;
|
|
31
|
+
const orguuid = dependencies?.stubber?.orguuid;
|
|
32
|
+
const stubref = dependencies?.stubber?.stubref;
|
|
33
|
+
if (!socket || !orguuid || !stubref) {
|
|
34
|
+
console.error("ClientHub socket or stubber details not available.");
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
const details = {
|
|
38
|
+
resource_name: "contacts"
|
|
71
39
|
};
|
|
72
|
-
}
|
|
40
|
+
details.params = $fieldStore.params || {};
|
|
41
|
+
details.params.orguuid = orguuid;
|
|
42
|
+
details.params.stubref = stubref;
|
|
43
|
+
details.params.input = search_term;
|
|
44
|
+
if (details.params.limit === void 0) {
|
|
45
|
+
details.params.limit = 50;
|
|
46
|
+
}
|
|
47
|
+
console.log("Loading contacts with details:", details);
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
socket.emit("request", { type: "resource", details }, (res) => {
|
|
50
|
+
if (res.success) {
|
|
51
|
+
console.log("Contacts loaded:", res);
|
|
52
|
+
const contacts = res.payload?.contacts || [];
|
|
53
|
+
const result = contacts.map((contact) => {
|
|
54
|
+
let label = contact._default_label;
|
|
55
|
+
if (params.label && contact[params.label]) {
|
|
56
|
+
label = contact[params.label];
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
value: contact,
|
|
60
|
+
label
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
resolve(result);
|
|
64
|
+
} else {
|
|
65
|
+
console.error("Failed to load contacts:", res);
|
|
66
|
+
resolve([]);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
73
71
|
</script>
|
|
74
72
|
|
|
75
|
-
<SelectField {fieldStore}>
|
|
73
|
+
<SelectField {fieldStore} {load_options}>
|
|
76
74
|
<Button
|
|
77
75
|
on:click={show_create_contact_modal}
|
|
78
76
|
variant="ghost"
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
import type { Writable } from "svelte/store";
|
|
3
3
|
import type { IBaseField, IBuiltField, IInitialForm } from "../interfaces";
|
|
4
|
-
export interface IContactSelectorFieldParams {
|
|
4
|
+
export interface IContactSelectorFieldParams extends ISelectFieldParams {
|
|
5
5
|
label?: string;
|
|
6
6
|
limit?: number;
|
|
7
|
-
load_options?: (search_term: string) => Promise<ISelectFieldOption[]>;
|
|
8
7
|
}
|
|
9
8
|
export declare const contact_selector_field_param_spec: IInitialForm;
|
|
10
9
|
export interface IContactSelectorField extends IBaseField<IContactSelectorFieldParams> {
|
|
11
10
|
fieldtype: "contactselector";
|
|
12
11
|
}
|
|
13
|
-
import { type
|
|
12
|
+
import { type ISelectFieldParams } from "./select-field.svelte";
|
|
14
13
|
declare const __propDef: {
|
|
15
14
|
props: {
|
|
16
15
|
fieldStore: Writable<IBuiltField<IContactSelectorFieldParams>>;
|
|
@@ -311,6 +311,7 @@ function select_field_type(newValue, trigger) {
|
|
|
311
311
|
</Collapsible.Trigger>
|
|
312
312
|
|
|
313
313
|
<Collapsible.Content class="flex flex-col gap-y-2 pl-2 pt-2">
|
|
314
|
+
<!-- todo this doesnt update when fieldtype changes -->
|
|
314
315
|
{@const field_param_spec = field_params_spec_lookup[value.fieldtype ?? "unknown"]}
|
|
315
316
|
{#if field_param_spec}
|
|
316
317
|
<Form
|
|
@@ -33,6 +33,7 @@ import FieldLabel from "../FieldLabel.svelte";
|
|
|
33
33
|
import FieldMessage from "../FieldMessage.svelte";
|
|
34
34
|
import { set_value_details } from "../utils";
|
|
35
35
|
export let fieldStore;
|
|
36
|
+
export let load_options = void 0;
|
|
36
37
|
let open = false;
|
|
37
38
|
let loading = false;
|
|
38
39
|
let items = [];
|
|
@@ -70,19 +71,18 @@ function closeAndFocusTrigger(triggerId) {
|
|
|
70
71
|
let last_search = void 0;
|
|
71
72
|
const handle_search = async (search) => {
|
|
72
73
|
last_search = search;
|
|
73
|
-
if (
|
|
74
|
+
if (load_options) {
|
|
74
75
|
loading = true;
|
|
75
|
-
const remote_results = await
|
|
76
|
+
const remote_results = await load_options($state.search);
|
|
76
77
|
loading = false;
|
|
77
78
|
items = map_field_options(remote_results);
|
|
78
79
|
}
|
|
79
80
|
};
|
|
80
81
|
let debounced_handle_search = null;
|
|
81
|
-
if (
|
|
82
|
+
if (load_options) {
|
|
82
83
|
debounced_handle_search = debounce(handle_search, 300);
|
|
83
84
|
}
|
|
84
|
-
$: if (
|
|
85
|
-
console.log("doing debounced search", !!debounced_handle_search);
|
|
85
|
+
$: if (load_options && $state.search !== void 0 && $state.search !== last_search) {
|
|
86
86
|
if (debounced_handle_search) debounced_handle_search($state.search);
|
|
87
87
|
}
|
|
88
88
|
const handle_select = (item_key, trigger) => {
|
|
@@ -110,7 +110,7 @@ const handle_select = (item_key, trigger) => {
|
|
|
110
110
|
</Button>
|
|
111
111
|
</Popover.Trigger>
|
|
112
112
|
<Popover.Content sameWidth class="p-0 z-[100]">
|
|
113
|
-
<Command.Root shouldFilter={!
|
|
113
|
+
<Command.Root shouldFilter={!load_options} {state}>
|
|
114
114
|
<Command.Input class="border-none outline-none focus:ring-0" placeholder="Search..." />
|
|
115
115
|
<Command.List>
|
|
116
116
|
{#if loading}
|
|
@@ -7,7 +7,6 @@ export interface ISelectFieldOption {
|
|
|
7
7
|
}
|
|
8
8
|
export interface ISelectFieldParams {
|
|
9
9
|
options?: ISelectFieldOption[];
|
|
10
|
-
load_options?: (search_term: string) => Promise<ISelectFieldOption[]>;
|
|
11
10
|
}
|
|
12
11
|
export declare const select_field_param_spec: IInitialForm;
|
|
13
12
|
export interface ISelectField extends IBaseField<ISelectFieldParams> {
|
|
@@ -16,6 +15,7 @@ export interface ISelectField extends IBaseField<ISelectFieldParams> {
|
|
|
16
15
|
declare const __propDef: {
|
|
17
16
|
props: {
|
|
18
17
|
fieldStore: Writable<IBuiltField<ISelectFieldParams>>;
|
|
18
|
+
load_options?: ((search_term: string) => Promise<ISelectFieldOption[]>) | undefined;
|
|
19
19
|
};
|
|
20
20
|
events: {
|
|
21
21
|
[evt: string]: CustomEvent<any>;
|