diff --git a/src/lib/components/dictionary/test/page/tabs/calculation.svelte b/src/lib/components/dictionary/test/page/tabs/calculation.svelte index cb3d6fa..2c4c8f4 100644 --- a/src/lib/components/dictionary/test/page/tabs/calculation.svelte +++ b/src/lib/components/dictionary/test/page/tabs/calculation.svelte @@ -18,9 +18,6 @@ let cursorIndex = $state(0); let showLiteralPopover = $state(false); let literalPopoverType = $state(('string')); -$inspect(tokens) - // let expression = $state(''); - // let cursorPosition = $state(0); function uid() { return Math.random().toString(36).slice(2, 9); @@ -106,92 +103,6 @@ $inspect(tokens) props.calFormState.form[key] = []; props.calFormState.validateField?.(key, [], false); } - - // function unselectAll(key) { - // props.calFormState.form[key] = []; - // props.calFormState.validateField?.(key, [], false); - // } - - // function getErrorStatus(formulaCode = '') { - // const selected = props.calFormState.form.FormulaInput; - // if (!Array.isArray(selected)) return []; - - // return selected.map((item) => ({ - // value: item.value, - // done: new RegExp(`\\b${item.value}\\b`, 'i').test(formulaCode) - // })); - // } - - // function addToExpression(text) { - // const before = expression.slice(0, cursorPosition); - // const after = expression.slice(cursorPosition); - // expression = before + text + after; - // cursorPosition += text.length; - // } - - // function addOperator(op) { - // addToExpression(op); - // props.calFormState.form.FormulaCode = expression; - // props.calFormState.validateField?.('FormulaCode', expression, false); - // } - - // function addValue(val) { - // addToExpression(val); - // props.calFormState.form.FormulaCode = expression; - // props.calFormState.validateField?.('FormulaCode', expression, false); - // } - - // function handleInput(e) { - // expression = e.target.value; - // cursorPosition = e.target.selectionStart; - // formState.form.FormulaCode = expression; - // formState.validateField?.('FormulaCode', expression, false); - // } - - // function handleClick(e) { - // cursorPosition = e.target.selectionStart; - // } - - // function handleContainerClick(e) { - // const rect = e.currentTarget.getBoundingClientRect(); - // const text = expression; - // const charWidth = 8.5; - // const padding = 12; - // const clickX = e.clientX - rect.left - padding; - // let newPos = Math.floor(clickX / charWidth); - // newPos = Math.max(0, Math.min(newPos, text.length)); - // cursorPosition = newPos; - // } - - // function moveCursorLeft() { - // if (cursorPosition > 0) { - // cursorPosition -= 1; - // } - // } - - // function moveCursorRight() { - // if (cursorPosition < expression.length) { - // cursorPosition += 1; - // } - // } - - // function deleteChar() { - // if (cursorPosition > 0) { - // const before = expression.slice(0, cursorPosition - 1); - // const after = expression.slice(cursorPosition); - // expression = before + after; - // cursorPosition -= 1; - // props.calFormState.form.FormulaCode = expression; - // props.calFormState.validateField?.('FormulaCode', expression, false); - // } - // } - - // function clearExpression() { - // expression = ''; - // cursorPosition = 0; - // props.calFormState.form.FormulaCode = expression; - // props.calFormState.validateField?.('FormulaCode', expression, false); - // }
diff --git a/src/lib/components/reusable/form/dictionary-form-renderer.svelte b/src/lib/components/reusable/form/dictionary-form-renderer.svelte index 5f5ab99..a580d46 100644 --- a/src/lib/components/reusable/form/dictionary-form-renderer.svelte +++ b/src/lib/components/reusable/form/dictionary-form-renderer.svelte @@ -126,6 +126,20 @@ {#if required} * {/if} + {#if key === 'FormulaCode' && formState.form.FormulaInput?.length} + {@const inputStatus = onGetErrorStatus?.()} +
+ Must included : + +
+ {#each inputStatus as item (item.value)} + + {item.value} + + {/each} +
+
+ {/if}
@@ -487,52 +501,49 @@
{ - if (e.key === 'Backspace') { e.preventDefault(); onDeleteChar(); } - if (e.key === 'ArrowLeft') onMoveCursorLeft(); - if (e.key === 'ArrowRight') onMoveCursorRight(); - }} - > - {#if tokens.length === 0} - Click buttons below to build formula... - {:else} - - {@const lines = (() => { - const result = [[]]; - tokens.forEach((tok, idx) => { - if (tok.type === 'newline') result.push([]); - else result[result.length - 1].push({ tok, idx }); - }); - return result; - })()} - {#each lines as line, lineIdx} -
- {#each line as { tok, idx }} - {#if cursorIndex === idx} - - {/if} - + class="relative flex-1 min-h-[2rem] rounded-md border bg-background px-3 py-2 font-mono text-sm cursor-text focus-within:ring-1 focus-within:ring-ring" + role="textbox" + tabindex="0" + onkeydown={(e) => { + if (e.key === 'Backspace') { e.preventDefault(); onDeleteChar(); } + if (e.key === 'ArrowLeft') onMoveCursorLeft(); + if (e.key === 'ArrowRight') onMoveCursorRight(); + }} + > + {#if tokens.length === 0} + Select test then click buttons below to build formula + {:else} + {@const lines = (() => { + const result = [[]]; + tokens.forEach((tok, idx) => { + if (tok.type === 'newline') result.push([]); + else result[result.length - 1].push({ tok, idx }); + }); + return result; + })()} + {#each lines as line, lineIdx} +
+ {#each line as { tok, idx }} + {#if cursorIndex === idx} + + {/if} + + {/each} + {#if line.length > 0 && cursorIndex === line[line.length - 1].idx + 1} + + {:else if line.length === 0 && lineIdx === lines.length - 1} + + {/if} +
{/each} - {#if line.length > 0 && cursorIndex === line[line.length - 1].idx + 1} - - {/if} -
- {/each} - {#if cursorIndex === tokens.length && (tokens.length === 0 || tokens[tokens.length - 1].type === 'newline')} - - {/if} - {/if} -
+ {/if} +
@@ -545,187 +556,184 @@ - + {#if formState.form.FormulaInput?.length > 0} -
- -
- Selected Tests -
- {#each formState.form.FormulaInput as item (item)} - - {/each} -
-
- - -
- Custom Values -
- - - - {#snippet child({ props: triggerProps })} - - {/snippet} - - -
-
-

Enter Text Value

- { - if (e.key === 'Enter' && stringLiteralInput.trim()) { - onAddLiteral(`"${stringLiteralInput.trim()}"`); - stringLiteralInput = ''; - } - }} - /> -
+
+
+ +
+ {#each formState.form.FormulaInput as item (item)} -
+ {/each} +
+
+ + +
+ +
+ + + {#snippet child({ props: triggerProps })} + + {/snippet} + + +
+
+

Enter Text Value

+ { + if (e.key === 'Enter' && stringLiteralInput.trim()) { + onAddLiteral(`"${stringLiteralInput.trim()}"`); + stringLiteralInput = ''; + } + }} + /> +
+ +
+
+
+
+
+ + + + {#snippet child({ props: triggerProps })} + + {/snippet} + + +
+
+

Enter Number Value

+ { + if (e.key === 'Enter' && numberLiteralInput != null && !isNaN(numberLiteralInput)) { + onAddLiteral(String(numberLiteralInput)); + numberLiteralInput = null; + } + }} + /> +
+ +
+
+
+
+
+
+
+ +
+ +
+ {#each logicalop as op} + + {/each} +
+
+ + +
+ +
+ {#each comparisonop as op} + + {/each} +
+
+ + +
+ +
+ {#each operators as op} + + {/each} +
+
+ + {#if tokens.length > 0} +
+ +
+
{expressionString}
- - - - - - - {#snippet child({ props: triggerProps })} - - {/snippet} - - -
-
-

Enter Number Value

- { - if (e.key === 'Enter' && numberLiteralInput != null && !isNaN(numberLiteralInput)) { - onAddLiteral(String(numberLiteralInput)); - numberLiteralInput = null; - } - }} - /> -
- -
-
-
-
-
-
-
- - -
- Logical Operators -
- {#each logicalop as op} - - {/each} -
-
- - -
- Comparison Operators -
- {#each comparisonop as op} - - {/each} -
-
- - -
- Math Operators -
- {#each operators as op} - - {/each} -
-
- - - {#if tokens.length > 0} -
- -
{expressionString}
-
- {/if} -
- {/if} + {/if} +
+ {/if}
{:else if type === 'members'} {@const filteredOptions = getFilteredOptions(key)} @@ -814,22 +822,6 @@ {errorMessage}
{/if} - {#if key === 'FormulaCode' && formState.form.FormulaInput?.length} - {@const inputStatus = onGetErrorStatus?.()} - - -
- Must included : - -
- {#each inputStatus as item (item.value)} - - {item.value} - - {/each} -
-
- {/if}