add file system observer #38
2 changed files with 31 additions and 17 deletions
|
@ -1,4 +1,4 @@
|
|||
import { Component, createEffect, createMemo, createSignal, For, onMount, untrack } from 'solid-js';
|
||||
import { Component, createEffect, createMemo, createSignal, For, on, onMount, untrack } from 'solid-js';
|
||||
import { debounce } from '@solid-primitives/scheduled';
|
||||
import { createSelection, getTextNodes } from '@solid-primitives/selection';
|
||||
import { createSource } from '~/features/source';
|
||||
|
@ -18,12 +18,21 @@ interface TextareaProps {
|
|||
export function Textarea(props: TextareaProps) {
|
||||
const [selection, setSelection] = createSelection();
|
||||
const [editorRef, setEditorRef] = createSignal<HTMLElement>();
|
||||
let mounted = false;
|
||||
|
||||
const source = createSource(props.value);
|
||||
|
||||
createEffect(() => {
|
||||
props.oninput?.(source.in);
|
||||
});
|
||||
createEffect(on(() => [props.oninput, source.in] as const, ([oninput, text]) => {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
oninput?.(text);
|
||||
}));
|
||||
|
||||
onMount((() => {
|
||||
mounted = true;
|
||||
}));
|
||||
|
||||
createEffect(() => {
|
||||
source.in = props.value;
|
||||
|
@ -109,13 +118,19 @@ const Suggestions: Component = () => {
|
|||
const ref = untrack(() => suggestionRef()!);
|
||||
|
||||
if (m === undefined) {
|
||||
if (ref.matches(':popover-open')) {
|
||||
ref.hidePopover();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m.style.setProperty('anchor-name', '--suggestions');
|
||||
|
||||
if (ref.matches(':not(:popover-open)')) {
|
||||
ref.showPopover();
|
||||
}
|
||||
|
||||
ref.focus()
|
||||
|
||||
return m;
|
||||
|
|
|
@ -29,7 +29,7 @@ const groupBy = (rows: DataSetRowNode<number, Entry>[]) => {
|
|||
: ({ kind: 'group', key, groupedBy: 'key', nodes: group(nodes.map(n => ({ ...n, _key: n._key.slice(key.length + 1) }))) })
|
||||
);
|
||||
|
||||
return group(rows.map<R>(r => ({ ...r, _key: r.value.key }))) as any;
|
||||
return group(rows.filter(r => r.value.key).map<R>(r => ({ ...r, _key: r.value.key }))) as any;
|
||||
}
|
||||
|
||||
export function Grid(props: { class?: string, rows: Entry[], locales: string[], api?: (api: GridApi) => any, children?: (key: string) => JSX.Element }) {
|
||||
|
@ -65,19 +65,18 @@ export function Grid(props: { class?: string, rows: Entry[], locales: string[],
|
|||
const [api, setApi] = createSignal<GridCompApi<Entry>>();
|
||||
|
||||
// Normalize dataset in order to make sure all the files have the correct structure
|
||||
createEffect(() => {
|
||||
// For tracking
|
||||
props.rows;
|
||||
// const value = untrack(() => rows.value);
|
||||
// createEffect(() => {
|
||||
// // For tracking
|
||||
// props.rows;
|
||||
|
||||
rows.mutateEach(({ key, ...locales }) => ({ key, ...Object.fromEntries(Object.entries(locales).map(([locale, value]) => [locale, value ?? ''])) }))
|
||||
});
|
||||
// rows.mutateEach(({ key, ...locales }) => ({ key, ...Object.fromEntries(Object.entries(locales).map(([locale, value]) => [locale, value ?? ''])) }))
|
||||
// });
|
||||
|
||||
createEffect(() => {
|
||||
const l = addedLocales();
|
||||
// createEffect(() => {
|
||||
// const l = addedLocales();
|
||||
|
||||
rows.mutateEach(({ key, ...rest }) => ({ key, ...rest, ...Object.fromEntries(l.map(locale => [locale, rest[locale] ?? ''])) }));
|
||||
});
|
||||
// rows.mutateEach(({ key, ...rest }) => ({ key, ...rest, ...Object.fromEntries(l.map(locale => [locale, rest[locale] ?? ''])) }));
|
||||
// });
|
||||
|
||||
createEffect(() => {
|
||||
props.api?.({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue