@stubber/form-fields 1.6.1 → 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.
@@ -15,7 +15,8 @@
15
15
  </script>
16
16
 
17
17
  <script>import { Button } from "@stubber/ui/button";
18
- import SelectField, {} from "./select-field.svelte";
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 field = $fieldStore;
29
- if (field.params) {
30
- field.params.load_options = async (search_term) => {
31
- const socket = dependencies?.clienthub?.socket;
32
- const orguuid = dependencies?.stubber?.orguuid;
33
- const stubref = dependencies?.stubber?.stubref;
34
- if (!socket || !orguuid || !stubref) {
35
- console.error("ClientHub socket or stubber details not available.");
36
- return [];
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 ISelectFieldOption } from "./select-field.svelte";
12
+ import { type ISelectFieldParams } from "./select-field.svelte";
14
13
  declare const __propDef: {
15
14
  props: {
16
15
  fieldStore: Writable<IBuiltField<IContactSelectorFieldParams>>;
@@ -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 (params.load_options) {
74
+ if (load_options) {
74
75
  loading = true;
75
- const remote_results = await params.load_options($state.search);
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 (params.load_options) {
82
+ if (load_options) {
82
83
  debounced_handle_search = debounce(handle_search, 300);
83
84
  }
84
- $: if (params.load_options && $state.search !== void 0 && $state.search !== last_search) {
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={!params.load_options} {state}>
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>;
@@ -61,9 +61,6 @@ const load_options = async (search_term) => {
61
61
  });
62
62
  });
63
63
  };
64
- if ($fieldStore.params) {
65
- $fieldStore.params.load_options = load_options;
66
- }
67
64
  </script>
68
65
 
69
- <SelectField {fieldStore} />
66
+ <SelectField {fieldStore} {load_options} />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stubber/form-fields",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "An automatic form builder based on field specifications",
5
5
  "keywords": [
6
6
  "components",