### Example Usage of mime-match
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/licenses/supplemental/mime-match/README.md
Demonstrates how to use the mime-match function to check if a target mime type matches a pattern, including exact matches, wildcard matches, filtering an array of patterns, and ignoring charset suffixes.
```javascript
var match = require('mime-match/');
// exact match
console.log(match('image/jpeg', 'image/jpeg'));
// --> true
// wildcard match
console.log(match('image/jpeg', 'image/*'));
// --> true
// find which of our wildcard patterns matches a specific mimetype
console.log(['application/*', 'image/*'].filter(match('image/jpeg')));
// --> ['image/*']
// charset suffix is ignored
console.log(match('application/json', 'application/json; charset=utf-8'));
// --> true
```
--------------------------------
### FieldHookComponent implementation example
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/frontend/src/components/dynamic-form/README.md
Defines a custom hook component that receives fieldPath, value, and onChange props. It renders a button to add rules to an array value.
```typescript
import type { FieldHookComponent } from '@/lib/field-hooks'
export const TalkValueRulesHook: FieldHookComponent = ({
fieldPath,
value,
onChange
}) => {
const rules = Array.isArray(value) ? value : []
return (
{fieldPath}
)
}
```
--------------------------------
### Wildcard matching with strings
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/licenses/supplemental/wildcard/README.md
Use wildcard('foo.*', 'foo.bar') to match a string against a pattern. Returns true when the pattern matches the string.
```javascript
var wildcard = require('wildcard');
console.log(wildcard('foo.*', 'foo.bar'));
// --> true
console.log(wildcard('foo.*', 'foo'));
// --> true
```
--------------------------------
### Wildcard matching with objects
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/licenses/supplemental/wildcard/README.md
Use wildcard('a.*.c', testdata) to match against object keys. Returns an object containing only the matching key-value pairs.
```javascript
var wildcard = require('wildcard');
var testdata = {
'a.b.c' : {},
'a.b' : {},
'a' : {},
'a.b.d' : {}
};
console.log(wildcard('a.*.c', testdata));
// --> { 'a.b.c': {} }
```
--------------------------------
### DynamicConfigForm
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/frontend/src/components/dynamic-form/README.md
The main component that takes a ConfigSchema and renders the entire form. It accepts schema, values, onChange, and optional hooks props.
```APIDOC
## DynamicConfigForm
### Description
The main component that takes a `ConfigSchema` and renders the entire form. It accepts schema, values, onChange, and optional hooks props.
### Props
- `schema` (ConfigSchema) - Required - The schema generated by the backend.
- `values` (Record) - Required - Current configuration values.
- `onChange` ((field: string, value: any) => void) - Required - Change handler.
- `hooks` (FieldHookRegistry) - Optional - Optional custom hook registry.
### Example
```typescript
import { DynamicConfigForm } from '@/components/dynamic-form'
import { fieldHooks } from '@/lib/field-hooks'
export function ConfigPage() {
const [config, setConfig] = useState({})
const schema = useConfigSchema() // Fetch from API
const handleChange = (fieldPath: string, value: unknown) => {
updateConfigAt(fieldPath, value)
}
return (
)
}
```
```
--------------------------------
### DynamicConfigForm usage in a React component
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/frontend/src/components/dynamic-form/README.md
Imports DynamicConfigForm and fieldHooks, then renders the form with schema, values, onChange, and hooks props. The onChange handler receives a nested fieldPath like 'section.subfield'.
```typescript
import { DynamicConfigForm } from '@/components/dynamic-form'
import { fieldHooks } from '@/lib/field-hooks'
// Example usage in a component
export function ConfigPage() {
const [config, setConfig] = useState({})
const schema = useConfigSchema() // Fetch from API
const handleChange = (fieldPath: string, value: unknown) => {
// fieldPath can be nested, e.g., 'section.subfield'
updateConfigAt(fieldPath, value)
}
return (
)
}
```
--------------------------------
### FieldHookComponent
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/frontend/src/components/dynamic-form/README.md
Interface for hook components. Receives fieldPath, value, onChange, and optionally children for wrapper hooks.
```APIDOC
## FieldHookComponent
### Description
Interface for hook components. Receives fieldPath, value, onChange, and optionally children for wrapper hooks.
### Props
- `fieldPath` (string) - Required - The full path to the field.
- `value` (any) - Required - The current value of the field/section.
- `onChange` (function) - Required - Callback to update the value.
- `children` (ReactNode) - Optional - (Only for `wrapper` hooks) The default field renderer.
### Example
```typescript
import type { FieldHookComponent } from '@/lib/field-hooks'
export const TalkValueRulesHook: FieldHookComponent = ({
fieldPath,
value,
onChange
}) => {
const rules = Array.isArray(value) ? value : []
return (
{fieldPath}
)
}
```
```
--------------------------------
### Wildcard matching with arrays
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/licenses/supplemental/wildcard/README.md
Use wildcard('a.b.*', testdata) to filter an array of strings. Returns an array of elements that match the pattern.
```javascript
var wildcard = require('wildcard');
var testdata = [
'a.b.c',
'a.b',
'a',
'a.b.d'
];
console.log(wildcard('a.b.*', testdata));
// --> ['a.b.c', 'a.b', 'a.b.d']
```
--------------------------------
### FieldHookRegistry
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/frontend/src/components/dynamic-form/README.md
A registry for custom React components that can replace or wrap default field rendering. Provides methods to register, retrieve, check, and unregister hooks.
```APIDOC
## FieldHookRegistry
### Description
A registry for custom React components that can replace or wrap default field rendering. Provides methods to register, retrieve, check, and unregister hooks.
### Methods
- `register(path, component, type)` - Register a hook.
- `get(path)` - Retrieve a registered hook.
- `has(path)` - Check if a hook exists.
- `unregister(path)` - Remove a hook.
### Example
```typescript
useEffect(() => {
fieldHooks.register('chat.reply_timing.talk_value_rules', TalkValueRulesHook, 'replace')
return () => fieldHooks.unregister('chat.reply_timing.talk_value_rules')
}, [])
```
```
--------------------------------
### Registering a hook with fieldHooks
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/frontend/src/components/dynamic-form/README.md
Registers a hook for the field path 'chat.reply_timing.talk_value_rules' with type 'replace' inside a useEffect, and unregisters it on cleanup.
```typescript
useEffect(() => {
fieldHooks.register('chat.reply_timing.talk_value_rules', TalkValueRulesHook, 'replace')
return () => fieldHooks.unregister('chat.reply_timing.talk_value_rules')
}, [])
```
--------------------------------
### Pydantic field with slider metadata
Source: https://github.com/bagpipe1289/dsh-paperflight/blob/main/frontend/src/components/dynamic-form/README.md
Defines a ChatConfig field with json_schema_extra specifying x-widget: 'slider' and step: 0.1. Requires ge and le for the slider range.
```python
class ChatConfig(ConfigBase):
talk_value: float = Field(
default=0.5,
ge=0.0,
le=1.0,
json_schema_extra={
"x-widget": "slider",
"step": 0.1
}
)
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.