Skip to content

Commit

Permalink
🚧 SeedConfigFork
Browse files Browse the repository at this point in the history
  • Loading branch information
wappon28dev committed Aug 18, 2024
1 parent 8652e34 commit fc1f844
Show file tree
Hide file tree
Showing 17 changed files with 515 additions and 267 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"LicenSeed",
"nanostores",
"pathe",
"rehype",
"resplit",
"Resplit",
"rspc",
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html lang="ja" data-color-mode="light">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@tauri-apps/api": ">=2.0.0-rc.0",
"@tauri-apps/plugin-dialog": "^2.0.0-rc.0",
"@tauri-apps/plugin-shell": ">=2.0.0-rc.0",
"@uiw/react-md-editor": "^4.0.4",
"lorem-ipsum": "^2.0.8",
"nanostores": "^0.10.3",
"natural-compare-lite": "^1.4.0",
Expand All @@ -34,6 +35,7 @@
"react-folder-tree": "^5.1.1",
"react-resplit": "^1.3.1",
"react-router-dom": "^6.23.0",
"rehype-sanitize": "^6.0.0",
"swr": "^2.2.5",
"ts-pattern": "^5.1.2",
"use-resize-observer": "^9.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/resources/seeds
Submodule seeds updated 50 files
+7 −6 bases/@software/0bsd.yml
+11 −10 bases/@software/afl-3.0.yml
+13 −12 bases/@software/agpl-3.0.yml
+11 −10 bases/@software/apache-2.0.yml
+11 −10 bases/@software/artistic-2.0.yml
+9 −8 bases/@software/blueoak-1.0.0.yml
+9 −8 bases/@software/bsd-2-clause-patent.yml
+8 −7 bases/@software/bsd-2-clause.yml
+9 −8 bases/@software/bsd-3-clause-clear.yml
+8 −7 bases/@software/bsd-3-clause.yml
+8 −7 bases/@software/bsd-4-clause.yml
+8 −7 bases/@software/bsl-1.0.yml
+11 −10 bases/@software/cc-by-4.0.yml
+12 −11 bases/@software/cc-by-sa-4.0.yml
+9 −8 bases/@software/cc0-1.0.yml
+12 −11 bases/@software/cecill-2.1.yml
+10 −9 bases/@software/cern-ohl-p-2.0.yml
+12 −11 bases/@software/cern-ohl-s-2.0.yml
+12 −11 bases/@software/cern-ohl-w-2.0.yml
+11 −10 bases/@software/ecl-2.0.yml
+11 −10 bases/@software/epl-1.0.yml
+11 −10 bases/@software/epl-2.0.yml
+14 −13 bases/@software/eupl-1.1.yml
+14 −13 bases/@software/eupl-1.2.yml
+11 −10 bases/@software/gfdl-1.3.yml
+11 −10 bases/@software/gpl-2.0.yml
+12 −11 bases/@software/gpl-3.0.yml
+8 −7 bases/@software/isc.yml
+11 −10 bases/@software/lgpl-2.1.yml
+12 −11 bases/@software/lgpl-3.0.yml
+10 −9 bases/@software/lppl-1.3c.yml
+7 −6 bases/@software/mit-0.yml
+8 −7 bases/@software/mit.yml
+12 −11 bases/@software/mpl-2.0.yml
+9 −8 bases/@software/ms-pl.yml
+11 −10 bases/@software/ms-rl.yml
+10 −9 bases/@software/mulanpsl-2.0.yml
+8 −7 bases/@software/ncsa.yml
+12 −11 bases/@software/odbl-1.0.yml
+9 −8 bases/@software/ofl-1.1.yml
+14 −13 bases/@software/osl-3.0.yml
+8 −7 bases/@software/postgresql.yml
+7 −6 bases/@software/unlicense.yml
+9 −8 bases/@software/upl-1.0.yml
+9 −8 bases/@software/vim.yml
+5 −4 bases/@software/wtfpl.yml
+9 −8 bases/@software/zlib.yml
+36 −17 schemas/base.json
+1 −0 script/.gitignore
+14 −37 script/choosealicense.ts
1 change: 1 addition & 0 deletions src-tauri/src/modules/seed/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct Terms {
permissions: HashMap<String, TermEntry>,
conditions: HashMap<String, TermEntry>,
limitations: HashMap<String, TermEntry>,
notes: Option<HashMap<String, TermEntry>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
Expand Down
5 changes: 3 additions & 2 deletions src-tauri/src/modules/seed/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ use specta::Type;
#[serde(tag = "type", rename_all = "SCREAMING_SNAKE_CASE")]
#[allow(dead_code)]
pub enum SummaryEntry {
Term { value: String },
Markdown { value: String },
Term { key: String },
Markdown { title: String, body: String },
}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct Summary {
permissions: Vec<SummaryEntry>,
limitations: Vec<SummaryEntry>,
conditions: Vec<SummaryEntry>,
notes: Option<Vec<SummaryEntry>>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
Expand Down
6 changes: 3 additions & 3 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ export function Button({
icon,
children,
type = "filled",
styles,
props,
}: {
type?: "filled" | "light" | "outline";
icon?: string;
children: ReactElement;
styles?: ComponentProps<(typeof p)["button"]>;
props?: ComponentProps<(typeof p)["button"]>;
}): ReactElement {
return (
<p.button
p="2"
px="5"
rounded="md"
{...styles}
style={{
backgroundColor: match(type)
.with("filled", () => token("colors.blue.500"))
Expand All @@ -34,6 +33,7 @@ export function Button({
.with("outline", () => `1px solid ${token("colors.blue.500")}`)
.otherwise(() => "none"),
}}
{...props}
>
<HStack>
{icon != null && <Icon icon={icon} />}
Expand Down
237 changes: 184 additions & 53 deletions src/components/seed/Summary.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
/* eslint-disable react/no-array-index-key */

import { Icon } from "@iconify/react";
import { styled as p, VStack } from "panda/jsx";
import MDEditor from "@uiw/react-md-editor";
import { css } from "panda/css";
import { HStack, styled as p, VStack } from "panda/jsx";
import { token } from "panda/tokens";
import { type ReactElement } from "react";
import { RenderedSummaryEntry } from "./SummaryEntry";
import { type SeedBaseGroupManifest, type Summary } from "@/types/bindings";
import rehypeSanitize from "rehype-sanitize";
import { DisplaySummaryEntry } from "./SummaryEntry";
import { Button } from "@/components/Button";
import { getEntries } from "@/lib/utils";
import {
type SummaryEntry,
type SeedBaseGroupManifest,
type Summary,
} from "@/types/bindings";

const Card = p("div", {
base: {
Expand All @@ -27,73 +39,192 @@ const IconText = p("div", {
},
});

const summaryEntry = {
permissions: {
id: 0,
title: "許可されていること",
color: "green.500",
bgColor: "green.100",
icon: "mdi:check",
},
limitations: {
id: 1,
title: "制限されていること",
color: "red.500",
bgColor: "red.100",
icon: "mdi:close",
},
conditions: {
id: 2,
title: "条件",
color: "yellow.800",
bgColor: "yellow.100",
icon: "mdi:alert",
},
notes: {
id: 3,
title: "特記事項",
color: "orange.800",
bgColor: "orange.100",
icon: "mdi:information",
},
} as const satisfies Record<
keyof Summary,
{
id: number;
title: string;
bgColor: string;
color: string;
icon: string;
}
>;

export function SeedSummary({
groupManifest,
summary,
}: {
groupManifest: SeedBaseGroupManifest;
summary: Summary;
}): ReactElement {
const { conditions, limitations, permissions } = summary;

return (
<VStack flex="1" gap="3" w="100%">
<p.div
alignItems="start"
display="grid"
gap="3"
gridTemplateColumns="repeat(auto-fit, minmax(300px, 1fr))"
gridTemplateColumns="repeat(auto-fill, minmax(300px, 1fr))"
justifyContent="start"
w="100%"
>
<Card bg="green.100">
<IconText color="green.500">
<Icon icon="mdi:check" /> 許可されていること
</IconText>
<p.ul>
{permissions.map((entry) => (
<RenderedSummaryEntry
key={entry.value}
entry={entry}
entryKey="permissions"
groupManifest={groupManifest}
/>
))}
</p.ul>
</Card>
<Card bg="red.100">
<IconText color="red.500">
<Icon icon="mdi:close" />
制限されていること
</IconText>
<p.ul>
{limitations.map((entry) => (
<RenderedSummaryEntry
key={entry.value}
entry={entry}
entryKey="limitations"
groupManifest={groupManifest}
/>
))}
</p.ul>
</Card>
{getEntries(summary)
.sort(
([k1, _], [k2, __]) => summaryEntry[k1].id - summaryEntry[k2].id,
)
.map(([k, v]) => {
if (v == null || v.length === 0) return undefined;
const { title, bgColor, color, icon } = summaryEntry[k];

return (
<Card
key={k}
style={{
background: token(`colors.${bgColor}`),
}}
>
<IconText
style={{
color: token(`colors.${color}`),
}}
>
<Icon icon={icon} />
{title}
</IconText>
<p.ul>
{v.map((entry, idx) => (
<DisplaySummaryEntry
key={idx}
summaryEntry={entry}
terms={groupManifest.terms}
termsEntryKey={k}
/>
))}
</p.ul>
</Card>
);
})}
</p.div>
<Card bg="yellow.100" h="fit-content">
<IconText color="yellow.800">
<Icon icon="mdi:alert" />
条件
</IconText>
<p.ul>
{conditions.map((entry) => (
<RenderedSummaryEntry
key={entry.value}
entry={entry}
entryKey="conditions"
groupManifest={groupManifest}
/>
))}
</p.ul>
</Card>
</VStack>
);
}

export function SeedSummaryNoteEditable({
entries,
setEntries,
}: {
entries: SummaryEntry[];
setEntries: (newEntries: SummaryEntry[]) => void;
}): ReactElement {
const { bgColor } = summaryEntry.notes;

return (
<VStack
p="3"
rounded="md"
style={{
background: token(`colors.${bgColor}`),
}}
w="100%"
>
<p.ul w="100%">
{entries.map((entry, idx) => (
<p.li key={idx} mb="3">
<VStack w="100%">
<HStack justifyContent="space-between" w="100%">
<p.input
bg="white"
border="1px solid"
onChange={(e) => {
const next = [...entries];
next[idx] = {
type: "MARKDOWN",
body: "",
title: e.target.value,
};

setEntries(next);
}}
p="1"
placeholder="タイトル"
rounded="md"
value={entry.type === "MARKDOWN" ? entry.title : ""}
w="100%"
/>
<p.button
onClick={() => {
setEntries(entries.filter((_, i) => i !== idx));
}}
>
<Icon height="1.5em" icon="mdi:delete-forever-outline" />
</p.button>
</HStack>
<MDEditor
className={css({
w: "100%",
})}
onChange={(value) => {
setEntries(
entries.map((e, i) =>
i === idx ? { ...e, body: value ?? "" } : e,
),
);
}}
previewOptions={{
rehypePlugins: [[rehypeSanitize]],
}}
value={entry.type === "MARKDOWN" ? entry.body : ""}
/>
</VStack>
</p.li>
))}
</p.ul>
<Button
icon="mdi:plus"
props={{
onClick: () => {
setEntries([
...entries,
{
type: "MARKDOWN",
title: "",
body: "",
},
]);
},
}}
type="outline"
>
<p.p>追加</p.p>
</Button>
</VStack>
);
}
Loading

0 comments on commit fc1f844

Please sign in to comment.