straplight 1.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/LICENSE +21 -0
- package/README.md +83 -0
- package/assets/icon.png +0 -0
- package/assets/screenshot.png +0 -0
- package/dist/_chunks/Settings-BLDXIWWB.js +166 -0
- package/dist/_chunks/Settings-CncfOILf.mjs +166 -0
- package/dist/_chunks/StraplightOverlay-DLEpUqQM.mjs +506 -0
- package/dist/_chunks/StraplightOverlay-dGd1yRZj.js +506 -0
- package/dist/_chunks/en-B4KWt_jN.js +4 -0
- package/dist/_chunks/en-Byx4XI2L.mjs +4 -0
- package/dist/_chunks/index-B2B6CFFk.mjs +82 -0
- package/dist/_chunks/index-CuzgWWKQ.js +103 -0
- package/dist/admin/index.js +3 -0
- package/dist/admin/index.mjs +4 -0
- package/dist/admin/src/components/StraplightOverlay.d.ts +1 -0
- package/dist/admin/src/components/StraplightPortal.d.ts +6 -0
- package/dist/admin/src/hooks/useStraplight.d.ts +23 -0
- package/dist/admin/src/hooks/useStraplightSettings.d.ts +6 -0
- package/dist/admin/src/index.d.ts +11 -0
- package/dist/admin/src/pages/Settings.d.ts +2 -0
- package/dist/admin/src/pluginId.d.ts +1 -0
- package/dist/admin/src/utils/getTranslation.d.ts +2 -0
- package/dist/server/index.js +263 -0
- package/dist/server/index.mjs +264 -0
- package/dist/server/src/bootstrap.d.ts +5 -0
- package/dist/server/src/config/index.d.ts +5 -0
- package/dist/server/src/content-types/index.d.ts +2 -0
- package/dist/server/src/controllers/controller.d.ts +7 -0
- package/dist/server/src/controllers/index.d.ts +14 -0
- package/dist/server/src/controllers/settings.d.ts +8 -0
- package/dist/server/src/destroy.d.ts +5 -0
- package/dist/server/src/index.d.ts +68 -0
- package/dist/server/src/middlewares/index.d.ts +2 -0
- package/dist/server/src/policies/index.d.ts +2 -0
- package/dist/server/src/register.d.ts +5 -0
- package/dist/server/src/routes/admin/index.d.ts +12 -0
- package/dist/server/src/routes/content-api/index.d.ts +5 -0
- package/dist/server/src/routes/index.d.ts +18 -0
- package/dist/server/src/services/index.d.ts +15 -0
- package/dist/server/src/services/service.d.ts +7 -0
- package/dist/server/src/services/settings.d.ts +28 -0
- package/dist/server/src/utils/content-type-helpers.d.ts +4 -0
- package/package.json +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bartosz Gamza
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/icon.png" width="120" alt="Straplight icon" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Straplight</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">Spotlight-like search overlay for the Strapi admin panel. Press <strong>Cmd+K</strong> (or <strong>Ctrl+K</strong>) to instantly search across all your content types.</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<img src="assets/screenshot.png" alt="Straplight search overlay" />
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Cmd+K search overlay** — opens a search dialog from anywhere in the admin panel
|
|
16
|
+
- **Full-text search** — searches across all string fields (title, name, text, email, richtext, etc.) in your `api::` content types
|
|
17
|
+
- **Keyboard navigation** — use arrow keys to navigate results, Enter to open, Escape to close
|
|
18
|
+
- **Debounced search** with stale-response protection — fast and flicker-free
|
|
19
|
+
- **Dark and light theme** support — follows your Strapi admin theme
|
|
20
|
+
- **Configurable** — fine-tune search behavior and choose which content types are searchable via the settings page
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install straplight
|
|
26
|
+
# or
|
|
27
|
+
yarn add straplight
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Add the plugin to your Strapi configuration:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
// config/plugins.ts
|
|
34
|
+
export default () => ({
|
|
35
|
+
straplight: {
|
|
36
|
+
enabled: true,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Rebuild your admin panel:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
yarn build
|
|
45
|
+
yarn develop
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
1. Press **Cmd+K** (macOS) or **Ctrl+K** (Windows/Linux) from anywhere in the admin panel
|
|
51
|
+
2. Start typing to search across all your content types
|
|
52
|
+
3. Use **Arrow Up/Down** to navigate results
|
|
53
|
+
4. Press **Enter** to open the selected entry in the Content Manager
|
|
54
|
+
5. Press **Escape** to close the overlay
|
|
55
|
+
|
|
56
|
+
## Settings
|
|
57
|
+
|
|
58
|
+
Navigate to **Settings > Straplight** in the admin panel to configure the plugin.
|
|
59
|
+
|
|
60
|
+
### General
|
|
61
|
+
|
|
62
|
+
| Setting | Description | Default |
|
|
63
|
+
| --- | --- | --- |
|
|
64
|
+
| **Delay** | Debounce delay in milliseconds before triggering a search | `200` |
|
|
65
|
+
| **Min characters** | Minimum query length required to trigger a search | `1` |
|
|
66
|
+
|
|
67
|
+
### Content Types
|
|
68
|
+
|
|
69
|
+
The content types table lets you control search behavior per content type:
|
|
70
|
+
|
|
71
|
+
- **Enabled** — toggle whether a content type is included in search results
|
|
72
|
+
- **Additional display fields** — choose up to 2 extra fields to show alongside the main field in search results (supports relations)
|
|
73
|
+
|
|
74
|
+
All `api::` content types are searchable by default.
|
|
75
|
+
|
|
76
|
+
## Compatibility
|
|
77
|
+
|
|
78
|
+
- Strapi v5 (5.x)
|
|
79
|
+
- Node.js >= 18
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
[MIT](LICENSE)
|
package/assets/icon.png
ADDED
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const admin = require("@strapi/strapi/admin");
|
|
6
|
+
const designSystem = require("@strapi/design-system");
|
|
7
|
+
const index = require("./index-CuzgWWKQ.js");
|
|
8
|
+
const DEFAULTS = {
|
|
9
|
+
debounceMs: 200,
|
|
10
|
+
minQueryLength: 1,
|
|
11
|
+
contentTypes: {}
|
|
12
|
+
};
|
|
13
|
+
function SettingsPage() {
|
|
14
|
+
const [settings, setSettings] = react.useState(DEFAULTS);
|
|
15
|
+
const [contentTypes, setContentTypes] = react.useState([]);
|
|
16
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
17
|
+
const [isSaving, setIsSaving] = react.useState(false);
|
|
18
|
+
const { toggleNotification } = admin.useNotification();
|
|
19
|
+
react.useEffect(() => {
|
|
20
|
+
const { get } = admin.getFetchClient();
|
|
21
|
+
get(`/${index.PLUGIN_ID}/settings`).then(({ data }) => {
|
|
22
|
+
setSettings({ ...DEFAULTS, ...data.settings });
|
|
23
|
+
setContentTypes(data.contentTypes || []);
|
|
24
|
+
}).catch(() => {
|
|
25
|
+
toggleNotification({
|
|
26
|
+
type: "danger",
|
|
27
|
+
message: "Failed to load settings"
|
|
28
|
+
});
|
|
29
|
+
}).finally(() => setIsLoading(false));
|
|
30
|
+
}, []);
|
|
31
|
+
const handleSave = async () => {
|
|
32
|
+
setIsSaving(true);
|
|
33
|
+
try {
|
|
34
|
+
const { put } = admin.getFetchClient();
|
|
35
|
+
const { data } = await put(`/${index.PLUGIN_ID}/settings`, settings);
|
|
36
|
+
setSettings({ ...DEFAULTS, ...data.settings });
|
|
37
|
+
toggleNotification({
|
|
38
|
+
type: "success",
|
|
39
|
+
message: "Settings saved successfully"
|
|
40
|
+
});
|
|
41
|
+
} catch {
|
|
42
|
+
toggleNotification({
|
|
43
|
+
type: "danger",
|
|
44
|
+
message: "Failed to save settings"
|
|
45
|
+
});
|
|
46
|
+
} finally {
|
|
47
|
+
setIsSaving(false);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const updateContentType = (uid, update) => {
|
|
51
|
+
setSettings((prev) => ({
|
|
52
|
+
...prev,
|
|
53
|
+
contentTypes: {
|
|
54
|
+
...prev.contentTypes,
|
|
55
|
+
[uid]: {
|
|
56
|
+
...{
|
|
57
|
+
enabled: prev.contentTypes[uid]?.enabled !== false,
|
|
58
|
+
displayFields: prev.contentTypes[uid]?.displayFields || []
|
|
59
|
+
},
|
|
60
|
+
...prev.contentTypes[uid],
|
|
61
|
+
...update
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
};
|
|
66
|
+
if (isLoading) {
|
|
67
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(admin.Layouts.Root, { children: [
|
|
68
|
+
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Header, { title: "Straplight", subtitle: "Configure the search overlay" }),
|
|
69
|
+
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: "Loading..." }) }) })
|
|
70
|
+
] });
|
|
71
|
+
}
|
|
72
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(admin.Layouts.Root, { children: [
|
|
73
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
74
|
+
admin.Layouts.Header,
|
|
75
|
+
{
|
|
76
|
+
title: "Straplight",
|
|
77
|
+
subtitle: "Configure the search overlay",
|
|
78
|
+
primaryAction: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: handleSave, loading: isSaving, children: "Save" })
|
|
79
|
+
}
|
|
80
|
+
),
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsxs(admin.Layouts.Content, { children: [
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 8, background: "neutral0", shadow: "filterShadow", hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
83
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h2", children: "General" }),
|
|
84
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 6, children: [
|
|
85
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, s: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { id: "delay-input", hint: "Debounce delay before triggering search (ms)", children: [
|
|
86
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Delay" }),
|
|
87
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
88
|
+
designSystem.NumberInput,
|
|
89
|
+
{
|
|
90
|
+
id: "delay-input",
|
|
91
|
+
name: "debounceMs",
|
|
92
|
+
value: settings.debounceMs,
|
|
93
|
+
onValueChange: (value) => setSettings((prev) => ({ ...prev, debounceMs: value ?? 200 })),
|
|
94
|
+
step: 50
|
|
95
|
+
}
|
|
96
|
+
),
|
|
97
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
|
|
98
|
+
] }) }),
|
|
99
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 6, s: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { id: "min-query-input", hint: "Minimum query length to trigger search", children: [
|
|
100
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Min characters" }),
|
|
101
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
102
|
+
designSystem.NumberInput,
|
|
103
|
+
{
|
|
104
|
+
label: "Min characters",
|
|
105
|
+
name: "minQueryLength",
|
|
106
|
+
value: settings.minQueryLength,
|
|
107
|
+
onValueChange: (value) => setSettings((prev) => ({ ...prev, minQueryLength: Math.max(1, value ?? 1) })),
|
|
108
|
+
step: 1
|
|
109
|
+
}
|
|
110
|
+
),
|
|
111
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
|
|
112
|
+
] }) })
|
|
113
|
+
] })
|
|
114
|
+
] }) }),
|
|
115
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 8, marginTop: 6, background: "neutral0", shadow: "filterShadow", hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
116
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "start", gap: 1, children: [
|
|
117
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h2", children: "Content Types" }),
|
|
118
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "Choose which content types are searchable and what fields to display in results" })
|
|
119
|
+
] }),
|
|
120
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: 3, rowCount: contentTypes.length, children: [
|
|
121
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
|
|
122
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Enabled" }) }),
|
|
123
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Content Type" }) }),
|
|
124
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Additional display fields" }) })
|
|
125
|
+
] }) }),
|
|
126
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: contentTypes.map((ct) => {
|
|
127
|
+
const ctSettings = settings.contentTypes[ct.uid];
|
|
128
|
+
const isEnabled = ctSettings?.enabled !== false;
|
|
129
|
+
const displayFields = ctSettings?.displayFields || [];
|
|
130
|
+
const availableFields = ct.fields.filter((f) => f.name !== ct.mainField);
|
|
131
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
|
|
132
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
133
|
+
designSystem.Switch,
|
|
134
|
+
{
|
|
135
|
+
checked: isEnabled,
|
|
136
|
+
onCheckedChange: (checked) => updateContentType(ct.uid, { enabled: checked }),
|
|
137
|
+
visibleLabels: true
|
|
138
|
+
}
|
|
139
|
+
) }),
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "start", gap: 1, children: [
|
|
141
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", children: ct.displayName }),
|
|
142
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: ct.uid })
|
|
143
|
+
] }) }),
|
|
144
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
145
|
+
designSystem.MultiSelect,
|
|
146
|
+
{
|
|
147
|
+
placeholder: "Select fields...",
|
|
148
|
+
value: displayFields,
|
|
149
|
+
onChange: (values) => {
|
|
150
|
+
if (values.length <= 2) {
|
|
151
|
+
updateContentType(ct.uid, { displayFields: values });
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
disabled: !isEnabled,
|
|
155
|
+
withTags: true,
|
|
156
|
+
children: availableFields.map((field) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.MultiSelectOption, { value: field.name, children: field.type === "relation" ? `${field.name} (${field.target})` : field.name }, field.name))
|
|
157
|
+
}
|
|
158
|
+
) })
|
|
159
|
+
] }, ct.uid);
|
|
160
|
+
}) })
|
|
161
|
+
] })
|
|
162
|
+
] }) })
|
|
163
|
+
] })
|
|
164
|
+
] });
|
|
165
|
+
}
|
|
166
|
+
exports.SettingsPage = SettingsPage;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { useNotification, getFetchClient, Layouts } from "@strapi/strapi/admin";
|
|
4
|
+
import { Box, Typography, Button, Flex, Grid, Field, NumberInput, Table, Thead, Tr, Th, Tbody, Td, Switch, MultiSelect, MultiSelectOption } from "@strapi/design-system";
|
|
5
|
+
import { P as PLUGIN_ID } from "./index-B2B6CFFk.mjs";
|
|
6
|
+
const DEFAULTS = {
|
|
7
|
+
debounceMs: 200,
|
|
8
|
+
minQueryLength: 1,
|
|
9
|
+
contentTypes: {}
|
|
10
|
+
};
|
|
11
|
+
function SettingsPage() {
|
|
12
|
+
const [settings, setSettings] = useState(DEFAULTS);
|
|
13
|
+
const [contentTypes, setContentTypes] = useState([]);
|
|
14
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
15
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
16
|
+
const { toggleNotification } = useNotification();
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const { get } = getFetchClient();
|
|
19
|
+
get(`/${PLUGIN_ID}/settings`).then(({ data }) => {
|
|
20
|
+
setSettings({ ...DEFAULTS, ...data.settings });
|
|
21
|
+
setContentTypes(data.contentTypes || []);
|
|
22
|
+
}).catch(() => {
|
|
23
|
+
toggleNotification({
|
|
24
|
+
type: "danger",
|
|
25
|
+
message: "Failed to load settings"
|
|
26
|
+
});
|
|
27
|
+
}).finally(() => setIsLoading(false));
|
|
28
|
+
}, []);
|
|
29
|
+
const handleSave = async () => {
|
|
30
|
+
setIsSaving(true);
|
|
31
|
+
try {
|
|
32
|
+
const { put } = getFetchClient();
|
|
33
|
+
const { data } = await put(`/${PLUGIN_ID}/settings`, settings);
|
|
34
|
+
setSettings({ ...DEFAULTS, ...data.settings });
|
|
35
|
+
toggleNotification({
|
|
36
|
+
type: "success",
|
|
37
|
+
message: "Settings saved successfully"
|
|
38
|
+
});
|
|
39
|
+
} catch {
|
|
40
|
+
toggleNotification({
|
|
41
|
+
type: "danger",
|
|
42
|
+
message: "Failed to save settings"
|
|
43
|
+
});
|
|
44
|
+
} finally {
|
|
45
|
+
setIsSaving(false);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const updateContentType = (uid, update) => {
|
|
49
|
+
setSettings((prev) => ({
|
|
50
|
+
...prev,
|
|
51
|
+
contentTypes: {
|
|
52
|
+
...prev.contentTypes,
|
|
53
|
+
[uid]: {
|
|
54
|
+
...{
|
|
55
|
+
enabled: prev.contentTypes[uid]?.enabled !== false,
|
|
56
|
+
displayFields: prev.contentTypes[uid]?.displayFields || []
|
|
57
|
+
},
|
|
58
|
+
...prev.contentTypes[uid],
|
|
59
|
+
...update
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
};
|
|
64
|
+
if (isLoading) {
|
|
65
|
+
return /* @__PURE__ */ jsxs(Layouts.Root, { children: [
|
|
66
|
+
/* @__PURE__ */ jsx(Layouts.Header, { title: "Straplight", subtitle: "Configure the search overlay" }),
|
|
67
|
+
/* @__PURE__ */ jsx(Layouts.Content, { children: /* @__PURE__ */ jsx(Box, { padding: 8, children: /* @__PURE__ */ jsx(Typography, { children: "Loading..." }) }) })
|
|
68
|
+
] });
|
|
69
|
+
}
|
|
70
|
+
return /* @__PURE__ */ jsxs(Layouts.Root, { children: [
|
|
71
|
+
/* @__PURE__ */ jsx(
|
|
72
|
+
Layouts.Header,
|
|
73
|
+
{
|
|
74
|
+
title: "Straplight",
|
|
75
|
+
subtitle: "Configure the search overlay",
|
|
76
|
+
primaryAction: /* @__PURE__ */ jsx(Button, { onClick: handleSave, loading: isSaving, children: "Save" })
|
|
77
|
+
}
|
|
78
|
+
),
|
|
79
|
+
/* @__PURE__ */ jsxs(Layouts.Content, { children: [
|
|
80
|
+
/* @__PURE__ */ jsx(Box, { padding: 8, background: "neutral0", shadow: "filterShadow", hasRadius: true, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
81
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", tag: "h2", children: "General" }),
|
|
82
|
+
/* @__PURE__ */ jsxs(Grid.Root, { gap: 6, children: [
|
|
83
|
+
/* @__PURE__ */ jsx(Grid.Item, { col: 6, s: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxs(Field.Root, { id: "delay-input", hint: "Debounce delay before triggering search (ms)", children: [
|
|
84
|
+
/* @__PURE__ */ jsx(Field.Label, { children: "Delay" }),
|
|
85
|
+
/* @__PURE__ */ jsx(
|
|
86
|
+
NumberInput,
|
|
87
|
+
{
|
|
88
|
+
id: "delay-input",
|
|
89
|
+
name: "debounceMs",
|
|
90
|
+
value: settings.debounceMs,
|
|
91
|
+
onValueChange: (value) => setSettings((prev) => ({ ...prev, debounceMs: value ?? 200 })),
|
|
92
|
+
step: 50
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
/* @__PURE__ */ jsx(Field.Hint, {})
|
|
96
|
+
] }) }),
|
|
97
|
+
/* @__PURE__ */ jsx(Grid.Item, { col: 6, s: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsxs(Field.Root, { id: "min-query-input", hint: "Minimum query length to trigger search", children: [
|
|
98
|
+
/* @__PURE__ */ jsx(Field.Label, { children: "Min characters" }),
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
NumberInput,
|
|
101
|
+
{
|
|
102
|
+
label: "Min characters",
|
|
103
|
+
name: "minQueryLength",
|
|
104
|
+
value: settings.minQueryLength,
|
|
105
|
+
onValueChange: (value) => setSettings((prev) => ({ ...prev, minQueryLength: Math.max(1, value ?? 1) })),
|
|
106
|
+
step: 1
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
/* @__PURE__ */ jsx(Field.Hint, {})
|
|
110
|
+
] }) })
|
|
111
|
+
] })
|
|
112
|
+
] }) }),
|
|
113
|
+
/* @__PURE__ */ jsx(Box, { padding: 8, marginTop: 6, background: "neutral0", shadow: "filterShadow", hasRadius: true, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
114
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "start", gap: 1, children: [
|
|
115
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", tag: "h2", children: "Content Types" }),
|
|
116
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: "Choose which content types are searchable and what fields to display in results" })
|
|
117
|
+
] }),
|
|
118
|
+
/* @__PURE__ */ jsxs(Table, { colCount: 3, rowCount: contentTypes.length, children: [
|
|
119
|
+
/* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
|
|
120
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Enabled" }) }),
|
|
121
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Content Type" }) }),
|
|
122
|
+
/* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: "Additional display fields" }) })
|
|
123
|
+
] }) }),
|
|
124
|
+
/* @__PURE__ */ jsx(Tbody, { children: contentTypes.map((ct) => {
|
|
125
|
+
const ctSettings = settings.contentTypes[ct.uid];
|
|
126
|
+
const isEnabled = ctSettings?.enabled !== false;
|
|
127
|
+
const displayFields = ctSettings?.displayFields || [];
|
|
128
|
+
const availableFields = ct.fields.filter((f) => f.name !== ct.mainField);
|
|
129
|
+
return /* @__PURE__ */ jsxs(Tr, { children: [
|
|
130
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(
|
|
131
|
+
Switch,
|
|
132
|
+
{
|
|
133
|
+
checked: isEnabled,
|
|
134
|
+
onCheckedChange: (checked) => updateContentType(ct.uid, { enabled: checked }),
|
|
135
|
+
visibleLabels: true
|
|
136
|
+
}
|
|
137
|
+
) }),
|
|
138
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "start", gap: 1, children: [
|
|
139
|
+
/* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: ct.displayName }),
|
|
140
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: ct.uid })
|
|
141
|
+
] }) }),
|
|
142
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(
|
|
143
|
+
MultiSelect,
|
|
144
|
+
{
|
|
145
|
+
placeholder: "Select fields...",
|
|
146
|
+
value: displayFields,
|
|
147
|
+
onChange: (values) => {
|
|
148
|
+
if (values.length <= 2) {
|
|
149
|
+
updateContentType(ct.uid, { displayFields: values });
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
disabled: !isEnabled,
|
|
153
|
+
withTags: true,
|
|
154
|
+
children: availableFields.map((field) => /* @__PURE__ */ jsx(MultiSelectOption, { value: field.name, children: field.type === "relation" ? `${field.name} (${field.target})` : field.name }, field.name))
|
|
155
|
+
}
|
|
156
|
+
) })
|
|
157
|
+
] }, ct.uid);
|
|
158
|
+
}) })
|
|
159
|
+
] })
|
|
160
|
+
] }) })
|
|
161
|
+
] })
|
|
162
|
+
] });
|
|
163
|
+
}
|
|
164
|
+
export {
|
|
165
|
+
SettingsPage
|
|
166
|
+
};
|