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

Feature/change app structure #1063

Merged
merged 9 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
2 changes: 1 addition & 1 deletion lxl-web/src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defaultLocale, Locales } from '$lib/i18n/locales';
import { env } from '$env/dynamic/private';
import { DisplayUtil, VocabUtil } from '$lib/utils/xl';
import fs from 'fs';
import { DERIVED_LENSES } from '$lib/utils/display.types';
import { DERIVED_LENSES } from '$lib/types/display.types';
import displayWeb from '$lib/assets/json/display-web.json';

let utilCache;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import type { ResourceData } from '$lib/types/ResourceData';
import type { ResourceData } from '$lib/types/resourceData.types';
import { onMount } from 'svelte';
import { computePosition, offset, shift, inline, flip, arrow } from '@floating-ui/dom';
import DecoratedData from '$lib/components/DecoratedData.svelte';
Expand Down
2 changes: 1 addition & 1 deletion lxl-web/src/lib/actions/resourcePopover/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Action } from 'svelte/action';
import type { LocaleCode } from '$lib/i18n/locales';
import ResourcePopover from './ResourcePopover.svelte';
import type { ResourceData } from '$lib/types/ResourceData';
import type { ResourceData } from '$lib/types/resourceData.types';

/** Tests to do
* - [] Attaches popover when user hovers over trigger node (after delay)
Expand Down
21 changes: 7 additions & 14 deletions lxl-web/src/lib/components/DecoratedData.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<script lang="ts">
import type { ResourceData } from '$lib/types/ResourceData';
import { ShowLabelsOptions } from '$lib/types/DecoratedData';
import type { ResourceData } from '$lib/types/resourceData.types';
import { ShowLabelsOptions } from '$lib/types/decoratedData.types';
import { page } from '$app/stores';
import resourcePopover from '$lib/actions/resourcePopover';
import { hasStyle, getStyle, getResourceId, getPropertyValue } from '$lib/utils/resourceData';
import { relativizeUrl } from '$lib/utils/http';
import { getSupportedLocale } from '$lib/i18n/locales';
import BiBoxArrowUpRight from '~icons/bi/box-arrow-up-right';

export let data: ResourceData;
export let depth = 0;
Expand Down Expand Up @@ -246,24 +245,18 @@
{data._contentAfter}
</span>
{/if}
{#if hasStyle(data, 'ext-link')}
<a href={getLink(data)} target="_blank">
<span class="ext-link inline-block pl-1">
<BiBoxArrowUpRight />
</span>
<!-- FIXME don't hardcode MediaObject -->
{#if data['@type'] === 'MediaObject'}
<span class="whitespace-pre after:content-['\a']"></span>
{/if}
</a>
{/if}
{/if}
{:else}
{data}
{/if}
{/key}

<style lang="postcss">
.ext-link::after {
content: '\2009↗';
@apply align-[10%] text-icon;
}

.definition {
@apply text-sm text-secondary underline decoration-dotted;
}
Expand Down
2 changes: 1 addition & 1 deletion lxl-web/src/lib/components/ResourceImage.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { type Image, Width } from '$lib/utils/auxd.types';
import { type Image, Width } from '$lib/types/auxd.types';
import placeholder from '$lib/assets/img/placeholder.svg';
import getTypeIcon from '$lib/utils/getTypeIcon';
import { bestSize } from '$lib/utils/auxd';
Expand Down
4 changes: 2 additions & 2 deletions lxl-web/src/lib/components/Search.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { page } from '$app/stores';
import { afterNavigate } from '$app/navigation';
import getDefaultSearchParams from '$lib/utils/addDefaultSearchParams';
import addDefaultSearchParams from '$lib/utils/addDefaultSearchParams';
import getSortedSearchParams from '$lib/utils/getSortedSearchParams';
import BiSearch from '~icons/bi/search';

Expand All @@ -13,7 +13,7 @@
? $page.url.searchParams.get('_q')?.trim()
: $page.url.searchParams.get('_i')?.trim();

let params = getSortedSearchParams(getDefaultSearchParams($page.url.searchParams));
let params = getSortedSearchParams(addDefaultSearchParams($page.url.searchParams));
// Always reset these params on new search
params.set('_offset', '0');
params.delete('_i');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { LocaleCode } from '$lib/i18n/locales';
import { page } from '$app/stores';
import { type FacetGroup } from './search';
import { type FacetGroup } from '$lib/types/search.types';
import BiChevronRight from '~icons/bi/chevron-right';
import FacetRange from './FacetRange.svelte';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { page } from '$app/stores';
import { afterNavigate } from '$app/navigation';
import type { FacetSearch } from './search';
import type { FacetSearch } from '$lib/types/search.types';

export let search: FacetSearch;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import { page } from '$app/stores';
import { getModalContext } from '$lib/contexts/modal';
import FacetGroup from './FacetGroup.svelte';
import type { DisplayMapping, FacetGroup as TypedFacetGroup } from './search';
import type { DisplayMapping, FacetGroup as TypedFacetGroup } from '$lib/types/search.types';
import SearchMapping from './SearchMapping.svelte';
import { shouldShowMapping } from './utils';
import { shouldShowMapping } from '$lib/utils/search';

export let facets: TypedFacetGroup[];
export let mapping: DisplayMapping[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { page } from '$app/stores';
import type { SearchResult } from './search';
import type { SearchResult } from '$lib/types/search.types';
import BiChevronRight from '~icons/bi/chevron-right';
import BiChevronLeft from '~icons/bi/chevron-left';
export let data: SearchResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<script lang="ts">
import jmespath from 'jmespath';
import type { SearchResultItem } from './search';
import DecoratedData from '$lib/components/DecoratedData.svelte';
import type { ResourceData } from '$lib/types/ResourceData';
import { ShowLabelsOptions } from '$lib/types/DecoratedData';
import type { SearchResultItem } from '$lib/types/search.types';
import type { ResourceData } from '$lib/types/resourceData.types';
import { LensType } from '$lib/types/xl.types';
import { ShowLabelsOptions } from '$lib/types/decoratedData.types';
import { LxlLens } from '$lib/types/display.types';

import { relativizeUrl } from '$lib/utils/http';
import { LensType } from '$lib/utils/xl';
import { LxlLens } from '$lib/utils/display.types';
import placeholder from '$lib/assets/img/placeholder.svg';
import getTypeIcon from '$lib/utils/getTypeIcon';
import placeholder from '$lib/assets/img/placeholder.svg';
import DecoratedData from '$lib/components/DecoratedData.svelte';
import { page } from '$app/stores';

export let item: SearchResultItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script lang="ts">
import { ShowLabelsOptions } from '$lib/types/decoratedData.types';
import type { DisplayMapping, SearchOperators } from '$lib/types/search.types';

import { page } from '$app/stores';
import DecoratedData from '$lib/components/DecoratedData.svelte';
import { ShowLabelsOptions } from '$lib/types/DecoratedData';
import { getModalContext } from '$lib/contexts/modal';
import type { DisplayMapping, SearchOperators } from './search';
import BiXLg from '~icons/bi/x-lg';
import BiPencil from '~icons/bi/pencil';
import BiPencilFill from '~icons/bi/pencil-fill';
import BiTrash from '~icons/bi/trash';

export let mapping: DisplayMapping[];
export let parentOperator: keyof typeof SearchOperators | undefined = undefined;
export let depth = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import Filters from './Filters.svelte';
import IconSliders from '~icons/bi/sliders';
import BiChevronDown from '~icons/bi/chevron-down';
import type { SearchResult, DisplayMapping } from './search';
import { shouldShowMapping } from './utils';
import type { SearchResult, DisplayMapping } from '$lib/types/search.types';
import { shouldShowMapping } from '$lib/utils/search';

let showFiltersModal = false;

$: searchResult = $page.data.searchResult as SearchResult;
export let searchResult: SearchResult;

$: sortOrder = $page.url.searchParams.get('_sort');
const sortOptions = [
Expand Down
jesperengstrom marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObject, JsonLd, type Link, Owl } from '$lib/utils/xl';
import { JsonLd, Owl, type Link } from './xl.types';

type SizePx = `${number}px`;

Expand Down Expand Up @@ -37,11 +37,3 @@ export interface Image {
export interface SecureImage extends Image {
sizes: SecureImageResolution[];
}

export function isImage(v: unknown): v is Image {
return isObject(v) && 'sizes' in v && 'recordId' in v;
}

export function isImageResolution(v: unknown): v is ImageResolution {
return isObject(v) && 'url' in v && 'widthṔx' in v && 'heightPx' in v;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type DerivedLensTypeDefinition, LensType } from '$lib/utils/xl';
import { type DerivedLensTypeDefinition, LensType } from '$lib/types/xl.types';

export enum LxlLens {
PageHeading = 'page-heading',
Expand Down
139 changes: 139 additions & 0 deletions lxl-web/src/lib/types/search.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { JsonLd, type Link, type DisplayDecorated, type FramedData } from '$lib/types/xl.types';
import { type SecureImageResolution } from '$lib/types/auxd.types';
import { LxlLens } from '$lib/types/display.types';

export interface SearchResult {
itemOffset: number;
itemsPerPage: number;
totalItems: number;
maxItems: number;
mapping: DisplayMapping[];
first: Link;
last: Link;
next?: Link;
items: SearchResultItem[];
facetGroups: FacetGroup[];
predicates: MultiSelectFacet[];
}

export interface SearchResultItem {
[JsonLd.ID]: string;
[JsonLd.TYPE]: string;
[LxlLens.CardHeading]: DisplayDecorated;
[LxlLens.CardBody]: DisplayDecorated;
image: SecureImageResolution | undefined;
typeStr: string;
}

type FacetGroupId = string;

export type FacetSearch = {
mapping: {
greaterThanOrEquals: string;
lessThanOrEquals: string;
variable: FacetGroupId;
};
template: string;
};

export interface FacetGroup {
label: string;
dimension: FacetGroupId;
search?: FacetSearch;
// TODO better to do this distinction on the group level?
facets: (Facet | MultiSelectFacet)[];
}

export interface Facet {
totalItems: number;
view: Link;
object: DisplayDecorated;
str: string;
discriminator: string;
}

export interface MultiSelectFacet extends Facet {
selected: boolean;
}

export interface DisplayMapping {
display?: DisplayDecorated;
up?: Link;
children?: DisplayMapping[];
label?: string;
operator: keyof typeof SearchOperators;
}

export interface PartialCollectionView {
[JsonLd.TYPE]: 'PartialCollectionView';
[JsonLd.ID]: string;
[JsonLd.CONTEXT]: string;
itemOffset: number;
itemsPerPage: number;
totalItems: number;
maxItems: number;
search: {
mapping: SearchMapping[];
};
first: Link;
last: Link;
next?: Link;
items: FramedData[];
stats?: {
[JsonLd.ID]: '#stats';
sliceByDimension: Record<FacetGroupId, Slice>;
_predicates: Observation[];
_boolFilters?: Observation[];
};
}

interface Slice {
alias: string;
dimension: FacetGroupId;
observation: Observation[];
search?: FacetSearch;
}

interface Observation {
totalItems: number;
view: Link;
object: FramedData;
_selected?: boolean;
}

export enum SearchOperators {
and = 'and',
or = 'or',
not = 'not',
equals = 'equals',
notEquals = 'notEquals',
greaterThan = 'greaterThan',
greaterThanOrEquals = 'greaterThanOrEquals',
lessThan = 'lessThan',
lessThanOrEquals = 'lessThanOrEquals',
existence = 'existence',
notExistence = 'notExistence',
none = 'none'
}

type MappingObj = { [key in SearchOperators]: SearchMapping[] | string | FramedData };

export interface SearchMapping extends MappingObj {
alias: string;
property?: ObjectProperty | DatatypeProperty | PropertyChainAxiom;
object?: FramedData;
up: { '@id': string };
}

interface ObjectProperty {}

export interface DatatypeProperty {
'@type': 'DataTypeProperty';
'@id': string;
}

interface PropertyChainAxiom {
propertyChainAxiom: (ObjectProperty | DatatypeProperty)[];
label: string; // e.g. "instanceOf language"
_key: string; // e.g. "instanceOf.language"
}
Loading