Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class RelationshipEditorModal extends Component<Sig> {
id={{formId}}
@onSubmit={{this.save}}
@controller={{@controller}}
@termTypes={{(array 'LiteralNode' 'ResourceNode')}}
@termTypes={{(array 'LiteralNode' 'ResourceNode' 'NamedNode')}}
@triple={{@triple}}
@importedResources={{@importedResources}}
/>
Expand Down
36 changes: 25 additions & 11 deletions addon/core/schema.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { v4 as uuidv4 } from 'uuid';
import { Mark, type Attrs, type DOMOutputSpec } from 'prosemirror-model';
import { PNode } from '@lblod/ember-rdfa-editor/index';
import { type PNode } from '@lblod/ember-rdfa-editor';
import { isSome, unwrap } from '../utils/_private/option';
import type {
ContentTriple,
IncomingLiteralNodeTriple,
IncomingTriple,
OutgoingTriple,
} from './rdfa-processor';
import { isElement } from '@lblod/ember-rdfa-editor/utils/_private/dom-helpers';
import { isElement } from '../utils/_private/dom-helpers';
import { sayDataFactory } from './say-data-factory';
import { IMPORTED_RESOURCES_ATTR } from '../plugins/imported-resources';

// const logger = createLogger('core/schema');

Expand Down Expand Up @@ -292,15 +293,28 @@ export function renderRdfaAttrs(
return {};
}

return {
about: backlinks[0].subject.value,
property: backlinks[0].predicate,
datatype: backlinks[0].subject.language.length
? null
: backlinks[0].subject.datatype.value,
lang: backlinks[0].subject.language,
'data-literal-node': 'true',
};
// @ts-expect-error rdfaAttrs can actually contain any Attrs, but since this is temporary, just
// ignore the type error
if (rdfaAttrs[IMPORTED_RESOURCES_ATTR]) {
// TODO figure out how to add links from resources in the snippet TO imported resources in a
// way that doesn't break tooling or require manually typing URIs into a NamedNode
// relationship.
// For now just warn and avoid crashing.
console.warn(
'Do not add relationships pointing TO an imported resource as a ResourceNode, use a NamedNode with the correct URI',
);
return {};
} else {
return {
about: backlinks[0].subject.value,
property: backlinks[0].predicate,
datatype: backlinks[0].subject.language.length
? null
: backlinks[0].subject.datatype.value,
lang: backlinks[0].subject.language,
'data-literal-node': 'true',
};
}
}
}

Expand Down