-
Notifications
You must be signed in to change notification settings - Fork 0
Release/v1.2.5 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release/v1.2.5 #13
Changes from all commits
7c1e6eb
839cd83
c9342ae
dd87efb
bc952db
84d8fb8
d50292b
f5d6f79
290f8ae
0812697
223af2a
0d4550c
c8e63a6
b4442a8
0d6928c
5c1099e
a7fa78c
75f5812
46eca91
bbbe858
f9e8f0b
e89b415
1ec97d3
17ac822
4028c50
f75f457
db0718e
e693078
d91a61d
82296b6
007e057
e4f4883
fcbf9b7
27d66ea
9b75f25
e834331
821d3a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| "name": "prompt-library", | ||
| "private": false, | ||
| "description": "A modern, sleek web application for managing AI prompts. Built with React, TypeScript, and Vite.", | ||
| "version": "1.2.5", | ||
| "version": "1.2.8", | ||
| "author": "Ivan Andrei (NaviAndrei)", | ||
|
Comment on lines
3
to
6
|
||
| "license": "MIT", | ||
| "type": "module", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ interface VariableInfo { | |
| name: string; | ||
| type: string; | ||
| raw: string; | ||
| hint?: string; | ||
| } | ||
|
|
||
| interface VariablePreset { | ||
|
|
@@ -34,22 +35,36 @@ const TYPE_MAP: Record<string, string> = { | |
|
|
||
| // Detects all unique variables of type {{name:type:options}} from text | ||
| function extractVariables(text: string): (VariableInfo & { options?: string[] })[] { | ||
| const regex = /\{\{(\w+)(?::(\w+))?(?::([^}]+))?\}\}/g; | ||
| // Permissive regex to support {{var}}, {{var:type}}, {{var:select:a,b}}, and {{var=hint}} | ||
| const regex = /\{\{([\w\s-]+)(?:[:=]([^}]+))?\}\}/g; | ||
| const seen = new Set<string>(); | ||
| const variables: (VariableInfo & { options?: string[] })[] = []; | ||
|
|
||
| let match; | ||
| while ((match = regex.exec(text)) !== null) { | ||
| const name = match[1]; | ||
| const typeHint = (match[2] || 'text').toLowerCase(); | ||
| const optionsRaw = match[3]; | ||
| const name = match[1].trim(); | ||
| const fullHint = (match[2] || '').trim(); | ||
|
|
||
| if (!seen.has(name)) { | ||
| seen.add(name); | ||
|
|
||
| // Extract type and options if colon syntax is used | ||
| let typeHint = 'text'; | ||
| let optionsRaw = ''; | ||
|
|
||
| if (fullHint.includes(':')) { | ||
| const parts = fullHint.split(':'); | ||
| typeHint = parts[0].toLowerCase(); | ||
| optionsRaw = parts.slice(1).join(':'); | ||
| } else if (fullHint && !fullHint.includes('=') && TYPE_MAP[fullHint.toLowerCase()]) { | ||
|
Comment on lines
+55
to
+59
|
||
| // If it's a recognized type (e.g. {{date:date}}), use it | ||
| typeHint = fullHint.toLowerCase(); | ||
| } | ||
| const info: VariableInfo & { options?: string[] } = { | ||
| name, | ||
| type: TYPE_MAP[typeHint] || 'text', | ||
| raw: match[0], | ||
| hint: fullHint && !TYPE_MAP[fullHint.toLowerCase()] && !fullHint.includes(':') ? fullHint : undefined, | ||
| }; | ||
|
|
||
| if (typeHint === 'select' && optionsRaw) { | ||
|
|
@@ -62,10 +77,13 @@ function extractVariables(text: string): (VariableInfo & { options?: string[] }) | |
| return variables; | ||
| } | ||
|
|
||
| // Replaces all occurrences of {{variable}} or {{variable:type}} with the corresponding value | ||
| function injectVariables(text: string, values: Record<string, string>): string { | ||
| return text.replace(/\{\{(\w+)(?::(\w+))?(?::([^}]+))?\}\}/g, (_, name) => { | ||
| return values[name] !== undefined && values[name] !== '' ? values[name] : `{{${name}}}`; | ||
| const regex = /\{\{([\w\s-]+)(?:[:=]([^}]+))?\}\}/g; | ||
| return text.replace(regex, (fullMatch, name) => { | ||
| const trimmedName = name.trim(); | ||
| return values[trimmedName] !== undefined && values[trimmedName] !== '' | ||
| ? values[trimmedName] | ||
| : fullMatch; | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -187,7 +205,7 @@ export function VariableInjector({ body }: VariableInjectorProps) { | |
| <input | ||
| type={v.type} | ||
| className={`variable-input ${v.type === 'number' ? 'variable-input-number' : ''}`} | ||
| placeholder={`Value for ${v.name}`} | ||
| placeholder={v.hint || `Value for ${v.name}`} | ||
| value={values[v.name] || ''} | ||
| onChange={e => handleChange(v.name, e.target.value)} | ||
| aria-label={`Enter value for variable ${v.name}`} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 1.2.6 changelog entry lists multiple fixes (Vite/Rolldown compile conflicts, FlexSearch typings, peer deps, IndexedDB hook compatibility) that are not part of this PR diff. Please ensure each changelog entry matches the actual code included in the corresponding version (move/remove items as needed), and keep language consistent with the rest of the changelog.