svelte-multistyle-ui 0.0.15-alpha → 0.1.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 +55 -3
- package/cli/bin.js +94 -92
- package/cli/emit.js +242 -225
- package/cli/fixtures/sample.expected.svelte +2 -1
- package/cli/generate.js +507 -499
- package/cli/registry.js +105 -100
- package/cli/schema.js +16 -0
- package/dist/actions/dialog.d.ts +11 -0
- package/dist/actions/dialog.js +118 -0
- package/dist/components/Accordion.svelte +11 -5
- package/dist/components/Accordion.svelte.d.ts +8 -12
- package/dist/components/Alert.svelte +11 -5
- package/dist/components/Alert.svelte.d.ts +8 -16
- package/dist/components/Avatar.svelte +13 -3
- package/dist/components/Avatar.svelte.d.ts +8 -14
- package/dist/components/Breadcrumb.svelte +9 -3
- package/dist/components/Breadcrumb.svelte.d.ts +8 -8
- package/dist/components/Button.svelte +11 -3
- package/dist/components/Button.svelte.d.ts +8 -20
- package/dist/components/ButtonGroup.svelte +10 -4
- package/dist/components/ButtonGroup.svelte.d.ts +8 -16
- package/dist/components/Card.svelte +9 -3
- package/dist/components/Card.svelte.d.ts +8 -12
- package/dist/components/Carousel.svelte +17 -9
- package/dist/components/Carousel.svelte.d.ts +8 -16
- package/dist/components/Checkbox.svelte +10 -4
- package/dist/components/Checkbox.svelte.d.ts +8 -14
- package/dist/components/Chip.svelte +10 -4
- package/dist/components/Chip.svelte.d.ts +8 -20
- package/dist/components/CodeEditor.svelte +139 -129
- package/dist/components/CodeEditor.svelte.d.ts +8 -16
- package/dist/components/Column.svelte +48 -38
- package/dist/components/Column.svelte.d.ts +8 -12
- package/dist/components/CommandPalette.svelte +14 -5
- package/dist/components/CommandPalette.svelte.d.ts +8 -12
- package/dist/components/CrudView.svelte +1604 -0
- package/dist/components/CrudView.svelte.d.ts +17 -0
- package/dist/components/DatePicker.svelte +42 -10
- package/dist/components/DatePicker.svelte.d.ts +8 -24
- package/dist/components/Divider.svelte +9 -3
- package/dist/components/Divider.svelte.d.ts +8 -10
- package/dist/components/Drawer.svelte +19 -3
- package/dist/components/Drawer.svelte.d.ts +8 -14
- package/dist/components/DropdownMenu.svelte +32 -5
- package/dist/components/DropdownMenu.svelte.d.ts +8 -18
- package/dist/components/FAB.svelte +10 -4
- package/dist/components/FAB.svelte.d.ts +8 -14
- package/dist/components/FileUpload.svelte +47 -8
- package/dist/components/FileUpload.svelte.d.ts +8 -14
- package/dist/components/FilterBar.svelte +768 -0
- package/dist/components/FilterBar.svelte.d.ts +17 -0
- package/dist/components/GraphEditor.svelte +725 -723
- package/dist/components/GraphEditor.svelte.d.ts +8 -8
- package/dist/components/Grid.svelte +61 -51
- package/dist/components/Grid.svelte.d.ts +8 -18
- package/dist/components/IconButton.svelte +12 -4
- package/dist/components/IconButton.svelte.d.ts +8 -22
- package/dist/components/InlineEdit.svelte +6 -3
- package/dist/components/InlineEdit.svelte.d.ts +10 -10
- package/dist/components/Input.svelte +18 -4
- package/dist/components/Input.svelte.d.ts +8 -62
- package/dist/components/Modal.svelte +14 -5
- package/dist/components/Modal.svelte.d.ts +8 -16
- package/dist/components/MultiSelect.svelte +22 -204
- package/dist/components/MultiSelect.svelte.d.ts +8 -16
- package/dist/components/Pagination.svelte +19 -4
- package/dist/components/Pagination.svelte.d.ts +8 -12
- package/dist/components/Popover.svelte +15 -4
- package/dist/components/Popover.svelte.d.ts +8 -16
- package/dist/components/ProgressBar.svelte +79 -73
- package/dist/components/ProgressBar.svelte.d.ts +8 -14
- package/dist/components/Radio.svelte +10 -4
- package/dist/components/Radio.svelte.d.ts +8 -14
- package/dist/components/Rating.svelte +30 -6
- package/dist/components/Rating.svelte.d.ts +8 -18
- package/dist/components/Row.svelte +49 -39
- package/dist/components/Row.svelte.d.ts +8 -14
- package/dist/components/Select.svelte +252 -32
- package/dist/components/Select.svelte.d.ts +8 -16
- package/dist/components/Skeleton.svelte +9 -3
- package/dist/components/Skeleton.svelte.d.ts +8 -12
- package/dist/components/Slider.svelte +14 -6
- package/dist/components/Slider.svelte.d.ts +8 -18
- package/dist/components/SortableList.svelte +136 -130
- package/dist/components/SortableList.svelte.d.ts +6 -14
- package/dist/components/Spinner.svelte +9 -3
- package/dist/components/Spinner.svelte.d.ts +8 -8
- package/dist/components/Stepper.svelte +101 -93
- package/dist/components/Stepper.svelte.d.ts +8 -10
- package/dist/components/Table.svelte +9 -3
- package/dist/components/Table.svelte.d.ts +8 -12
- package/dist/components/Tabs.svelte +29 -5
- package/dist/components/Tabs.svelte.d.ts +8 -10
- package/dist/components/TextEditor.svelte +191 -182
- package/dist/components/TextEditor.svelte.d.ts +8 -18
- package/dist/components/Textarea.svelte +24 -7
- package/dist/components/Textarea.svelte.d.ts +8 -24
- package/dist/components/Toast.svelte +52 -16
- package/dist/components/Toast.svelte.d.ts +8 -12
- package/dist/components/Toggle.svelte +10 -4
- package/dist/components/Toggle.svelte.d.ts +8 -14
- package/dist/components/Tooltip.svelte +14 -4
- package/dist/components/Tooltip.svelte.d.ts +8 -12
- package/dist/components/charts/BarChart.svelte +7 -5
- package/dist/components/charts/BarChart.svelte.d.ts +8 -22
- package/dist/components/charts/BubbleChart.svelte +7 -5
- package/dist/components/charts/BubbleChart.svelte.d.ts +8 -22
- package/dist/components/charts/Chart.svelte +273 -248
- package/dist/components/charts/Chart.svelte.d.ts +8 -30
- package/dist/components/charts/ComboChart.svelte +7 -5
- package/dist/components/charts/ComboChart.svelte.d.ts +8 -22
- package/dist/components/charts/DoughnutChart.svelte +7 -5
- package/dist/components/charts/DoughnutChart.svelte.d.ts +8 -22
- package/dist/components/charts/LineChart.svelte +7 -5
- package/dist/components/charts/LineChart.svelte.d.ts +8 -22
- package/dist/components/charts/MermaidChart.svelte +106 -0
- package/dist/components/charts/MermaidChart.svelte.d.ts +20 -0
- package/dist/components/charts/PieChart.svelte +7 -5
- package/dist/components/charts/PieChart.svelte.d.ts +8 -22
- package/dist/components/charts/PolarAreaChart.svelte +7 -5
- package/dist/components/charts/PolarAreaChart.svelte.d.ts +8 -22
- package/dist/components/charts/RadarChart.svelte +7 -5
- package/dist/components/charts/RadarChart.svelte.d.ts +8 -22
- package/dist/components/charts/ScatterChart.svelte +7 -5
- package/dist/components/charts/ScatterChart.svelte.d.ts +8 -22
- package/dist/components/charts/StackedBarChart.svelte +20 -18
- package/dist/components/charts/StackedBarChart.svelte.d.ts +8 -22
- package/dist/components/charts/StackedLineChart.svelte +23 -21
- package/dist/components/charts/StackedLineChart.svelte.d.ts +8 -22
- package/dist/components/charts/chart-config.d.ts +5 -5
- package/dist/components/charts/chart-config.js +722 -733
- package/dist/components/charts/index.d.ts +12 -0
- package/dist/components/charts/index.js +12 -0
- package/dist/components/charts/mermaid-chart-styles.css +27 -0
- package/dist/components/checkbox-styles.css +122 -117
- package/dist/components/crudview-styles.css +1057 -0
- package/dist/components/fileupload-styles.css +121 -117
- package/dist/components/filterbar-styles.css +655 -0
- package/dist/components/graph/FlowNode.svelte +82 -79
- package/dist/components/graph/FlowNode.svelte.d.ts +8 -28
- package/dist/components/graph/GraphNode.svelte +72 -69
- package/dist/components/graph/GraphNode.svelte.d.ts +8 -22
- package/dist/components/prism-manual.d.ts +0 -0
- package/dist/components/prism-manual.js +4 -0
- package/dist/components/radio-styles.css +118 -113
- package/dist/components/rating-styles.css +70 -65
- package/dist/components/select-styles.css +239 -11
- package/dist/components/slider-styles.css +85 -81
- package/dist/components/text-editor-core/dom-utils.d.ts +1 -1
- package/dist/components/text-editor-core/editor-core.d.ts +9 -9
- package/dist/components/text-editor-core/editor-core.js +854 -808
- package/dist/components/text-editor-core/sanitizer.d.ts +4 -1
- package/dist/components/text-editor-core/sanitizer.js +236 -161
- package/dist/components/text-editor-core/selection-engine.d.ts +3 -3
- package/dist/components/theme.css +59 -49
- package/dist/components/toast-styles.css +8 -8
- package/dist/components/toggle-styles.css +126 -121
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/config.svelte.d.ts +5 -4
- package/dist/config.svelte.js +124 -81
- package/dist/graph/geometry.d.ts +1 -1
- package/dist/graph/node-types.d.ts +1 -1
- package/dist/index.d.ts +4 -11
- package/dist/index.js +9 -12
- package/dist/themes/generator.js +175 -173
- package/dist/themes/presets.d.ts +21 -21
- package/dist/themes/presets.js +6 -6
- package/dist/utils/dbmr.d.ts +27 -0
- package/dist/utils/dbmr.js +381 -0
- package/dist/utils/filter.d.ts +103 -0
- package/dist/utils/filter.js +621 -0
- package/package.json +114 -85
- package/dist/components/multiselect-styles.css +0 -364
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { serializeDbmrQuery, serializeDbmrQueryBody } from "./filter.js";
|
|
2
|
+
|
|
3
|
+
function formatLabel(key) {
|
|
4
|
+
return String(key || "")
|
|
5
|
+
.replace(/[_-]+/g, " ")
|
|
6
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
7
|
+
.replace(/\b\w/g, (c) => c.toUpperCase())
|
|
8
|
+
.trim();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function mapDiscoveryType(rawType, mode, hasValues) {
|
|
12
|
+
if (mode === "fixed" && hasValues) return "select";
|
|
13
|
+
const t = String(rawType || "text").toLowerCase();
|
|
14
|
+
if (["select", "enum"].includes(t)) return "select";
|
|
15
|
+
if (["number", "integer", "int", "float", "double", "decimal", "numeric"].includes(t)) return "number";
|
|
16
|
+
if (["boolean", "bool"].includes(t)) return "boolean";
|
|
17
|
+
if (["date", "datetime", "timestamp", "time"].includes(t)) return "date";
|
|
18
|
+
if (["tags", "array", "list"].includes(t)) return "tags";
|
|
19
|
+
return "text";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes discovery metadata from either a `dbmr` `DISCOVER` response
|
|
24
|
+
* (`{ columns: [...] }`) or a custom/non-dbmr structure (`Array` or `{ fields: [...] }`)
|
|
25
|
+
* into `FilterBar` / `CrudView` field definitions.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object|Array|null} discovery
|
|
28
|
+
* @returns {Array<Object>} Normalized field definitions
|
|
29
|
+
*/
|
|
30
|
+
export function normalizeDiscovery(discovery) {
|
|
31
|
+
if (!discovery) return [];
|
|
32
|
+
|
|
33
|
+
const rawList = Array.isArray(discovery)
|
|
34
|
+
? discovery
|
|
35
|
+
: Array.isArray(discovery.columns)
|
|
36
|
+
? discovery.columns
|
|
37
|
+
: Array.isArray(discovery.fields)
|
|
38
|
+
? discovery.fields
|
|
39
|
+
: [];
|
|
40
|
+
|
|
41
|
+
const fields = [];
|
|
42
|
+
for (const col of rawList) {
|
|
43
|
+
if (!col) continue;
|
|
44
|
+
if (col.filterable === false) continue;
|
|
45
|
+
|
|
46
|
+
const key = col.key || col.name;
|
|
47
|
+
if (!key) continue;
|
|
48
|
+
|
|
49
|
+
const options = col.options ?? col.values ?? undefined;
|
|
50
|
+
const hasValues = Array.isArray(options) && options.length > 0;
|
|
51
|
+
const mode = col.mode || (col.searchable ? "searchable" : hasValues ? "fixed" : undefined);
|
|
52
|
+
const type = mapDiscoveryType(col.type, mode, hasValues);
|
|
53
|
+
|
|
54
|
+
const field = {
|
|
55
|
+
key,
|
|
56
|
+
label: col.label || formatLabel(key),
|
|
57
|
+
type
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (options !== undefined) field.options = options;
|
|
61
|
+
if (mode !== undefined) field.mode = mode;
|
|
62
|
+
if (col.minSearchChars !== undefined) {
|
|
63
|
+
field.minSearchChars = col.minSearchChars;
|
|
64
|
+
} else if (mode === "searchable") {
|
|
65
|
+
field.minSearchChars = 3;
|
|
66
|
+
}
|
|
67
|
+
if (col.onsearch) field.onsearch = col.onsearch;
|
|
68
|
+
if (col.sortable !== undefined) field.sortable = col.sortable;
|
|
69
|
+
if (col.primary !== undefined) field.primary = col.primary;
|
|
70
|
+
if (col.width !== undefined) field.width = col.width;
|
|
71
|
+
|
|
72
|
+
fields.push(field);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return fields;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Maps a `dbmr` `OPTIONS /resources` response (`{ resource, methods: [...] }`)
|
|
80
|
+
* or an array of HTTP methods into `CrudView` permission props.
|
|
81
|
+
*
|
|
82
|
+
* @param {Object|Array<string>} optionsResponse
|
|
83
|
+
* @returns {Object} `{ allowCreate, allowView, allowEdit, allowDelete, allowExport }`
|
|
84
|
+
*/
|
|
85
|
+
export function mapOptionsToCrudProps(optionsResponse) {
|
|
86
|
+
const rawMethods = Array.isArray(optionsResponse)
|
|
87
|
+
? optionsResponse
|
|
88
|
+
: Array.isArray(optionsResponse?.methods)
|
|
89
|
+
? optionsResponse.methods
|
|
90
|
+
: [];
|
|
91
|
+
|
|
92
|
+
const methods = new Set(rawMethods.map((m) => String(m).toUpperCase()));
|
|
93
|
+
return {
|
|
94
|
+
allowCreate: methods.has("POST"),
|
|
95
|
+
allowAdd: methods.has("POST"),
|
|
96
|
+
allowView: methods.has("GET") || methods.has("QUERY"),
|
|
97
|
+
allowEdit: methods.has("PUT") || methods.has("PATCH"),
|
|
98
|
+
allowDelete: methods.has("DELETE"),
|
|
99
|
+
allowExport: methods.has("GET")
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates a lightweight `dbmr` v0.0.3 HTTP client that pairs directly with `CrudView`.
|
|
105
|
+
* Supports `GET`/`QUERY` listing, `DISCOVER` column & autocomplete lookup, `OPTIONS`,
|
|
106
|
+
* `POST`/`PATCH`/`PUT`/`DELETE`, bulk delete, and optimistic locking (`ETag` / `version`).
|
|
107
|
+
*
|
|
108
|
+
* @param {string} baseUrl - Base resource URL (e.g. "/api/posts")
|
|
109
|
+
* @param {Object} [config]
|
|
110
|
+
* @returns {Object} dbmr client & `crudProps()` helper
|
|
111
|
+
*/
|
|
112
|
+
export function createDbmrClient(baseUrl, config = {}) {
|
|
113
|
+
const cleanBase = String(baseUrl || "").replace(/\/+$/, "");
|
|
114
|
+
const fetchFn = config.fetch || ((...args) => globalThis.fetch(...args));
|
|
115
|
+
const idField = config.idField || "id";
|
|
116
|
+
const versionField = config.versionField || "";
|
|
117
|
+
const primarySearchCol = config.primarySearchCol || "";
|
|
118
|
+
const selectColumns = config.selectColumns || [];
|
|
119
|
+
const include = config.include || [];
|
|
120
|
+
const useQueryMethod = config.useQueryMethod ?? "auto"; // "auto" | true | false
|
|
121
|
+
|
|
122
|
+
async function resolveHeaders(extra = {}) {
|
|
123
|
+
const baseHeaders = typeof config.headers === "function"
|
|
124
|
+
? await config.headers()
|
|
125
|
+
: (config.headers || {});
|
|
126
|
+
return {
|
|
127
|
+
Accept: "application/json",
|
|
128
|
+
...baseHeaders,
|
|
129
|
+
...extra
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function request(url, init = {}) {
|
|
134
|
+
const res = await fetchFn(url, init);
|
|
135
|
+
const etag = res.headers?.get?.("etag") || null;
|
|
136
|
+
const text = await res.text();
|
|
137
|
+
let payload = null;
|
|
138
|
+
if (text) {
|
|
139
|
+
try {
|
|
140
|
+
payload = JSON.parse(text);
|
|
141
|
+
} catch {
|
|
142
|
+
payload = text;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (!res.ok) {
|
|
146
|
+
const msg = (payload && typeof payload === "object" && payload.message)
|
|
147
|
+
? payload.message
|
|
148
|
+
: `Request failed (${res.status})`;
|
|
149
|
+
const err = new Error(msg);
|
|
150
|
+
err.status = res.status;
|
|
151
|
+
err.payload = payload;
|
|
152
|
+
throw err;
|
|
153
|
+
}
|
|
154
|
+
if (etag && payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
155
|
+
payload.__etag = etag;
|
|
156
|
+
}
|
|
157
|
+
return payload;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function list(params = {}) {
|
|
161
|
+
const queryOpts = {
|
|
162
|
+
search: params.search ?? "",
|
|
163
|
+
primarySearchCol,
|
|
164
|
+
filters: params.filters ?? [],
|
|
165
|
+
conjunction: params.conjunction ?? "and",
|
|
166
|
+
page: params.page ?? 1,
|
|
167
|
+
limit: params.perPage ?? params.limit ?? 10,
|
|
168
|
+
sortKey: params.sortKey ?? "",
|
|
169
|
+
sortDirection: params.sortDirection ?? "asc",
|
|
170
|
+
select: selectColumns,
|
|
171
|
+
include
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const shouldUseQuery =
|
|
175
|
+
useQueryMethod === true ||
|
|
176
|
+
(useQueryMethod === "auto" &&
|
|
177
|
+
(queryOpts.conjunction === "or" || (queryOpts.filters || []).length > 0));
|
|
178
|
+
|
|
179
|
+
if (shouldUseQuery) {
|
|
180
|
+
const body = serializeDbmrQueryBody(queryOpts);
|
|
181
|
+
const headers = await resolveHeaders({ "Content-Type": "application/json" });
|
|
182
|
+
return request(cleanBase, {
|
|
183
|
+
method: "QUERY",
|
|
184
|
+
headers,
|
|
185
|
+
body: JSON.stringify(body)
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const qs = serializeDbmrQuery(queryOpts);
|
|
190
|
+
const url = qs ? `${cleanBase}?${qs}` : cleanBase;
|
|
191
|
+
const headers = await resolveHeaders();
|
|
192
|
+
return request(url, { method: "GET", headers });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function discover(column = "", query = "") {
|
|
196
|
+
const headers = await resolveHeaders();
|
|
197
|
+
if (!column) {
|
|
198
|
+
return request(cleanBase, { method: "DISCOVER", headers });
|
|
199
|
+
}
|
|
200
|
+
const qs = new URLSearchParams({ column });
|
|
201
|
+
if (query) qs.set("q", query);
|
|
202
|
+
const res = await request(`${cleanBase}?${qs.toString()}`, {
|
|
203
|
+
method: "DISCOVER",
|
|
204
|
+
headers
|
|
205
|
+
});
|
|
206
|
+
return Array.isArray(res?.values) ? res.values : [];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async function options() {
|
|
210
|
+
const headers = await resolveHeaders();
|
|
211
|
+
const res = await request(cleanBase, { method: "OPTIONS", headers });
|
|
212
|
+
return {
|
|
213
|
+
...res,
|
|
214
|
+
crudProps: mapOptionsToCrudProps(res)
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function create(item) {
|
|
219
|
+
const headers = await resolveHeaders({ "Content-Type": "application/json" });
|
|
220
|
+
return request(cleanBase, {
|
|
221
|
+
method: "POST",
|
|
222
|
+
headers,
|
|
223
|
+
body: JSON.stringify(item)
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function bulkCreate(items) {
|
|
228
|
+
const headers = await resolveHeaders({ "Content-Type": "application/json" });
|
|
229
|
+
return request(cleanBase, {
|
|
230
|
+
method: "POST",
|
|
231
|
+
headers,
|
|
232
|
+
body: JSON.stringify({ data: items })
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function update(item, initialItem = null, opts = {}) {
|
|
237
|
+
const originalId = initialItem?.[idField];
|
|
238
|
+
const draftId = item?.[idField];
|
|
239
|
+
const id = originalId ?? draftId;
|
|
240
|
+
if (id === undefined || id === null || id === "") {
|
|
241
|
+
throw new Error(`Missing primary key "${idField}" for update`);
|
|
242
|
+
}
|
|
243
|
+
if (
|
|
244
|
+
originalId !== undefined &&
|
|
245
|
+
draftId !== undefined &&
|
|
246
|
+
String(originalId) !== String(draftId)
|
|
247
|
+
) {
|
|
248
|
+
throw new Error(`Cannot change primary key "${idField}" during update`);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const usePut = opts.fullReplace === true || !initialItem;
|
|
252
|
+
let payload = item;
|
|
253
|
+
if (!usePut) {
|
|
254
|
+
payload = {};
|
|
255
|
+
for (const k of Object.keys(item)) {
|
|
256
|
+
if (JSON.stringify(item[k]) !== JSON.stringify(initialItem[k])) {
|
|
257
|
+
payload[k] = item[k];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (versionField && item[versionField] !== undefined) {
|
|
261
|
+
payload[versionField] = item[versionField];
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const extraHeaders = { "Content-Type": "application/json" };
|
|
266
|
+
const etag = item?.__etag || initialItem?.__etag;
|
|
267
|
+
if (etag) {
|
|
268
|
+
extraHeaders["If-Match"] = etag;
|
|
269
|
+
} else if (versionField && (item?.[versionField] ?? initialItem?.[versionField]) !== undefined) {
|
|
270
|
+
extraHeaders["If-Match"] = String(item?.[versionField] ?? initialItem?.[versionField]);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const cleanPayload = { ...payload };
|
|
274
|
+
delete cleanPayload.__etag;
|
|
275
|
+
|
|
276
|
+
const headers = await resolveHeaders(extraHeaders);
|
|
277
|
+
return request(`${cleanBase}/${encodeURIComponent(id)}`, {
|
|
278
|
+
method: usePut ? "PUT" : "PATCH",
|
|
279
|
+
headers,
|
|
280
|
+
body: JSON.stringify(cleanPayload)
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function remove(item) {
|
|
285
|
+
const isObj = typeof item === "object" && item !== null;
|
|
286
|
+
const id = isObj ? item[idField] : item;
|
|
287
|
+
if (id === undefined || id === null || id === "") {
|
|
288
|
+
throw new Error(`Missing primary key "${idField}" for delete`);
|
|
289
|
+
}
|
|
290
|
+
const extraHeaders = {};
|
|
291
|
+
if (isObj) {
|
|
292
|
+
if (item.__etag) {
|
|
293
|
+
extraHeaders["If-Match"] = item.__etag;
|
|
294
|
+
} else if (versionField && item[versionField] !== undefined) {
|
|
295
|
+
extraHeaders["If-Match"] = String(item[versionField]);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const headers = await resolveHeaders(extraHeaders);
|
|
299
|
+
return request(`${cleanBase}/${encodeURIComponent(id)}`, {
|
|
300
|
+
method: "DELETE",
|
|
301
|
+
headers
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async function bulkRemove(items) {
|
|
306
|
+
const ids = (items || [])
|
|
307
|
+
.map((item) => (typeof item === "object" && item !== null ? item[idField] : item))
|
|
308
|
+
.filter((id) => id !== undefined && id !== null && id !== "");
|
|
309
|
+
if (ids.length === 0) return { rows: 0 };
|
|
310
|
+
|
|
311
|
+
const headers = await resolveHeaders({ "Content-Type": "application/json" });
|
|
312
|
+
return request(cleanBase, {
|
|
313
|
+
method: "DELETE",
|
|
314
|
+
headers,
|
|
315
|
+
body: JSON.stringify({ filter: [[[idField, "in", ids]]] })
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function exportUrl(params = {}, format = "csv") {
|
|
320
|
+
const conjunction = params.conjunction ?? "and";
|
|
321
|
+
const baseOpts = {
|
|
322
|
+
search: params.search ?? "",
|
|
323
|
+
primarySearchCol,
|
|
324
|
+
filters: conjunction === "or" ? [] : (params.filters ?? []),
|
|
325
|
+
sortKey: params.sortKey ?? "",
|
|
326
|
+
sortDirection: params.sortDirection ?? "asc",
|
|
327
|
+
select: selectColumns,
|
|
328
|
+
include,
|
|
329
|
+
page: null,
|
|
330
|
+
limit: config.exportLimit ?? 200
|
|
331
|
+
};
|
|
332
|
+
const qsParts = [];
|
|
333
|
+
const qs = serializeDbmrQuery(baseOpts);
|
|
334
|
+
if (qs) qsParts.push(qs);
|
|
335
|
+
|
|
336
|
+
if (conjunction === "or" && (params.filters || []).length > 0) {
|
|
337
|
+
const qBody = serializeDbmrQueryBody({
|
|
338
|
+
search: params.search ?? "",
|
|
339
|
+
primarySearchCol,
|
|
340
|
+
filters: params.filters ?? [],
|
|
341
|
+
conjunction: "or",
|
|
342
|
+
page: null,
|
|
343
|
+
limit: null
|
|
344
|
+
});
|
|
345
|
+
if (qBody.filter) {
|
|
346
|
+
qsParts.push(`filter=${encodeURIComponent(JSON.stringify(qBody.filter))}`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
qsParts.push(`output_content_type=${encodeURIComponent(format)}`);
|
|
351
|
+
return `${cleanBase}?${qsParts.join("&")}`;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return {
|
|
355
|
+
list,
|
|
356
|
+
discover,
|
|
357
|
+
options,
|
|
358
|
+
create,
|
|
359
|
+
bulkCreate,
|
|
360
|
+
update,
|
|
361
|
+
remove,
|
|
362
|
+
bulkRemove,
|
|
363
|
+
exportUrl,
|
|
364
|
+
crudHandlers() {
|
|
365
|
+
return {
|
|
366
|
+
serverSide: true,
|
|
367
|
+
onfiltersearch: (fieldKey, query) => discover(fieldKey, query),
|
|
368
|
+
onsave: async (draft, initial, meta) => {
|
|
369
|
+
if (meta?.isNew || draft?.[idField] === undefined || draft?.[idField] === "") {
|
|
370
|
+
const toCreate = { ...draft };
|
|
371
|
+
if (toCreate[idField] === "") delete toCreate[idField];
|
|
372
|
+
return create(toCreate);
|
|
373
|
+
}
|
|
374
|
+
return update(draft, initial);
|
|
375
|
+
},
|
|
376
|
+
ondelete: (item) => remove(item),
|
|
377
|
+
onbulkdelete: (items) => bulkRemove(items)
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export function getOperatorsForType(type?: string): any;
|
|
2
|
+
export function isUnaryOperator(operator: any, type?: string): boolean;
|
|
3
|
+
export function evaluateCondition(rawVal: any, operator: any, targetVal: any): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Filter an array of items according to Userflow filter rules, conjunction (and/or), and quick search.
|
|
6
|
+
*/
|
|
7
|
+
export function filterItems(items?: any[], options?: {}): any[];
|
|
8
|
+
/**
|
|
9
|
+
* Serializes FilterBar and CrudView filter rules into dbmr v0.0.3 URL query parameters.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} options
|
|
12
|
+
* @param {string} [options.search] - Free-text quick search
|
|
13
|
+
* @param {string} [options.primarySearchCol] - Optional column targeted by quick search; if omitted, uses dbmr `search=`
|
|
14
|
+
* @param {Array} [options.filters=[]] - Filter rules [{ field, operator, value }]
|
|
15
|
+
* @param {number} [options.page=1] - 1-based page index (converted to 0-based for dbmr unless zeroBasedPage is false)
|
|
16
|
+
* @param {boolean} [options.zeroBasedPage=true] - Whether to emit 0-based `page` (dbmr v0.0.3 default)
|
|
17
|
+
* @param {number} [options.limit=10] - Items per page (emitted as `size`)
|
|
18
|
+
* @param {string} [options.sortKey] - Column key to sort by
|
|
19
|
+
* @param {string} [options.sortDirection="asc"] - Sort direction ("asc" | "desc")
|
|
20
|
+
* @param {Array<string>} [options.select] - Fields to include (`select_columns`)
|
|
21
|
+
* @param {Array<string>} [options.include] - Relations to embed (e.g. ["chapters", "author"])
|
|
22
|
+
* @returns {string} URL query string (e.g. "page=0&size=10&sort=-created_at&status=published&price=>=10")
|
|
23
|
+
*/
|
|
24
|
+
export function serializeDbmrQuery(options?: {
|
|
25
|
+
search?: string;
|
|
26
|
+
primarySearchCol?: string;
|
|
27
|
+
filters?: any[];
|
|
28
|
+
page?: number;
|
|
29
|
+
zeroBasedPage?: boolean;
|
|
30
|
+
limit?: number;
|
|
31
|
+
sortKey?: string;
|
|
32
|
+
sortDirection?: string;
|
|
33
|
+
select?: Array<string>;
|
|
34
|
+
include?: Array<string>;
|
|
35
|
+
}): string;
|
|
36
|
+
/**
|
|
37
|
+
* Converts FilterBar/CrudView filter rules into dbmr's Filter AST (`[[["col","op",value],...],...]`),
|
|
38
|
+
* supporting both AND and OR conjunctions.
|
|
39
|
+
*
|
|
40
|
+
* @param {Array} [filters=[]] - Filter rules [{ field, operator, value }]
|
|
41
|
+
* @param {"and"|"or"} [conjunction="and"] - How rules are combined
|
|
42
|
+
* @returns {Array} OR-of-AND-groups filter AST
|
|
43
|
+
*/
|
|
44
|
+
export function buildDbmrFilterAst(filters?: any[], conjunction?: "and" | "or"): any[];
|
|
45
|
+
/**
|
|
46
|
+
* Serializes FilterBar / CrudView state into a JSON payload for dbmr's `QUERY` HTTP method.
|
|
47
|
+
*
|
|
48
|
+
* @param {Object} options
|
|
49
|
+
* @returns {Object} JSON body for `QUERY /resources`
|
|
50
|
+
*/
|
|
51
|
+
export function serializeDbmrQueryBody(options?: any): any;
|
|
52
|
+
export namespace OPERATORS_BY_TYPE {
|
|
53
|
+
let text: ({
|
|
54
|
+
key: string;
|
|
55
|
+
label: string;
|
|
56
|
+
unary?: undefined;
|
|
57
|
+
} | {
|
|
58
|
+
key: string;
|
|
59
|
+
label: string;
|
|
60
|
+
unary: boolean;
|
|
61
|
+
})[];
|
|
62
|
+
let select: ({
|
|
63
|
+
key: string;
|
|
64
|
+
label: string;
|
|
65
|
+
unary?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
key: string;
|
|
68
|
+
label: string;
|
|
69
|
+
unary: boolean;
|
|
70
|
+
})[];
|
|
71
|
+
let tags: ({
|
|
72
|
+
key: string;
|
|
73
|
+
label: string;
|
|
74
|
+
unary?: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
key: string;
|
|
77
|
+
label: string;
|
|
78
|
+
unary: boolean;
|
|
79
|
+
})[];
|
|
80
|
+
let number: ({
|
|
81
|
+
key: string;
|
|
82
|
+
label: string;
|
|
83
|
+
unary?: undefined;
|
|
84
|
+
} | {
|
|
85
|
+
key: string;
|
|
86
|
+
label: string;
|
|
87
|
+
unary: boolean;
|
|
88
|
+
})[];
|
|
89
|
+
let date: ({
|
|
90
|
+
key: string;
|
|
91
|
+
label: string;
|
|
92
|
+
unary?: undefined;
|
|
93
|
+
} | {
|
|
94
|
+
key: string;
|
|
95
|
+
label: string;
|
|
96
|
+
unary: boolean;
|
|
97
|
+
})[];
|
|
98
|
+
let boolean: {
|
|
99
|
+
key: string;
|
|
100
|
+
label: string;
|
|
101
|
+
unary: boolean;
|
|
102
|
+
}[];
|
|
103
|
+
}
|