Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON editor #62

Open
wants to merge 31 commits into
base: patchwork
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1ae12de
load datatypes lazily
paulsonnentag May 29, 2024
4503f11
add loaders for remaining datatypes
paulsonnentag May 29, 2024
f200ef9
Abstract datatypeLoaders to modules
paulsonnentag May 30, 2024
af734a2
load tools lazily
paulsonnentag May 30, 2024
4d4f876
cleanup naming dataTypeLoader -> dataTypeModule
paulsonnentag May 30, 2024
485530e
Fix typescript errors
paulsonnentag May 30, 2024
534cc42
export all datatypes as searate files
paulsonnentag May 30, 2024
0fa88c3
export tools as separate files
paulsonnentag May 30, 2024
d4f2022
Add tool picker
paulsonnentag May 31, 2024
32f8770
Add dummy button to load modules
paulsonnentag May 31, 2024
24362ef
Rename datatypeSettings -> moduleSettings
paulsonnentag May 31, 2024
a28026e
hide tool picker if there is just one tool
paulsonnentag May 31, 2024
01c5d13
Add cors headers for netlify deploy
paulsonnentag May 31, 2024
a86e13d
fix _headers file
paulsonnentag May 31, 2024
78412b8
Allow to add modules
paulsonnentag May 31, 2024
e663f53
load dynamic modules
paulsonnentag May 31, 2024
0bee0e0
use automerge in data type
paulsonnentag May 31, 2024
8222be4
load automerge-repo and react through import map
paulsonnentag May 31, 2024
1ae911a
Delete confetti tool
paulsonnentag May 31, 2024
be98d1d
hide tool picker if no document is selected
paulsonnentag May 31, 2024
fa38ae1
Replace url input with prompt
paulsonnentag Jun 3, 2024
7487d9a
enable service worker again
paulsonnentag Jun 6, 2024
82b68e3
remove unused dependencies
paulsonnentag Jun 6, 2024
3016224
add module data type
paulsonnentag Jun 6, 2024
3cba60b
wip: load module documents in root folder
paulsonnentag Jun 6, 2024
719447f
add vite plugin to externalize automerge and react deps
paulsonnentag Jun 7, 2024
64e82f7
replace plugin with simple import map lookup
paulsonnentag Jun 7, 2024
b03192d
fix import map and comment out service worker
paulsonnentag Jun 7, 2024
88ccdb3
don't change imports in dev mode
paulsonnentag Jun 10, 2024
3f1eecc
add source map for shared dependencies
paulsonnentag Jun 10, 2024
9d9aeb6
Add json tool
paulsonnentag May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
</head>
<body>
<div id="root"></div>
<script>
window.esmsInitOptions = {
polyfillEnable: ["css-modules", "json-modules", "wasm-modules"],
};
</script>
<script
async
src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js"
crossorigin="anonymous"
></script>
<script type="module" src="/src/os/main.tsx"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@codemirror/view": "^6.21.3",
"@handsontable/react": "^14.1.0",
"@lezer/highlight": "^1.1.6",
"@microlink/react-json-view": "^1.23.0",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-context-menu": "^2.1.5",
Expand Down Expand Up @@ -86,16 +87,20 @@
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.16",
"cheerio": "^1.0.0-rc.12",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"glob": "^10.4.1",
"jsdom": "^22.1.0",
"pnpm": "^8.14.1",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.3",
"tsc-alias": "^1.8.8",
"typescript": "^5.0.2",
"vite": "^5.0.12",
"vite-plugin-external": "^4.3.1",
"vite-plugin-externalize-dependencies": "^0.12.0",
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^0.34.6"
Expand Down
2 changes: 2 additions & 0 deletions public/_headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*
Access-Control-Allow-Origin: *
5 changes: 0 additions & 5 deletions src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ import { useReducer } from "react";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export function useForceUpdate() {
const [, forceUpdate] = useReducer((x) => x + 1, 0);
return forceUpdate;
}
13 changes: 4 additions & 9 deletions src/datatypes/bot/datatype.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { MarkdownDatatype } from "@/datatypes/essay/datatype";
import { MarkdownDoc } from "@/datatypes/essay/schema";
import { DataTypeWitoutMetaData } from "@/os/datatypes";
import { ContactDoc, RegisteredContactDoc } from "@/os/explorer/account";
import { MarkdownDatatype } from "@/datatypes/markdown/datatype";
import { MarkdownDoc } from "@/datatypes/markdown/schema";
import { type DataType } from "@/os/datatypes";
import { AutomergeUrl, Repo } from "@automerge/automerge-repo";
import { Bot } from "lucide-react";
import { EssayEditingBotDoc } from "./schema";

const BOT_AVATAR_URL = "automerge:uL1duhieqUV4qaeHGHX1dg8FnNy" as AutomergeUrl;

export const EssayEditingBotDatatype: DataType<
export const EssayEditingBotDatatype: DataTypeWitoutMetaData<
EssayEditingBotDoc,
never,
never
> = {
id: "bot",
name: "Bot",
isExperimental: true,
icon: Bot,
init: (doc: any, repo: Repo) => {
const contactHandle = repo.create<RegisteredContactDoc>();
const promptHandle = repo.create<MarkdownDoc>();
Expand Down
2 changes: 1 addition & 1 deletion src/datatypes/bot/essayEditingBot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RegisteredContactDoc } from "@/os/explorer/account";
import { DEFAULT_MODEL, openaiClient } from "@/os/lib/llm";
import { createBranch } from "@/os/versionControl/branches";
import { MarkdownDoc } from "@/datatypes/markdown/schema";
import { MarkdownDoc } from "@/datatypes/essay/schema";
import { AutomergeUrl, DocHandle, Repo } from "@automerge/automerge-repo";
import { splice } from "@automerge/automerge/next";
import { EssayEditingBotDoc } from "./schema";
Expand Down
21 changes: 21 additions & 0 deletions src/datatypes/bot/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DataTypeMetadata, DataTypeWitoutMetaData } from "@/os/datatypes";
import { Module } from "@/os/modules";
import { Bot } from "lucide-react";
import { EssayEditingBotDoc } from "./schema";

export default new Module<
DataTypeMetadata,
DataTypeWitoutMetaData<EssayEditingBotDoc, never, never>
>({
metadata: {
id: "bot",
name: "Bot",
icon: Bot,
isExperimental: true,
},

load: () =>
import("./datatype").then(
({ EssayEditingBotDatatype }) => EssayEditingBotDatatype
),
});
9 changes: 2 additions & 7 deletions src/datatypes/datagrid/datatype.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { DataType } from "@/os/datatypes";
import { DataTypeWitoutMetaData } from "@/os/datatypes";
import { DecodedChangeWithMetadata } from "@/os/versionControl/groupChanges";
import { Annotation } from "@/os/versionControl/schema";
import { next as A } from "@automerge/automerge";
import { pick } from "lodash";
import { Sheet } from "lucide-react";
import { DataGridDoc, DataGridDocAnchor } from "./schema";

// When a copy of the document has been made,
Expand Down Expand Up @@ -123,15 +122,11 @@ const patchesToAnnotations = (
});
};

export const DataGridDatatype: DataType<
export const DataGridDatatype: DataTypeWitoutMetaData<
DataGridDoc,
DataGridDocAnchor,
string
> = {
id: "datagrid",
name: "Spreadsheet",
isExperimental: true,
icon: Sheet,
init,
getTitle,
setTitle,
Expand Down
19 changes: 19 additions & 0 deletions src/datatypes/datagrid/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DataTypeMetadata, DataTypeWitoutMetaData } from "@/os/datatypes";
import { Module } from "@/os/modules";
import { Sheet } from "lucide-react";
import { DataGridDoc, DataGridDocAnchor } from "./schema";

export default new Module<
DataTypeMetadata,
DataTypeWitoutMetaData<DataGridDoc, DataGridDocAnchor, string>
>({
metadata: {
id: "datagrid",
name: "Spreadsheet",
icon: Sheet,
isExperimental: true,
},

load: () =>
import("./datatype").then(({ DataGridDatatype }) => DataGridDatatype),
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataType } from "@/os/datatypes";
import { DataTypeWitoutMetaData } from "@/os/datatypes";
import { FileExportMethod } from "@/os/fileExports";
import { DecodedChangeWithMetadata } from "@/os/versionControl/groupChanges";
import {
Expand All @@ -12,9 +12,8 @@ import {
} from "@/os/versionControl/utils";
import { next as A } from "@automerge/automerge";
import { Repo } from "@automerge/automerge-repo";
import { Doc, splice } from "@automerge/automerge/next";
import { splice } from "@automerge/automerge/next";
import { pick } from "lodash";
import { Text } from "lucide-react";
import { AssetsDoc } from "../../tools/essay/assets";
import { MarkdownDoc, MarkdownDocAnchor } from "./schema";

Expand Down Expand Up @@ -289,14 +288,11 @@ const fileExportMethods: FileExportMethod<MarkdownDoc>[] = [
},
];

export const MarkdownDatatype: DataType<
export const MarkdownDatatype: DataTypeWitoutMetaData<
MarkdownDoc,
MarkdownDocAnchor,
string
> = {
id: "essay",
name: "Essay",
icon: Text,
init,
getTitle,
markCopy,
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions src/datatypes/essay/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DataTypeMetadata, DataTypeWitoutMetaData } from "@/os/datatypes";
import { Text } from "lucide-react";
import { MarkdownDoc, MarkdownDocAnchor } from "./schema";
import { Module } from "@/os/modules";

export default new Module<
DataTypeMetadata,
DataTypeWitoutMetaData<MarkdownDoc, MarkdownDocAnchor, string>
>({
metadata: {
id: "essay",
name: "Essay",
icon: Text,
},

load: () =>
import("./datatype").then(({ MarkdownDatatype }) => MarkdownDatatype),
});
File renamed without changes.
File renamed without changes.
8 changes: 2 additions & 6 deletions src/datatypes/folder/datatype.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DataType } from "@/os/datatypes";
import { FolderIcon } from "lucide-react";
import { DataTypeWitoutMetaData } from "@/os/datatypes";
import { FolderDoc } from ".";

export const init = (doc: any) => {
Expand All @@ -22,10 +21,7 @@ export const setTitle = (doc: FolderDoc, title: string) => {
doc.title = title;
};

export const FolderDatatype: DataType<FolderDoc, never, never> = {
id: "folder",
name: "Folder",
icon: FolderIcon,
export const FolderDatatype: DataTypeWitoutMetaData<FolderDoc, never, never> = {
init,
getTitle,
setTitle,
Expand Down
17 changes: 17 additions & 0 deletions src/datatypes/folder/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DataTypeMetadata, DataTypeWitoutMetaData } from "@/os/datatypes";
import { Folder } from "lucide-react";
import { FolderDoc } from "./schema";
import { Module } from "@/os/modules";

export default new Module<
DataTypeMetadata,
DataTypeWitoutMetaData<FolderDoc, never, never>
>({
metadata: {
id: "folder",
name: "Folder",
icon: Folder,
},

load: () => import("./datatype").then(({ FolderDatatype }) => FolderDatatype),
});
38 changes: 5 additions & 33 deletions src/datatypes/kanban/datatype.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
import { DataType } from "@/os/datatypes";
import { DataTypeWitoutMetaData, useDataType } from "@/os/datatypes";
import { ChangeGroup } from "@/os/versionControl/groupChanges";
import {
Annotation,
HasVersionControlMetadata,
initVersionControlMetadata,
} from "@/os/versionControl/schema";
import { next as A } from "@automerge/automerge";
import { KanbanSquare } from "lucide-react";

export type Lane = {
id: string;
title: string;
cardIds: string[];
};

export type Card = {
id: string;
title: string;
description: string;
label: string;
};

export type KanbanBoardDocAnchor =
| { type: "card"; id: string }
| { type: "lane"; id: string };

export type KanbanBoardDoc = {
title: string;
lanes: Lane[];
cards: Card[];
} & HasVersionControlMetadata<never, never>;
import { Card, KanbanBoardDoc, KanbanBoardDocAnchor, Lane } from "./schema";

// When a copy of the document has been made,
// update the title so it's more clear which one is the copy vs original.
export const markCopy = () => {
const markCopy = () => {
console.error("todo");
};

Expand All @@ -45,7 +21,7 @@ const setTitle = async (doc: KanbanBoardDoc, title: string) => {
doc.title = title;
};

export const init = (doc: any) => {
const init = (doc: any) => {
doc.title = "Untitled Board";
doc.lanes = [];
doc.cards = [];
Expand Down Expand Up @@ -240,15 +216,11 @@ const actions = {
},
};

export const KanbanBoardDatatype: DataType<
export const KanbanBoardDatatype: DataTypeWitoutMetaData<
KanbanBoardDoc,
KanbanBoardDocAnchor,
undefined
> = {
id: "kanban",
name: "Kanban Board",
isExperimental: true,
icon: KanbanSquare,
init,
getTitle,
setTitle,
Expand Down
5 changes: 2 additions & 3 deletions src/datatypes/kanban/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { KanbanBoardDatatype } from "./datatype";
export default KanbanBoardDatatype;

export { KanbanBoardDatatype } from "./datatype";
export * from "./schema";
export * from "./useDocumentWithActions";
19 changes: 19 additions & 0 deletions src/datatypes/kanban/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DataTypeMetadata, DataTypeWitoutMetaData } from "@/os/datatypes";
import { Module } from "@/os/modules";
import { KanbanSquare } from "lucide-react";
import { KanbanBoardDoc, KanbanBoardDocAnchor } from "./schema";

export default new Module<
DataTypeMetadata,
DataTypeWitoutMetaData<KanbanBoardDoc, KanbanBoardDocAnchor, undefined>
>({
metadata: {
id: "kanban",
name: "Kanban Board",
icon: KanbanSquare,
isExperimental: true,
},

load: () =>
import("./datatype").then(({ KanbanBoardDatatype }) => KanbanBoardDatatype),
});
24 changes: 24 additions & 0 deletions src/datatypes/kanban/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { HasVersionControlMetadata } from "@/os/versionControl/schema";

export type Lane = {
id: string;
title: string;
cardIds: string[];
};

export type Card = {
id: string;
title: string;
description: string;
label: string;
};

export type KanbanBoardDocAnchor =
| { type: "card"; id: string }
| { type: "lane"; id: string };

export type KanbanBoardDoc = {
title: string;
lanes: Lane[];
cards: Card[];
} & HasVersionControlMetadata<never, never>;
Loading