add quick and dirty decode function to handle escape characters in values
This commit is contained in:
parent
7264146d49
commit
a31168ca6c
2 changed files with 17 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
import { Accessor, Component, createEffect, createMemo, createSignal } from "solid-js";
|
||||
import { debounce, Mutation } from "~/utilities";
|
||||
import { debounce, decode, Mutation } from "~/utilities";
|
||||
import { Column, GridApi as GridCompApi, Grid as GridComp } from "~/components/grid";
|
||||
import { createDataSet, DataSetNode, DataSetRowNode } from "~/components/table";
|
||||
import { SelectionItem } from "../selectable";
|
||||
|
@ -109,10 +109,12 @@ const TextArea: Component<{ row: number, key: string, lang: string, value: strin
|
|||
mutate();
|
||||
};
|
||||
|
||||
const value = createMemo(() => decode(props.value));
|
||||
|
||||
return <textarea
|
||||
ref={setElement}
|
||||
class={css.textarea}
|
||||
value={props.value}
|
||||
value={value()}
|
||||
lang={props.lang}
|
||||
placeholder={`${props.key} in ${props.lang}`}
|
||||
name={`${props.row}[${props.lang}]`}
|
||||
|
|
|
@ -10,6 +10,19 @@ export const splitAt = (subject: string, index: number): readonly [string, strin
|
|||
return [subject.slice(0, index), subject.slice(index + 1)];
|
||||
};
|
||||
|
||||
const decodeRegex = /(?<!\\)\\(t|b|n|r|f|'|"|u[0-9a-f]{1,4})/gi;
|
||||
const decodeReplacer = (_: any, char: string) => ({
|
||||
t: '\t',
|
||||
b: '\b',
|
||||
n: '\n',
|
||||
r: '\r',
|
||||
f: '\f',
|
||||
"'": '\'',
|
||||
'"': '\"',
|
||||
u: String.fromCharCode(Number.parseInt(char.slice(1))),
|
||||
}[char.charAt(0)] ?? '');
|
||||
export const decode = (subject: string): string => subject.replace(decodeRegex, decodeReplacer);
|
||||
|
||||
export const debounce = <T extends (...args: any[]) => void>(callback: T, delay: number): ((...args: Parameters<T>) => void) => {
|
||||
let handle: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue