@stubber/form-fields 1.4.6 → 1.5.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.
- package/README.md +61 -295
- package/dist/fields2/FieldLabel.svelte +8 -0
- package/dist/fields2/FieldLabel.svelte.d.ts +20 -0
- package/dist/fields2/FieldMessage.svelte +16 -0
- package/dist/fields2/FieldMessage.svelte.d.ts +20 -0
- package/dist/fields2/Form.svelte +29 -0
- package/dist/fields2/Form.svelte.d.ts +23 -0
- package/dist/fields2/fileserver.d.ts +15 -0
- package/dist/fields2/fileserver.js +52 -0
- package/dist/fields2/form-field.svelte +10 -0
- package/dist/fields2/form-field.svelte.d.ts +20 -0
- package/dist/fields2/interfaces.d.ts +207 -0
- package/dist/fields2/interfaces.js +82 -0
- package/dist/fields2/sub/array-builder-field.svelte +110 -0
- package/dist/fields2/sub/array-builder-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/checkbox-autocomplete.svelte +56 -0
- package/dist/fields2/sub/checkbox-autocomplete.svelte.d.ts +27 -0
- package/dist/fields2/sub/checkbox-field.svelte +41 -0
- package/dist/fields2/sub/checkbox-field.svelte.d.ts +28 -0
- package/dist/fields2/sub/code-field.svelte +146 -0
- package/dist/fields2/sub/code-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/contact-selector-field.svelte +84 -0
- package/dist/fields2/sub/contact-selector-field.svelte.d.ts +30 -0
- package/dist/fields2/sub/currency-field.svelte +197 -0
- package/dist/fields2/sub/currency-field.svelte.d.ts +29 -0
- package/dist/fields2/sub/data-indication-field.svelte +19 -0
- package/dist/fields2/sub/data-indication-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/date-field.svelte +31 -0
- package/dist/fields2/sub/date-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/date-time-field.svelte +31 -0
- package/dist/fields2/sub/date-time-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/email-field.svelte +40 -0
- package/dist/fields2/sub/email-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/field-builder-field.svelte +525 -0
- package/dist/fields2/sub/field-builder-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/file-field.svelte +150 -0
- package/dist/fields2/sub/file-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/grid-field.svelte +54 -0
- package/dist/fields2/sub/grid-field.svelte.d.ts +30 -0
- package/dist/fields2/sub/heading-field.svelte +28 -0
- package/dist/fields2/sub/heading-field.svelte.d.ts +28 -0
- package/dist/fields2/sub/hidden-field.svelte +142 -0
- package/dist/fields2/sub/hidden-field.svelte.d.ts +37 -0
- package/dist/fields2/sub/hidden-location-field.svelte +23 -0
- package/dist/fields2/sub/hidden-location-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/html-field.svelte +22 -0
- package/dist/fields2/sub/html-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/json-editor-bound.svelte +17 -0
- package/dist/fields2/sub/json-editor-bound.svelte.d.ts +65 -0
- package/dist/fields2/sub/jsoneditor-field.svelte +23 -0
- package/dist/fields2/sub/jsoneditor-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/map-field.svelte +144 -0
- package/dist/fields2/sub/map-field.svelte.d.ts +28 -0
- package/dist/fields2/sub/multi-checkbox-field.svelte +83 -0
- package/dist/fields2/sub/multi-checkbox-field.svelte.d.ts +34 -0
- package/dist/fields2/sub/multistep-field.svelte +70 -0
- package/dist/fields2/sub/multistep-field.svelte.d.ts +24 -0
- package/dist/fields2/sub/note-field.svelte +18 -0
- package/dist/fields2/sub/note-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/number-field.svelte +77 -0
- package/dist/fields2/sub/number-field.svelte.d.ts +29 -0
- package/dist/fields2/sub/object-builder-field.svelte +123 -0
- package/dist/fields2/sub/object-builder-field.svelte.d.ts +28 -0
- package/dist/fields2/sub/qr-code-scanner-field.svelte +86 -0
- package/dist/fields2/sub/qr-code-scanner-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/radio-field.svelte +69 -0
- package/dist/fields2/sub/radio-field.svelte.d.ts +30 -0
- package/dist/fields2/sub/screenrecorder-field.svelte +182 -0
- package/dist/fields2/sub/screenrecorder-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/screenshot-field.svelte +165 -0
- package/dist/fields2/sub/screenshot-field.svelte.d.ts +26 -0
- package/dist/fields2/sub/scroll-and-read-display-field.svelte +92 -0
- package/dist/fields2/sub/scroll-and-read-display-field.svelte.d.ts +29 -0
- package/dist/fields2/sub/section-field.svelte +27 -0
- package/dist/fields2/sub/section-field.svelte.d.ts +26 -0
- package/dist/fields2/sub/select-field.svelte +138 -0
- package/dist/fields2/sub/select-field.svelte.d.ts +34 -0
- package/dist/fields2/sub/selectresource-field.svelte +69 -0
- package/dist/fields2/sub/selectresource-field.svelte.d.ts +29 -0
- package/dist/fields2/sub/signature-field.svelte +84 -0
- package/dist/fields2/sub/signature-field.svelte.d.ts +23 -0
- package/dist/fields2/sub/slider-field.svelte +28 -0
- package/dist/fields2/sub/slider-field.svelte.d.ts +28 -0
- package/dist/fields2/sub/smart-text-field.svelte +245 -0
- package/dist/fields2/sub/smart-text-field.svelte.d.ts +36 -0
- package/dist/fields2/sub/telephone-field.svelte +68 -0
- package/dist/fields2/sub/telephone-field.svelte.d.ts +26 -0
- package/dist/fields2/sub/text-field.svelte +46 -0
- package/dist/fields2/sub/text-field.svelte.d.ts +27 -0
- package/dist/fields2/sub/voicenote-field.svelte +161 -0
- package/dist/fields2/sub/voicenote-field.svelte.d.ts +26 -0
- package/dist/fields2/utils.d.ts +9 -0
- package/dist/fields2/utils.js +116 -0
- package/dist/fields2/validations/validate_field.d.ts +11 -0
- package/dist/fields2/validations/validate_field.js +121 -0
- package/package.json +6 -9
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
<script context="module">import {} from "../interfaces";
|
|
2
|
+
export const file_field_param_spec = {
|
|
3
|
+
spec: {
|
|
4
|
+
fields: {
|
|
5
|
+
max_files: {
|
|
6
|
+
fieldtype: "number"
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script>import { Button } from "@stubber/ui/button";
|
|
14
|
+
import { isEmpty, isUndefined } from "lodash-es";
|
|
15
|
+
import Dropzone from "svelte-file-dropzone";
|
|
16
|
+
import FieldLabel from "../FieldLabel.svelte";
|
|
17
|
+
import FieldMessage from "../FieldMessage.svelte";
|
|
18
|
+
import { append_attachment, remove_attachment, uploadFiles } from "../fileserver";
|
|
19
|
+
export let fieldStore;
|
|
20
|
+
$: validation_result = $fieldStore.validation_result;
|
|
21
|
+
$: validation_type = validation_result?.type;
|
|
22
|
+
function parse_string_value(value) {
|
|
23
|
+
if (value === "true") return true;
|
|
24
|
+
if (value === "false") return false;
|
|
25
|
+
if (value !== "" && !isNaN(Number(value))) {
|
|
26
|
+
return Number(value);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
async function handle_files_select(e) {
|
|
31
|
+
const { acceptedFiles, fileRejections } = e.detail;
|
|
32
|
+
if (limit_remaining < acceptedFiles.length) {
|
|
33
|
+
alert("You have reached the maximum number of files allowed");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
selected_files = [
|
|
37
|
+
...selected_files,
|
|
38
|
+
...acceptedFiles.map((f) => ({
|
|
39
|
+
filename: f.name,
|
|
40
|
+
f_id: Math.random().toString(36).substring(7)
|
|
41
|
+
}))
|
|
42
|
+
];
|
|
43
|
+
const upload_res = await uploadFiles(acceptedFiles, $fieldStore.formDependencies);
|
|
44
|
+
const { uploaded_files: newly_uploaded, failed_files: newly_failed } = upload_res || {
|
|
45
|
+
uploaded_files: [],
|
|
46
|
+
failed_files: []
|
|
47
|
+
};
|
|
48
|
+
const newly_uploaded_with_f_id = newly_uploaded.map((f) => ({
|
|
49
|
+
filename: f.filename,
|
|
50
|
+
fileuuid: f.fileuuid,
|
|
51
|
+
f_id: Math.random().toString(36).substring(7),
|
|
52
|
+
originalname: f.originalname,
|
|
53
|
+
contentType: f.contentType
|
|
54
|
+
}));
|
|
55
|
+
for (const f of newly_uploaded) {
|
|
56
|
+
append_attachment(f, $fieldStore.attachmentsStore);
|
|
57
|
+
}
|
|
58
|
+
uploaded_files = [...uploaded_files, ...newly_uploaded_with_f_id];
|
|
59
|
+
failed_files = [
|
|
60
|
+
...failed_files,
|
|
61
|
+
...newly_failed.map((f) => ({
|
|
62
|
+
filename: f.name,
|
|
63
|
+
f_id: Math.random().toString(36).substring(7)
|
|
64
|
+
}))
|
|
65
|
+
];
|
|
66
|
+
selected_files = [];
|
|
67
|
+
}
|
|
68
|
+
let uploaded_files = [];
|
|
69
|
+
let failed_files = [];
|
|
70
|
+
let selected_files = [];
|
|
71
|
+
$: update_fieldStore(uploaded_files);
|
|
72
|
+
function update_fieldStore(uploaded_files2) {
|
|
73
|
+
if (isEmpty(uploaded_files2) && isUndefined($fieldStore.value)) return;
|
|
74
|
+
$fieldStore.value = uploaded_files2;
|
|
75
|
+
}
|
|
76
|
+
$: all_files = [
|
|
77
|
+
...uploaded_files.map((f) => ({ ...f, is_uploaded: true, is_failed: false })),
|
|
78
|
+
...failed_files.map((f) => ({ ...f, is_failed: true, is_uploaded: false })),
|
|
79
|
+
...selected_files.map((f) => ({ ...f, is_uploaded: false, is_failed: false }))
|
|
80
|
+
];
|
|
81
|
+
let max_files = isNaN(Number($fieldStore.params?.max_files)) ? Infinity : Number($fieldStore.params?.max_files);
|
|
82
|
+
$: limit_remaining = max_files - selected_files.length - uploaded_files.length;
|
|
83
|
+
function remove_file(item) {
|
|
84
|
+
uploaded_files = uploaded_files?.filter((f) => f.f_id !== item.f_id);
|
|
85
|
+
failed_files = failed_files?.filter((f) => f.f_id !== item.f_id);
|
|
86
|
+
selected_files = selected_files?.filter((f) => f.f_id !== item.f_id);
|
|
87
|
+
if ("fileuuid" in item) {
|
|
88
|
+
remove_attachment(item.fileuuid, $fieldStore.attachmentsStore);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<FieldLabel {fieldStore} />
|
|
94
|
+
<div class="w-full flex flex-col {validation_type == 'error' ? 'border-b border-warning-500' : ''}">
|
|
95
|
+
<Dropzone on:drop={handle_files_select} disabled={limit_remaining <= 0}>
|
|
96
|
+
<div class="flex justify-center h-full flex-col text-center rounded-sm">
|
|
97
|
+
<div>
|
|
98
|
+
<p class=" text-surface-800">Drop files to upload</p>
|
|
99
|
+
<p class=" text-surface-800">
|
|
100
|
+
Or click <span
|
|
101
|
+
class="text-primary-500 hover:text-primary-400 hover:underline cursor-pointer"
|
|
102
|
+
>here</span
|
|
103
|
+
>
|
|
104
|
+
to browse
|
|
105
|
+
</p>
|
|
106
|
+
{#if limit_remaining <= 0}
|
|
107
|
+
<p class="text-field text-danger-600 text-sm italic">
|
|
108
|
+
You have reached the maximum number of files allowed
|
|
109
|
+
</p>
|
|
110
|
+
{/if}
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
</Dropzone>
|
|
114
|
+
<div class="w-full mt-2">
|
|
115
|
+
{#each all_files as item}
|
|
116
|
+
<div class="w-full flex flex-row">
|
|
117
|
+
{#if item.is_uploaded}
|
|
118
|
+
<div class="px-2">
|
|
119
|
+
<i class="fa fa-check text-success-500" />
|
|
120
|
+
</div>
|
|
121
|
+
{:else if item.is_failed}
|
|
122
|
+
<div class="px-2 space-x-2 flex items-center text-danger-400">
|
|
123
|
+
<i class="fa-regular fa-triangle-exclamation" />
|
|
124
|
+
<p class="hidden md:block text-fluid-md">Failed</p>
|
|
125
|
+
</div>
|
|
126
|
+
{:else}
|
|
127
|
+
<div class="px-2 space-x-2 flex items-center text-surface-500">
|
|
128
|
+
<p class="hidden md:block text-fluid-md" />
|
|
129
|
+
<i class="fa fa-pulse fa-spinner" />
|
|
130
|
+
</div>
|
|
131
|
+
{/if}
|
|
132
|
+
<div class="w-full shrink py-1 pl-2 truncate border border-surface-200 rounded-sm">
|
|
133
|
+
<p class="text-surface-800 text-fluid-md">
|
|
134
|
+
{item?.filename}
|
|
135
|
+
</p>
|
|
136
|
+
</div>
|
|
137
|
+
<Button
|
|
138
|
+
type="button"
|
|
139
|
+
variant="destructive"
|
|
140
|
+
size="icon"
|
|
141
|
+
class="shrink-0 ml-1 p-1 px-2 fa-solid fa-2xs fa-x border-surface-0 "
|
|
142
|
+
on:click={() => {
|
|
143
|
+
remove_file(item);
|
|
144
|
+
}}
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
{/each}
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
<FieldMessage {fieldStore} />
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { Writable } from "svelte/store";
|
|
3
|
+
import { type IBaseField, type IBuiltField, type IInitialForm } from "../interfaces";
|
|
4
|
+
export interface IFileFieldParams {
|
|
5
|
+
max_files?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface IFileField extends IBaseField<IFileFieldParams> {
|
|
8
|
+
fieldtype: "file";
|
|
9
|
+
}
|
|
10
|
+
export declare const file_field_param_spec: IInitialForm;
|
|
11
|
+
declare const __propDef: {
|
|
12
|
+
props: {
|
|
13
|
+
fieldStore: Writable<IBuiltField<IFileFieldParams>>;
|
|
14
|
+
};
|
|
15
|
+
events: {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {};
|
|
19
|
+
exports?: {} | undefined;
|
|
20
|
+
bindings?: string | undefined;
|
|
21
|
+
};
|
|
22
|
+
export type FileFieldProps = typeof __propDef.props;
|
|
23
|
+
export type FileFieldEvents = typeof __propDef.events;
|
|
24
|
+
export type FileFieldSlots = typeof __propDef.slots;
|
|
25
|
+
export default class FileField extends SvelteComponent<FileFieldProps, FileFieldEvents, FileFieldSlots> {
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script context="module">export const grid_field_param_spec = {
|
|
2
|
+
spec: {
|
|
3
|
+
fields: {
|
|
4
|
+
columnDefs: {
|
|
5
|
+
fieldtype: "jsoneditor",
|
|
6
|
+
help: "Column Definitions as per https://www.ag-grid.com/javascript-data-grid/column-definitions/"
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script>import { createGrid, GridApi } from "ag-grid-community";
|
|
14
|
+
import "ag-grid-community/styles/ag-grid.css";
|
|
15
|
+
import "ag-grid-community/styles/ag-theme-material.css";
|
|
16
|
+
import { onMount } from "svelte";
|
|
17
|
+
import FieldLabel from "../FieldLabel.svelte";
|
|
18
|
+
import FieldMessage from "../FieldMessage.svelte";
|
|
19
|
+
export let fieldStore;
|
|
20
|
+
let gridDiv;
|
|
21
|
+
let gridApi;
|
|
22
|
+
const gridOptions = {
|
|
23
|
+
autoSizeStrategy: {
|
|
24
|
+
type: "fitGridWidth",
|
|
25
|
+
defaultMinWidth: 100
|
|
26
|
+
},
|
|
27
|
+
defaultColDef: {
|
|
28
|
+
suppressMovable: true
|
|
29
|
+
},
|
|
30
|
+
onGridReady: (params) => {
|
|
31
|
+
gridApi = params.api;
|
|
32
|
+
},
|
|
33
|
+
onCellValueChanged: () => {
|
|
34
|
+
let rowData = [];
|
|
35
|
+
gridApi.forEachNode((node) => rowData.push(node.data));
|
|
36
|
+
$fieldStore.value = rowData;
|
|
37
|
+
},
|
|
38
|
+
// Row Data: The data to be displayed.
|
|
39
|
+
rowData: [],
|
|
40
|
+
// Column Definitions: Defines & controls grid columns.
|
|
41
|
+
columnDefs: []
|
|
42
|
+
};
|
|
43
|
+
onMount(() => {
|
|
44
|
+
let columnDefs = $fieldStore.params?.columnDefs;
|
|
45
|
+
if (columnDefs) gridOptions.columnDefs = columnDefs;
|
|
46
|
+
let rowData = $fieldStore.value;
|
|
47
|
+
if (Array.isArray(rowData)) gridOptions.rowData = rowData;
|
|
48
|
+
createGrid(gridDiv, gridOptions);
|
|
49
|
+
});
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<FieldLabel {fieldStore} />
|
|
53
|
+
<div bind:this={gridDiv} class="ag-theme-material w-full h-96" />
|
|
54
|
+
<FieldMessage {fieldStore} />
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { Writable } from "svelte/store";
|
|
3
|
+
import type { IBaseField, IBuiltField, IInitialForm } from "../interfaces";
|
|
4
|
+
interface IGridParams {
|
|
5
|
+
columnDefs?: ColDef[];
|
|
6
|
+
}
|
|
7
|
+
export declare const grid_field_param_spec: IInitialForm;
|
|
8
|
+
export interface IGridField extends IBaseField<IGridParams> {
|
|
9
|
+
fieldtype: "grid";
|
|
10
|
+
}
|
|
11
|
+
import { type ColDef } from "ag-grid-community";
|
|
12
|
+
import "ag-grid-community/styles/ag-grid.css";
|
|
13
|
+
import "ag-grid-community/styles/ag-theme-material.css";
|
|
14
|
+
declare const __propDef: {
|
|
15
|
+
props: {
|
|
16
|
+
fieldStore: Writable<IBuiltField<IGridParams>>;
|
|
17
|
+
};
|
|
18
|
+
events: {
|
|
19
|
+
[evt: string]: CustomEvent<any>;
|
|
20
|
+
};
|
|
21
|
+
slots: {};
|
|
22
|
+
exports?: {} | undefined;
|
|
23
|
+
bindings?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
export type GridFieldProps = typeof __propDef.props;
|
|
26
|
+
export type GridFieldEvents = typeof __propDef.events;
|
|
27
|
+
export type GridFieldSlots = typeof __propDef.slots;
|
|
28
|
+
export default class GridField extends SvelteComponent<GridFieldProps, GridFieldEvents, GridFieldSlots> {
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script context="module">import {} from "../interfaces";
|
|
2
|
+
export const heading_field_param_spec = {
|
|
3
|
+
spec: {
|
|
4
|
+
fields: {
|
|
5
|
+
heading_text: {
|
|
6
|
+
fieldtype: "text"
|
|
7
|
+
},
|
|
8
|
+
subheading_text: {
|
|
9
|
+
fieldtype: "text"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script>export let fieldStore;
|
|
17
|
+
$: heading_text = $fieldStore?.params?.heading_text;
|
|
18
|
+
$: subheading_text = $fieldStore?.params?.subheading_text;
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<div class="flex flex-col w-full mb-2">
|
|
22
|
+
{#if heading_text}
|
|
23
|
+
<h1 class="text-xl text-black tracking-tight font-semibold mt-4">{heading_text}</h1>
|
|
24
|
+
{/if}
|
|
25
|
+
{#if subheading_text}
|
|
26
|
+
<h2 class="text-sm text-surface-500 whitespace-pre-wrap">{subheading_text}</h2>
|
|
27
|
+
{/if}
|
|
28
|
+
</div>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { Writable } from "svelte/store";
|
|
3
|
+
import { type IBaseField, type IBuiltField, type IInitialForm } from "../interfaces";
|
|
4
|
+
export interface IHeadingFieldParams {
|
|
5
|
+
heading_text?: string;
|
|
6
|
+
subheading_text?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface IHeadingField extends IBaseField<IHeadingFieldParams> {
|
|
9
|
+
fieldtype: "heading";
|
|
10
|
+
}
|
|
11
|
+
export declare const heading_field_param_spec: IInitialForm;
|
|
12
|
+
declare const __propDef: {
|
|
13
|
+
props: {
|
|
14
|
+
fieldStore: Writable<IBuiltField<IHeadingFieldParams>>;
|
|
15
|
+
};
|
|
16
|
+
events: {
|
|
17
|
+
[evt: string]: CustomEvent<any>;
|
|
18
|
+
};
|
|
19
|
+
slots: {};
|
|
20
|
+
exports?: {} | undefined;
|
|
21
|
+
bindings?: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
export type HeadingFieldProps = typeof __propDef.props;
|
|
24
|
+
export type HeadingFieldEvents = typeof __propDef.events;
|
|
25
|
+
export type HeadingFieldSlots = typeof __propDef.slots;
|
|
26
|
+
export default class HeadingField extends SvelteComponent<HeadingFieldProps, HeadingFieldEvents, HeadingFieldSlots> {
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<script context="module">import {} from "../interfaces";
|
|
2
|
+
import { debounce, isArray, isEqual, isObject } from "lodash-es";
|
|
3
|
+
import jsonata from "jsonata";
|
|
4
|
+
export const hidden_field_param_spec = {
|
|
5
|
+
spec: {
|
|
6
|
+
fields: {
|
|
7
|
+
type: {
|
|
8
|
+
fieldtype: "select",
|
|
9
|
+
details: {
|
|
10
|
+
datapath: "value"
|
|
11
|
+
},
|
|
12
|
+
without_value_details: true,
|
|
13
|
+
params: {
|
|
14
|
+
options: [
|
|
15
|
+
{
|
|
16
|
+
value: "string",
|
|
17
|
+
label: "Raw expression"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
value: "jsonata",
|
|
21
|
+
label: "JSONata expression"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: "apicall",
|
|
25
|
+
label: "API call"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
expression: {
|
|
31
|
+
conditions: ["form.data.value.type != 'apicall'"],
|
|
32
|
+
fieldtype: "text",
|
|
33
|
+
details: {
|
|
34
|
+
datapath: "value"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
api_params: {
|
|
38
|
+
fieldtype: "section",
|
|
39
|
+
conditions: ["form.data.value.type = 'apicall'"],
|
|
40
|
+
details: {
|
|
41
|
+
datapath: "value"
|
|
42
|
+
},
|
|
43
|
+
fields: {
|
|
44
|
+
method: { fieldtype: "text" },
|
|
45
|
+
url: { fieldtype: "text" },
|
|
46
|
+
headers: {
|
|
47
|
+
fieldtype: "arraybuilder",
|
|
48
|
+
params: {
|
|
49
|
+
new_entry_field: {
|
|
50
|
+
fieldtype: "section",
|
|
51
|
+
fields: {
|
|
52
|
+
key: { fieldtype: "text" },
|
|
53
|
+
value: { fieldtype: "text" }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
body: {
|
|
59
|
+
fieldtype: "jsoneditor"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<script>export let fieldStore;
|
|
69
|
+
let params = $fieldStore.params;
|
|
70
|
+
let formStore = $fieldStore.formStore;
|
|
71
|
+
$: recalculate_value($formStore);
|
|
72
|
+
async function recalculate_value(form_data) {
|
|
73
|
+
if (typeof params?.value === "string") {
|
|
74
|
+
if (params?.value !== $fieldStore.value) {
|
|
75
|
+
$fieldStore.value = params.value;
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (params?.value) {
|
|
80
|
+
switch (params?.value?.type) {
|
|
81
|
+
case "string":
|
|
82
|
+
if (params?.value?.expression !== $fieldStore.value) {
|
|
83
|
+
$fieldStore.value = params.value.expression;
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
case "jsonata":
|
|
87
|
+
if (!params?.value?.expression) return;
|
|
88
|
+
try {
|
|
89
|
+
const expression = jsonata(params?.value?.expression);
|
|
90
|
+
const result = await expression.evaluate({
|
|
91
|
+
form: {
|
|
92
|
+
data: form_data
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (!isEqual(result, $fieldStore.value)) {
|
|
96
|
+
$fieldStore.value = result;
|
|
97
|
+
}
|
|
98
|
+
} catch (err) {
|
|
99
|
+
if ($fieldStore.value !== void 0) $fieldStore.value = void 0;
|
|
100
|
+
console.warn(err);
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
case "apicall": {
|
|
104
|
+
let api_params = params.value?.api_params || {};
|
|
105
|
+
debounced_api_call(api_params);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const debounced_api_call = debounce(call_api, 500);
|
|
112
|
+
async function call_api(api_params) {
|
|
113
|
+
const { url, method, headers, body } = api_params;
|
|
114
|
+
if (method && url) {
|
|
115
|
+
try {
|
|
116
|
+
let fetchOptions = { headers: {} };
|
|
117
|
+
fetchOptions.method = method.toUpperCase();
|
|
118
|
+
if (isArray(headers)) {
|
|
119
|
+
for (let h of headers) {
|
|
120
|
+
let [key, value] = h.split(":");
|
|
121
|
+
fetchOptions.headers[key] = value;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (body) fetchOptions.body = JSON.stringify(body);
|
|
125
|
+
let res = await fetch(url, fetchOptions);
|
|
126
|
+
let resJSON;
|
|
127
|
+
if (res.headers.get("content-type")?.includes("application/json")) {
|
|
128
|
+
resJSON = await res.json();
|
|
129
|
+
} else {
|
|
130
|
+
resJSON = await res.text();
|
|
131
|
+
}
|
|
132
|
+
if (!isEqual(resJSON, $fieldStore.value)) {
|
|
133
|
+
$fieldStore.value = resJSON;
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
console.warn(err);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
</script>
|
|
141
|
+
|
|
142
|
+
<input id={$fieldStore.id} name={$fieldStore.id} bind:value={$fieldStore.value} hidden />
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { Writable } from "svelte/store";
|
|
3
|
+
import { type IBaseField, type IBuiltField, type IInitialForm } from "../interfaces";
|
|
4
|
+
interface IApiParams {
|
|
5
|
+
url?: string;
|
|
6
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
7
|
+
headers?: string[];
|
|
8
|
+
body?: any;
|
|
9
|
+
}
|
|
10
|
+
export interface IHiddenFieldParams {
|
|
11
|
+
value: {
|
|
12
|
+
type: "string" | "jsonata" | "apicall";
|
|
13
|
+
expression?: string;
|
|
14
|
+
api_params?: IApiParams;
|
|
15
|
+
} | string | undefined;
|
|
16
|
+
}
|
|
17
|
+
export interface IHiddenField extends IBaseField<IHiddenFieldParams> {
|
|
18
|
+
fieldtype: "hidden";
|
|
19
|
+
}
|
|
20
|
+
export declare const hidden_field_param_spec: IInitialForm;
|
|
21
|
+
declare const __propDef: {
|
|
22
|
+
props: {
|
|
23
|
+
fieldStore: Writable<IBuiltField<IHiddenFieldParams>>;
|
|
24
|
+
};
|
|
25
|
+
events: {
|
|
26
|
+
[evt: string]: CustomEvent<any>;
|
|
27
|
+
};
|
|
28
|
+
slots: {};
|
|
29
|
+
exports?: {} | undefined;
|
|
30
|
+
bindings?: string | undefined;
|
|
31
|
+
};
|
|
32
|
+
export type HiddenFieldProps = typeof __propDef.props;
|
|
33
|
+
export type HiddenFieldEvents = typeof __propDef.events;
|
|
34
|
+
export type HiddenFieldSlots = typeof __propDef.slots;
|
|
35
|
+
export default class HiddenField extends SvelteComponent<HiddenFieldProps, HiddenFieldEvents, HiddenFieldSlots> {
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script context="module">import { isEqual } from "lodash-es";
|
|
2
|
+
import {} from "../interfaces";
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script>import { onMount } from "svelte";
|
|
6
|
+
export let fieldStore;
|
|
7
|
+
onMount(() => {
|
|
8
|
+
navigator.geolocation.getCurrentPosition((o) => {
|
|
9
|
+
let { latitude, longitude } = o?.coords || {};
|
|
10
|
+
if (!latitude || !longitude) return;
|
|
11
|
+
let value = {
|
|
12
|
+
lat: latitude,
|
|
13
|
+
lng: longitude,
|
|
14
|
+
latlng: `${latitude},${longitude}`
|
|
15
|
+
};
|
|
16
|
+
if (!isEqual(value, $fieldStore.value)) {
|
|
17
|
+
$fieldStore.value = value;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<input id={$fieldStore.id} name={$fieldStore.id} bind:value={$fieldStore.value} hidden />
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { Writable } from "svelte/store";
|
|
3
|
+
import { type IBaseField, type IBuiltField } from "../interfaces";
|
|
4
|
+
export interface IHiddenLocationField extends IBaseField<{}> {
|
|
5
|
+
fieldtype: "hiddenlocation";
|
|
6
|
+
}
|
|
7
|
+
declare const __propDef: {
|
|
8
|
+
props: {
|
|
9
|
+
fieldStore: Writable<IBuiltField>;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
};
|
|
14
|
+
slots: {};
|
|
15
|
+
exports?: {} | undefined;
|
|
16
|
+
bindings?: string | undefined;
|
|
17
|
+
};
|
|
18
|
+
export type HiddenLocationFieldProps = typeof __propDef.props;
|
|
19
|
+
export type HiddenLocationFieldEvents = typeof __propDef.events;
|
|
20
|
+
export type HiddenLocationFieldSlots = typeof __propDef.slots;
|
|
21
|
+
export default class HiddenLocationField extends SvelteComponent<HiddenLocationFieldProps, HiddenLocationFieldEvents, HiddenLocationFieldSlots> {
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script context="module">import {} from "../interfaces";
|
|
2
|
+
export const html_field_param_spec = {
|
|
3
|
+
spec: {
|
|
4
|
+
fields: {
|
|
5
|
+
html: {
|
|
6
|
+
fieldtype: "text"
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script>export let fieldStore;
|
|
14
|
+
let params = $fieldStore.params;
|
|
15
|
+
$: html = params?.html;
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<div class="w-full">
|
|
19
|
+
{#if html}
|
|
20
|
+
{@html html}
|
|
21
|
+
{/if}
|
|
22
|
+
</div>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { Writable } from "svelte/store";
|
|
3
|
+
import { type IBaseField, type IBuiltField, type IInitialForm } from "../interfaces";
|
|
4
|
+
export interface IHTMLFieldParams {
|
|
5
|
+
html?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IHTMLField extends IBaseField<IHTMLFieldParams> {
|
|
8
|
+
fieldtype: "html";
|
|
9
|
+
}
|
|
10
|
+
export declare const html_field_param_spec: IInitialForm;
|
|
11
|
+
declare const __propDef: {
|
|
12
|
+
props: {
|
|
13
|
+
fieldStore: Writable<IBuiltField<IHTMLFieldParams>>;
|
|
14
|
+
};
|
|
15
|
+
events: {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {};
|
|
19
|
+
exports?: {} | undefined;
|
|
20
|
+
bindings?: string | undefined;
|
|
21
|
+
};
|
|
22
|
+
export type HtmlFieldProps = typeof __propDef.props;
|
|
23
|
+
export type HtmlFieldEvents = typeof __propDef.events;
|
|
24
|
+
export type HtmlFieldSlots = typeof __propDef.slots;
|
|
25
|
+
export default class HtmlField extends SvelteComponent<HtmlFieldProps, HtmlFieldEvents, HtmlFieldSlots> {
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script>import { cloneDeep } from "lodash-es";
|
|
2
|
+
import { JSONEditor } from "svelte-jsoneditor";
|
|
3
|
+
export let value;
|
|
4
|
+
$: content = value === void 0 ? { text: "", json: void 0 } : {
|
|
5
|
+
text: typeof value === "string" ? value : void 0,
|
|
6
|
+
json: typeof value === "string" ? void 0 : cloneDeep(value)
|
|
7
|
+
};
|
|
8
|
+
function handleChange(new_content) {
|
|
9
|
+
if ("json" in new_content) {
|
|
10
|
+
value = cloneDeep(new_content.json);
|
|
11
|
+
} else if ("text" in new_content) {
|
|
12
|
+
value = cloneDeep(new_content.text);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<JSONEditor {content} onChange={handleChange} {...$$restProps} />
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
content?: import("svelte-jsoneditor").Content;
|
|
5
|
+
selection?: import("svelte-jsoneditor").JSONEditorSelection | undefined;
|
|
6
|
+
readOnly?: boolean;
|
|
7
|
+
indentation?: number | string;
|
|
8
|
+
tabSize?: number;
|
|
9
|
+
mode?: import("svelte-jsoneditor").Mode;
|
|
10
|
+
mainMenuBar?: boolean;
|
|
11
|
+
navigationBar?: boolean;
|
|
12
|
+
statusBar?: boolean;
|
|
13
|
+
askToFormat?: boolean;
|
|
14
|
+
escapeControlCharacters?: boolean;
|
|
15
|
+
escapeUnicodeCharacters?: boolean;
|
|
16
|
+
flattenColumns?: boolean;
|
|
17
|
+
parser?: import("svelte-jsoneditor").JSONParser;
|
|
18
|
+
validator?: import("svelte-jsoneditor").Validator | undefined;
|
|
19
|
+
validationParser?: import("svelte-jsoneditor").JSONParser;
|
|
20
|
+
pathParser?: import("svelte-jsoneditor").JSONPathParser;
|
|
21
|
+
queryLanguages?: import("svelte-jsoneditor").QueryLanguage[];
|
|
22
|
+
queryLanguageId?: string;
|
|
23
|
+
onChangeQueryLanguage?: import("svelte-jsoneditor").OnChangeQueryLanguage;
|
|
24
|
+
onChange?: import("svelte-jsoneditor").OnChange | undefined;
|
|
25
|
+
onSelect?: import("svelte-jsoneditor").OnSelect | undefined;
|
|
26
|
+
onRenderValue?: import("svelte-jsoneditor").OnRenderValue;
|
|
27
|
+
onClassName?: import("svelte-jsoneditor").OnClassName;
|
|
28
|
+
onRenderMenu?: import("svelte-jsoneditor").OnRenderMenu;
|
|
29
|
+
onRenderContextMenu?: import("svelte-jsoneditor").OnRenderContextMenu;
|
|
30
|
+
onChangeMode?: import("svelte-jsoneditor").OnChangeMode;
|
|
31
|
+
onError?: import("svelte-jsoneditor").OnError;
|
|
32
|
+
onFocus?: import("svelte-jsoneditor").OnFocus;
|
|
33
|
+
onBlur?: import("svelte-jsoneditor").OnBlur;
|
|
34
|
+
get?: () => import("svelte-jsoneditor").Content;
|
|
35
|
+
set?: (newContent: import("svelte-jsoneditor").Content) => Promise<void>;
|
|
36
|
+
update?: (updatedContent: import("svelte-jsoneditor").Content) => Promise<void>;
|
|
37
|
+
patch?: (operations: import("immutable-json-patch").JSONPatchDocument) => Promise<import("svelte-jsoneditor").JSONPatchResult>;
|
|
38
|
+
select?: (newSelection: import("svelte-jsoneditor").JSONEditorSelection | undefined) => Promise<void>;
|
|
39
|
+
expand?: (path: import("immutable-json-patch").JSONPath, callback?: import("svelte-jsoneditor").OnExpand) => Promise<void>;
|
|
40
|
+
collapse?: (path: import("immutable-json-patch").JSONPath, recursive?: boolean) => Promise<void>;
|
|
41
|
+
transform?: (options: import("svelte-jsoneditor").TransformModalOptions) => void;
|
|
42
|
+
validate?: () => import("svelte-jsoneditor").ContentErrors | undefined;
|
|
43
|
+
acceptAutoRepair?: () => Promise<import("svelte-jsoneditor").Content>;
|
|
44
|
+
scrollTo?: (path: import("immutable-json-patch").JSONPath) => Promise<void>;
|
|
45
|
+
findElement?: (path: import("immutable-json-patch").JSONPath) => Element | undefined;
|
|
46
|
+
focus?: () => Promise<void>;
|
|
47
|
+
refresh?: () => Promise<void>;
|
|
48
|
+
updateProps?: (props: import("svelte-jsoneditor").JSONEditorPropsOptional) => Promise<void>;
|
|
49
|
+
destroy?: () => Promise<void>;
|
|
50
|
+
} & {
|
|
51
|
+
value: any;
|
|
52
|
+
};
|
|
53
|
+
events: {
|
|
54
|
+
[evt: string]: CustomEvent<any>;
|
|
55
|
+
};
|
|
56
|
+
slots: {};
|
|
57
|
+
exports?: {} | undefined;
|
|
58
|
+
bindings?: string | undefined;
|
|
59
|
+
};
|
|
60
|
+
export type JsonEditorBoundProps = typeof __propDef.props;
|
|
61
|
+
export type JsonEditorBoundEvents = typeof __propDef.events;
|
|
62
|
+
export type JsonEditorBoundSlots = typeof __propDef.slots;
|
|
63
|
+
export default class JsonEditorBound extends SvelteComponent<JsonEditorBoundProps, JsonEditorBoundEvents, JsonEditorBoundSlots> {
|
|
64
|
+
}
|
|
65
|
+
export {};
|