wip: add types to kestrel
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
parent
27a1ee1051
commit
ee5d50ee48
|
@ -1,15 +1,15 @@
|
|||
<script lang="ts">
|
||||
import EntryView, { type Widget } from "./EntryView.svelte";
|
||||
import { query, useEntity } from "../lib/entity";
|
||||
import { useEntity } from "../lib/entity";
|
||||
import UpObject from "./display/UpObject.svelte";
|
||||
import { createEventDispatcher, setContext } from "svelte";
|
||||
import { writable } from "svelte/store";
|
||||
import { derived, writable, type Readable } from "svelte/store";
|
||||
import type { UpEntry } from "upend";
|
||||
import Spinner from "./utils/Spinner.svelte";
|
||||
import NotesEditor from "./utils/NotesEditor.svelte";
|
||||
import type { AttributeChange } from "../types/base";
|
||||
import Selector from "./utils/Selector.svelte";
|
||||
import type { IValue } from "upend/types";
|
||||
import type { EntityInfo, IValue } from "upend/types";
|
||||
import IconButton from "./utils/IconButton.svelte";
|
||||
import type { BrowseContext } from "../util/browse";
|
||||
import { Link, useParams } from "svelte-navigator";
|
||||
|
@ -19,7 +19,7 @@
|
|||
import EntryList from "./widgets/EntryList.svelte";
|
||||
import api from "../lib/api";
|
||||
import Gallery from "./widgets/Gallery.svelte";
|
||||
import { ATTR_IN, ATTR_LABEL, ATTR_KEY } from "upend/constants";
|
||||
import { ATTR_IN, ATTR_LABEL, ATTR_KEY, ATTR_OF } from "upend/constants";
|
||||
const dispatch = createEventDispatcher();
|
||||
const params = useParams();
|
||||
|
||||
|
@ -45,6 +45,76 @@
|
|||
|
||||
$: ({ entity, entityInfo, error, revalidate } = useEntity(address));
|
||||
|
||||
$: allTypes = derived(
|
||||
entityInfo,
|
||||
($entityInfo, set) => {
|
||||
getAllTypes($entityInfo).then((allTypes) => {
|
||||
set(allTypes);
|
||||
});
|
||||
},
|
||||
{}
|
||||
) as Readable<{
|
||||
[key: string]: {
|
||||
labels: string[];
|
||||
attributes: string[];
|
||||
};
|
||||
}>;
|
||||
|
||||
async function getAllTypes(entityInfo: EntityInfo) {
|
||||
const allTypes = {};
|
||||
|
||||
if (!entityInfo) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const typeAddresses: string[] = [
|
||||
await api.getAddress(entityInfo.t),
|
||||
...$entity.attr[ATTR_IN].map((e) => e.value.c as string),
|
||||
];
|
||||
const typeAddressesIn = typeAddresses.map((addr) => `@${addr}`).join(" ");
|
||||
|
||||
const labelsQuery = await api.query(
|
||||
`(matches (in ${typeAddressesIn}) "${ATTR_LABEL}" ?)`
|
||||
);
|
||||
typeAddresses.forEach((address) => {
|
||||
let labels = labelsQuery.getObject(address).identify();
|
||||
if (!labels.length) {
|
||||
labels.push(address);
|
||||
}
|
||||
allTypes[address] = {
|
||||
labels,
|
||||
attributes: [],
|
||||
};
|
||||
});
|
||||
|
||||
const attributes = await api.query(
|
||||
`(matches ? "${ATTR_OF}" (in ${typeAddressesIn}))`
|
||||
);
|
||||
await Promise.all(
|
||||
typeAddresses.map(async (address) => {
|
||||
allTypes[address].attributes = (
|
||||
await Promise.all(
|
||||
(attributes.getObject(address).attr[`~${ATTR_OF}`] || []).map(
|
||||
async (e) => {
|
||||
try {
|
||||
const { t, c } = await api.addressToComponents(e.entity);
|
||||
if (t == "Attribute") {
|
||||
return c;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
).filter(Boolean);
|
||||
})
|
||||
);
|
||||
|
||||
return allTypes;
|
||||
}
|
||||
|
||||
let typedAttributes = {} as { [key: string]: UpEntry[] };
|
||||
let untypedAttributes = [] as UpEntry[];
|
||||
|
||||
|
@ -53,10 +123,8 @@
|
|||
untypedAttributes = [];
|
||||
|
||||
($entity?.attributes || []).forEach((entry) => {
|
||||
const entryTypes = Object.entries(/*allTypes*/ {}).filter(
|
||||
([_, t]) =>
|
||||
// t.attributes.includes(entry.attribute)
|
||||
false
|
||||
const entryTypes = Object.entries($allTypes || {}).filter(([_, t]) =>
|
||||
t.attributes.includes(entry.attribute)
|
||||
);
|
||||
if (entryTypes.length > 0) {
|
||||
entryTypes.forEach(([addr, _]) => {
|
||||
|
@ -318,9 +386,8 @@
|
|||
{editable}
|
||||
widgets={attributeWidgets}
|
||||
on:change={onChange}
|
||||
initialWidget={String($entity.get("LAST_ATTRIBUTE_WIDGET"))}
|
||||
on:widgetSwitched={onAttributeWidgetSwitch}
|
||||
highlighted={highlightedType == typeAddr}
|
||||
title={$allTypes[typeAddr].labels.join(" | ")}
|
||||
/>
|
||||
{/each}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { UpEndApi } from "upend/api";
|
||||
import wasmURL from "upend/upend_wasm_bg.wasm?url";
|
||||
|
||||
export default new UpEndApi("/");
|
||||
export default new UpEndApi("/", wasmURL);
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/// <reference types="vite/client" />
|
Loading…
Reference in New Issue