Skip to content

Commit

Permalink
Update editor to rdfa-backwards-compatibility build (#395)
Browse files Browse the repository at this point in the history
* wip: update editor

* update editor to latest dev commit

* update nodes to use rdfa-attr-spec function

* update dummy pages to use rdfa-aware nodes

* enable rdfa-awareness on regulatory statement doc node-spec

* lint: remove unused imports

* lint: prettier

* make links in dummy pages rdfa-aware

* feat(citation-plugin): update citation plugin to work with rdfa-aware link nodes

* fix invisible_rdfa typo

* enable rdfa-awareness on besluit-editable-nodes doc node-spec

* use full uris when inserting/removing decision type properties

* fix issue with toDOM of besluit_articel_structure node-spec

* chore: bump editor to latest release

* fix: revert dummy app route back to js

---------

Co-authored-by: abeforgit <[email protected]>
  • Loading branch information
elpoelma and abeforgit authored Apr 4, 2024
1 parent f2020d0 commit 3cc0097
Show file tree
Hide file tree
Showing 24 changed files with 420 additions and 258 deletions.
9 changes: 4 additions & 5 deletions addon/components/besluit-type-plugin/toolbar-dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { addProperty, removeProperty } from '@lblod/ember-rdfa-editor/commands';
import { SayController } from '@lblod/ember-rdfa-editor';
import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
import { ResolvedPNode } from '@lblod/ember-rdfa-editor/plugins/datastore';
import { getRdfaAttribute } from '@lblod/ember-rdfa-editor/utils/rdfa-utils';
import fetchBesluitTypes, {
BesluitType,
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/besluit-type-plugin/utils/fetchBesluitTypes';
Expand Down Expand Up @@ -77,7 +76,7 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
get currentBesluitURI() {
if (this.currentBesluitRange) {
const node = unwrap(this.doc.nodeAt(this.currentBesluitRange.from));
return getRdfaAttribute(node, 'resource').pop();
return node.attrs['subject'] as string | undefined;
}
return;
}
Expand Down Expand Up @@ -204,7 +203,7 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
const resource =
(this.currentBesluitRange &&
'node' in this.currentBesluitRange &&
(this.currentBesluitRange.node.attrs.resource as string)) ||
(this.currentBesluitRange.node.attrs.subject as string)) ||
undefined;
if (this.besluitType && resource) {
this.cardExpanded = false;
Expand All @@ -213,7 +212,7 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
removeProperty({
resource,
property: {
predicate: RDF('type').prefixed,
predicate: RDF('type').full,
object: sayDataFactory.namedNode(this.previousBesluitType),
},
}),
Expand All @@ -224,7 +223,7 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
addProperty({
resource,
property: {
predicate: RDF('type').prefixed,
predicate: RDF('type').full,
object: sayDataFactory.namedNode(this.besluitType.uri),
},
}),
Expand Down
2 changes: 1 addition & 1 deletion addon/components/variable-plugin/codelist/insert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { NodeSelection, SayController } from '@lblod/ember-rdfa-editor';
import { SayController } from '@lblod/ember-rdfa-editor';
import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
import {
CodeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
hasOutgoingNamedNodeTriple,
hasRDFaAttribute,
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
const rdfaAware = true;
import {
constructStructureBodyNodeSpec,
getNumberUtils,
Expand Down Expand Up @@ -141,7 +142,7 @@ export const article_paragraph: NodeSpec = {
editable: true,
defining: true,
attrs: {
...rdfaAttrSpec,
...rdfaAttrSpec({ rdfaAware }),
typeof: {
default: SAY('Paragraph').prefixed,
},
Expand Down Expand Up @@ -173,7 +174,7 @@ export const article_paragraph: NodeSpec = {
tag: 'div',
context: 'article/article_body/',
getAttrs(element: HTMLElement) {
const rdfaAttrs = getRdfaAttrs(element);
const rdfaAttrs = getRdfaAttrs(element, { rdfaAware });
if (
hasOutgoingNamedNodeTriple(
rdfaAttrs,
Expand All @@ -194,7 +195,7 @@ export const article_paragraph: NodeSpec = {
tag: 'div',
context: 'article/article_body/',
getAttrs(element: HTMLElement) {
const rdfaAttrs = getRdfaAttrs(element);
const rdfaAttrs = getRdfaAttrs(element, { rdfaAware });
if (
hasOutgoingNamedNodeTriple(rdfaAttrs, RDF('type'), SAY('Paragraph'))
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {
hasRDFaAttribute,
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';

const rdfaAware = true;
export const structure_header_number: NodeSpec = {
attrs: rdfaAttrSpec,
attrs: rdfaAttrSpec({ rdfaAware }),
content: 'text*',
inline: true,
editable: true,
Expand All @@ -30,7 +31,7 @@ export const structure_header_number: NodeSpec = {
{
tag: 'span',
getAttrs(node: HTMLElement) {
const attrs = getRdfaAttrs(node);
const attrs = getRdfaAttrs(node, { rdfaAware });
if (hasBacklink(attrs, ELI('number'))) {
return attrs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
import { EXT } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
import { hasBacklink } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';

const rdfaAware = true;
export const structure_header_title: NodeSpec = {
attrs: rdfaAttrSpec,
attrs: rdfaAttrSpec({ rdfaAware }),
content: 'placeholder|text*',
inline: true,
editable: true,
Expand All @@ -25,7 +26,7 @@ export const structure_header_title: NodeSpec = {
tag: 'span',
context: 'structure_header/|article_header/',
getAttrs(node: HTMLElement) {
const attrs = getRdfaAttrs(node);
const attrs = getRdfaAttrs(node, { rdfaAware });
if (hasBacklink(attrs, EXT('title'))) {
return attrs;
}
Expand Down
18 changes: 9 additions & 9 deletions addon/plugins/article-structure-plugin/utils/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { StructureSpec } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/ar
import { unwrap } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
import { romanize } from './romanize';

const rdfaAware = true;
export function constructStructureNodeSpec(config: {
type: Resource;
content: string;
Expand All @@ -42,7 +43,7 @@ export function constructStructureNodeSpec(config: {
editable: true,
isolating: true,
attrs: {
...rdfaAttrSpec,
...rdfaAttrSpec({ rdfaAware }),
rdfaNodeType: {
default: 'resource',
},
Expand All @@ -68,7 +69,7 @@ export function constructStructureNodeSpec(config: {
tag: 'div',
preserveWhitespace: false,
getAttrs(element: HTMLElement) {
const rdfaAttrs = getRdfaAttrs(element);
const rdfaAttrs = getRdfaAttrs(element, { rdfaAware });
if (
hasOutgoingNamedNodeTriple(rdfaAttrs, RDF('type'), type) &&
hasRdfaContentChild(element)
Expand All @@ -84,7 +85,7 @@ export function constructStructureNodeSpec(config: {
tag: 'div',
preserveWhitespace: false,
getAttrs(element: HTMLElement) {
const rdfaAttrs = getRdfaAttrs(element);
const rdfaAttrs = getRdfaAttrs(element, { rdfaAware });
if (hasOutgoingNamedNodeTriple(rdfaAttrs, RDF('type'), type)) {
return rdfaAttrs;
}
Expand All @@ -109,7 +110,7 @@ export function constructStructureBodyNodeSpec(config: {
editable: true,
isolating: true,
allowSplitByTable: config.allowSplitByTable,
attrs: rdfaAttrSpec,
attrs: rdfaAttrSpec({ rdfaAware }),
toDOM(node) {
return renderRdfaAware({
renderable: node,
Expand All @@ -128,7 +129,7 @@ export function constructStructureBodyNodeSpec(config: {
tag,
context,
getAttrs(element: HTMLElement) {
const rdfaAttrs = getRdfaAttrs(element);
const rdfaAttrs = getRdfaAttrs(element, { rdfaAware });
if (
hasBacklink(rdfaAttrs, SAY('body')) &&
hasRdfaContentChild(element)
Expand All @@ -144,7 +145,7 @@ export function constructStructureBodyNodeSpec(config: {
tag,
context,
getAttrs(element: HTMLElement) {
const rdfaAttrs = getRdfaAttrs(element);
const rdfaAttrs = getRdfaAttrs(element, { rdfaAware });
if (hasBacklink(rdfaAttrs, SAY('body'))) {
return rdfaAttrs;
}
Expand Down Expand Up @@ -188,7 +189,7 @@ export function constructStructureHeaderNodeSpec({
selectable: false,
allowSplitByTable: false,
attrs: {
...rdfaAttrSpec,
...rdfaAttrSpec({ rdfaAware }),
property: {
default: SAY('heading').prefixed,
},
Expand Down Expand Up @@ -233,8 +234,7 @@ export function constructStructureHeaderNodeSpec({
priority: 60,
getAttrs(element: HTMLElement) {
const level = TAG_TO_LEVEL.get(element.tagName.toLowerCase()) ?? 6;
const rdfaAttrs = getRdfaAttrs(element);

const rdfaAttrs = getRdfaAttrs(element, { rdfaAware });
if (hasBacklink(rdfaAttrs, SAY('heading'))) {
const titleChild = element.querySelector(`
span[property~='${EXT('title').prefixed}'],
Expand Down
46 changes: 38 additions & 8 deletions addon/plugins/citation-plugin/utils/cited-text.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,48 @@
import { PNode } from '@lblod/ember-rdfa-editor';
import { CitationSchema } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/citation-plugin';
import {
ELI,
RDF,
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
import { unwrap } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';

export function citedText(
schema: CitationSchema,
title: string,
uri: string,
): PNode {
return unwrap(schema.nodes.link).create(
{
href: uri,
property: 'eli:cites',
typeof: 'eli:LegalExpression',
},
[schema.text(title)],
);
const linkType = unwrap(schema.nodes.link);
const linkSpec = linkType.spec;
if (linkSpec.attrs && linkSpec.attrs['properties']) {
// Link node-spec is RDFa-aware
return linkType.create(
{
href: uri,
subject: uri,
rdfaNodeType: 'resource',
properties: [
{
predicate: RDF('type').full,
object: sayDataFactory.namedNode(ELI('LegalExpression').full),
},
{
predicate: ELI('cites').full,
object: sayDataFactory.contentLiteral(),
},
],
},
schema.text(title),
);
} else {
// Link node-spec uses classic RDFa
return linkType.create(
{
href: uri,
property: 'eli:cites',
typeof: 'eli:LegalExpression',
},
[schema.text(title)],
);
}
}
7 changes: 4 additions & 3 deletions addon/plugins/document-title-plugin/nodes/document-title.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { NodeSpec, getRdfaAttrs, rdfaAttrs } from '@lblod/ember-rdfa-editor';
import { NodeSpec, getRdfaAttrs, rdfaAttrSpec } from '@lblod/ember-rdfa-editor';

import { ELI } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';

import { hasRDFaAttribute } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';

const rdfaAware = true;
export const document_title: NodeSpec = {
content: 'paragraph{1}',
inline: false,
Expand All @@ -12,7 +13,7 @@ export const document_title: NodeSpec = {
group: '',
allowSplitByTable: false,
attrs: {
...rdfaAttrs,
...rdfaAttrSpec({ rdfaAware }),
property: {
default: 'eli:title',
},
Expand All @@ -28,7 +29,7 @@ export const document_title: NodeSpec = {
tag: 'h1,h2,h3,h4,h5',
getAttrs(element: HTMLElement) {
if (hasRDFaAttribute(element, 'property', ELI('title'))) {
return getRdfaAttrs(element);
return getRdfaAttrs(element, { rdfaAware });
}
return false;
},
Expand Down
7 changes: 4 additions & 3 deletions addon/plugins/roadsign-regulation-plugin/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getRdfaAttrs, NodeSpec, rdfaAttrs } from '@lblod/ember-rdfa-editor';
import { getRdfaAttrs, NodeSpec, rdfaAttrSpec } from '@lblod/ember-rdfa-editor';
import {
DCT,
EXT,
Expand All @@ -10,11 +10,12 @@ import { hasRDFaAttribute } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/n
const CONTENT_SELECTOR = `div[property~='${
DCT('description').full
}'],div[property~='${DCT('description').prefixed}']`;
const rdfaAware = false;
export const roadsign_regulation: NodeSpec = {
content: 'block+',
group: 'block',
attrs: {
...rdfaAttrs,
...rdfaAttrSpec({ rdfaAware }),
resourceUri: {},
measureUri: {},
zonality: {},
Expand Down Expand Up @@ -96,7 +97,7 @@ export const roadsign_regulation: NodeSpec = {
measureUri,
zonality,
temporal,
...getRdfaAttrs(node),
...getRdfaAttrs(node, { rdfaAware }),
};
}
return false;
Expand Down
Loading

0 comments on commit 3cc0097

Please sign in to comment.