Skip to content

Commit

Permalink
Merge pull request #19 from chris-kruining/feature/add-language
Browse files Browse the repository at this point in the history
[ Add language
  • Loading branch information
chris-kruining authored Dec 19, 2024
2 parents 7aab9b2 + 1b18198 commit aadc272
Show file tree
Hide file tree
Showing 43 changed files with 2,618 additions and 689 deletions.
4 changes: 4 additions & 0 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export default defineConfig({
html: {
cspNonce: 'KAAS_IS_AWESOME',
},
// css: {
// postcss: {
// },
// },
plugins: [
solidSvg()
// VitePWA({
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[test]
coverage = true
coverageSkipTestFiles = true
coverageReporter = ['text', 'lcov']
coverageDir = './.coverage'
preload = "./test.config.ts"
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "calque",
"dependencies": {
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.15.1",
"@solidjs/router": "^0.15.2",
"@solidjs/start": "^1.0.10",
"dexie": "^4.0.10",
"iterator-helpers-polyfill": "^3.0.1",
"sitemap": "^8.0.0",
"solid-icons": "^1.1.0",
"solid-js": "^1.9.3",
"ts-pattern": "^5.5.0",
"ts-pattern": "^5.6.0",
"vinxi": "^0.4.3"
},
"engines": {
Expand Down
51 changes: 44 additions & 7 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,32 @@
--surface-600: oklch(from var(--surface-500) calc(l + .025) c h);
--surface-700: oklch(from var(--surface-600) calc(l + .025) c h);

--text-1: light-dark(oklch(from var(--primary-500) .2 .02 h), oklch(from var(--primary-500) .9 .02 h));
--text-2: oklch(from var(--text-1) calc(l + .1) c h);

--info: light-dark(oklch(.71 .17 249), oklch(.71 .17 249));
--fail: light-dark(oklch(.64 .21 25.3), oklch(.64 .21 25.3));
--warn: light-dark(oklch(.82 .18 78.9), oklch(.82 .18 78.9));
--succ: light-dark(oklch(.86 .28 150), oklch(.86 .28 150));

--radii-s: .125em;
--radii-m: .25em;
--radii-l: .5em;
--radii-xl: 1em;
--text-1: light-dark(oklch(from var(--primary-500) .2 .02 h), oklch(from var(--primary-500) .9 .02 h));
--text-2: oklch(from var(--text-1) calc(l + .1) c h);

--text-lighter: 100;
--text-light: 300;
--text-normal: 500;
--text-bold: 700;
--text-bolder: 900;

--text-s: .8rem;
--text-m: 1rem;
--text-l: 1.25rem;
--text-xl: 1.6rem;
--text-xxl: 2rem;

--radii-s: .125em;
--radii-m: .25em;
--radii-l: .5em;
--radii-xl: 1em;

--padding-xs: .125em;
--padding-s: .25em;
--padding-m: .5em;
--padding-l: .75em;
Expand Down Expand Up @@ -144,6 +151,36 @@ code {
border-radius: var(--radii-m);
}

ins {
background-color: oklch(from var(--succ) l c h / .1);
color: oklch(from var(--succ) .1 .2 h);
}

del {
background-color: oklch(from var(--fail) l c h / .1);
color: oklch(from var(--fail) .1 .2 h);
}

kbd {
background-color: var(--surface-600);
border-radius: var(--radii-m);
border: 1px solid var(--surface-500);
box-shadow:
0 1px 1px rgba(0, 0, 0, 0.2),
0 2px 0 0 rgba(255, 255, 255, 0.7) inset;
color: var(--text-2);
display: inline-block;
font-size: var(--text-s);
font-weight: var(--text-bold);
line-height: 1;
padding: var(--padding-xs) var(--padding-s);
white-space: nowrap;
}

samp {
display: inline-block;
}

@property --hue {
syntax: '<angle>';
inherits: false;
Expand Down
1 change: 1 addition & 0 deletions src/components/colorschemepicker.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
padding: var(--padding-s);

& select {
flex: 1 1 auto;
border: none;
background-color: inherit;
border-radius: var(--radii-m);
Expand Down
4 changes: 2 additions & 2 deletions src/components/filetree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ export const Tree: Component<{ entries: Entry[], children: readonly [(folder: Ac
const _Tree: Component<{ entries: Entry[], children: readonly [(folder: Accessor<FolderEntry>) => JSX.Element, (file: Accessor<FileEntry>) => JSX.Element] }> = (props) => {
const context = useContext(TreeContext);

return <For each={props.entries.sort(sort_by('kind'))}>{
return <For each={props.entries.toSorted(sort_by('kind'))}>{
entry => <>
<Show when={entry.kind === 'folder' ? entry : undefined}>{
folder => <Folder folder={folder()} children={props.children} />
}</Show>

<Show when={entry.kind === 'file' ? entry : undefined}>{
file => <span use:selectable={{ value: file() }} ondblclick={() => context?.open(file().meta)}><AiFillFile /> {props.children[1](file)}</span>
file => <span use:selectable={{ key: file().id, value: file() }} ondblclick={() => context?.open(file().meta)}><AiFillFile /> {props.children[1](file)}</span>
}</Show>
</>
}</For>
Expand Down
Empty file.
124 changes: 124 additions & 0 deletions src/components/grid/grid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { Accessor, createContext, createEffect, createMemo, createSignal, JSX, useContext } from "solid-js";
import { Mutation } from "~/utilities";
import { SelectionMode, Table, Column as TableColumn, TableApi, DataSet, CellRenderer as TableCellRenderer } from "~/components/table";
import css from './grid.module.css';

export interface CellRenderer<T extends Record<string, any>, K extends keyof T> {
(cell: Parameters<TableCellRenderer<T, K>>[0] & { mutate: (next: T[K]) => any }): JSX.Element;
}

export interface Column<T extends Record<string, any>> extends Omit<TableColumn<T>, 'renderer'> {
renderer?: CellRenderer<T, keyof T>;
}

export interface GridApi<T extends Record<string, any>> extends TableApi<T> {
readonly mutations: Accessor<Mutation[]>;
remove(keys: number[]): void;
insert(row: T, at?: number): void;
addColumn(column: keyof T): void;
}

interface GridContextType<T extends Record<string, any>> {
readonly mutations: Accessor<Mutation[]>;
readonly selection: TableApi<T>['selection'];
mutate<K extends keyof T>(row: number, column: K, value: T[K]): void;
remove(rows: number[]): void;
insert(row: T, at?: number): void;
addColumn(column: keyof T, value: T[keyof T]): void;
}

const GridContext = createContext<GridContextType<any>>();

const useGrid = () => useContext(GridContext)!;

type GridProps<T extends Record<string, any>> = { class?: string, groupBy?: keyof T, columns: Column<T>[], rows: DataSet<T>, api?: (api: GridApi<T>) => any };

export function Grid<T extends Record<string, any>>(props: GridProps<T>) {
const [table, setTable] = createSignal<TableApi<T>>();

const rows = createMemo(() => props.rows);
const columns = createMemo(() => props.columns as TableColumn<T>[]);
const mutations = createMemo(() => rows().mutations());

const ctx: GridContextType<T> = {
mutations,
selection: createMemo(() => table()?.selection() ?? []),

mutate<K extends keyof T>(row: number, column: K, value: T[K]) {
rows().mutate(row, column, value);
},

remove(indices: number[]) {
rows().remove(indices);
table()?.clear();
},

insert(row: T, at?: number) {
rows().insert(row, at);
},

addColumn(column: keyof T, value: T[keyof T]): void {
// setState('rows', { from: 0, to: state.rows.length - 1 }, column as any, value);
},
};

const cellRenderers = createMemo(() => Object.fromEntries(
props.columns
.filter(c => c.renderer !== undefined)
.map(c => {
const Editor: CellRenderer<T, keyof T> = ({ row, column, value }) => {
const mutate = (next: T[keyof T]) => {
ctx.mutate(row, column, next);
};

return c.renderer!({ row, column, value, mutate });
};

return [c.id, Editor] as const;
})
) as any);

return <GridContext.Provider value={ctx}>
<Api api={props.api} table={table()} />

<Table api={setTable} class={`${css.grid} ${props.class}`} rows={rows()} columns={columns()} selectionMode={SelectionMode.Multiple}>{
cellRenderers()
}</Table>
</GridContext.Provider>;
};

function Api<T extends Record<string, any>>(props: { api: undefined | ((api: GridApi<T>) => any), table?: TableApi<T> }) {
const gridContext = useGrid();

const api = createMemo<GridApi<T> | undefined>(() => {
const table = props.table;

if (!table) {
return;
}

return {
...table,
mutations: gridContext.mutations,
remove(rows: number[]) {
gridContext.remove(rows);
},
insert(row: T, at?: number) {
gridContext.insert(row, at);
},
addColumn(column: keyof T): void {
// gridContext.addColumn(column, value);
},
};
});

createEffect(() => {
const value = api();

if (value) {
props.api?.(value);
}
});

return null;
};
4 changes: 4 additions & 0 deletions src/components/grid/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export type { DataSetRowNode, DataSetGroupNode, DataSetNode, SelectionMode, SortingFunction, SortOptions, GroupingFunction, GroupOptions } from '../table';
export type { GridApi, Column, CellRenderer as CellEditor } from './grid';
export { Grid } from './grid';
7 changes: 5 additions & 2 deletions src/components/prompt.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createEffect, createSignal, createUniqueId, JSX, onMount, ParentComponent, Show } from "solid-js";
import { createEffect, createSignal, JSX, ParentComponent, Show } from "solid-js";
import css from './prompt.module.css';

export interface PromptApi {
Expand Down Expand Up @@ -72,4 +72,7 @@ export const Prompt: ParentComponent<{ api: (api: PromptApi) => any, title?: str
</footer>
</form>
</dialog>;
};
};

let idCounter = 0;
const createUniqueId = () => `prompt-${idCounter++}`;
Loading

0 comments on commit aadc272

Please sign in to comment.