add file system observer #38

Merged
chris-kruining merged 2 commits from experiment/fileSystemObserver into main 2025-03-05 14:56:07 +00:00
2 changed files with 31 additions and 17 deletions
Showing only changes of commit 7cdefe3f6e - Show all commits

View file

@ -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 { debounce } from '@solid-primitives/scheduled';
import { createSelection, getTextNodes } from '@solid-primitives/selection'; import { createSelection, getTextNodes } from '@solid-primitives/selection';
import { createSource } from '~/features/source'; import { createSource } from '~/features/source';
@ -18,12 +18,21 @@ interface TextareaProps {
export function Textarea(props: TextareaProps) { export function Textarea(props: TextareaProps) {
const [selection, setSelection] = createSelection(); const [selection, setSelection] = createSelection();
const [editorRef, setEditorRef] = createSignal<HTMLElement>(); const [editorRef, setEditorRef] = createSignal<HTMLElement>();
let mounted = false;
const source = createSource(props.value); const source = createSource(props.value);
createEffect(() => { createEffect(on(() => [props.oninput, source.in] as const, ([oninput, text]) => {
props.oninput?.(source.in); if (!mounted) {
}); return;
}
oninput?.(text);
}));
onMount((() => {
mounted = true;
}));
createEffect(() => { createEffect(() => {
source.in = props.value; source.in = props.value;
@ -109,13 +118,19 @@ const Suggestions: Component = () => {
const ref = untrack(() => suggestionRef()!); const ref = untrack(() => suggestionRef()!);
if (m === undefined) { if (m === undefined) {
ref.hidePopover(); if (ref.matches(':popover-open')) {
ref.hidePopover();
}
return; return;
} }
m.style.setProperty('anchor-name', '--suggestions'); m.style.setProperty('anchor-name', '--suggestions');
ref.showPopover();
if (ref.matches(':not(:popover-open)')) {
ref.showPopover();
}
ref.focus() ref.focus()
return m; return m;

View file

@ -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) }))) }) : ({ 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 }) { 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>>(); const [api, setApi] = createSignal<GridCompApi<Entry>>();
// Normalize dataset in order to make sure all the files have the correct structure // Normalize dataset in order to make sure all the files have the correct structure
createEffect(() => { // createEffect(() => {
// For tracking // // For tracking
props.rows; // props.rows;
// const value = untrack(() => rows.value);
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(() => { // createEffect(() => {
const l = addedLocales(); // 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(() => { createEffect(() => {
props.api?.({ props.api?.({