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

Update article structure plugin to support rdfa editing #358

Merged
merged 16 commits into from
Dec 14, 2023

Conversation

piemonkey
Copy link
Collaborator

@piemonkey piemonkey commented Nov 28, 2023

Overview

Correctly support the insertion of any structures in the article structures plugin.

All comments should have been addressed, with the exception of pressing enter in the titles, which still creates a whole new structure with a new title. There are some design issues, but since we'll need to overhaul the design for editable nodes, I haven't done any tweaking.

connected issues and PRs:

This is made towards #357 with the intent that it collects all of the related changes rather than them being merged straight to master.
PR on editor repo

Setup

The 'editable nodes' route should now have the article structure plugin enabled.

How to test/reproduce

Inserting structure elements should function as expected.

Challenges/uncertainties

Checks PR readiness

  • UI: works on smaller screen sizes
  • UI: feedback for any loading/error states
  • Check if dummy app is correctly updated
  • Check cancel/go-back flows
  • changelog
  • npm lint
  • no new deprecations

@piemonkey piemonkey requested a review from elpoelma November 28, 2023 14:40
Copy link
Collaborator

@elpoelma elpoelma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The different article structures seem to be well integrated with the new rdfa-system already :) Very nice work!! I have added some comments with questions/remarks.

Some additional questions/remarks:

  • There still seem to be some issues with selections in and around structures, some of which also are related to the gap-cursor. We should look into improving that behaviour.
  • (not new) Pressing enter in a title splits the node in two, ideally enter should do nothing.
  • The different article structures have each two attribute-properties (heading and number), for which I'm not sure if these are (still) needed.
  • (design-related, not specific to this PR): we should probably make it clearer which parts of the structures are editable, and which are not (e.g. with different backgrounds, different cursors). Probably needs design input.
  • We could look into leveraging the properties and backlinks attributes in the parseDOM-rules in order to parse the different structures.

Comment on lines 51 to 59
{
type: 'attribute',
predicate: ELI('number').prefixed,
object: numberConverted,
},
{
type: 'attribute',
predicate: SAY('heading').prefixed,
object: `Artikel ${numberConverted}: ${titleText}`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason that these are still added as attribute-properties? As their content would also be included in the title-node right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my first idea of how to handle headings and titles with almost the same content, but I've now got a better version with them both as external properties. I'll add this to the PR soon now that I'm confident that the current weird issue I'm investigating isn't actually caused by this change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a version with heading split out, I'll put one in with number as an external tomorrow.

Comment on lines 50 to 59
{
type: 'attribute',
predicate: ELI('number').prefixed,
object: numberConverted,
},
{
type: 'attribute',
predicate: SAY('heading').prefixed,
object: `${numberConverted}. ${titleText}`,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark as above.

export const structure_header_title: NodeSpec = {
attrs: {
...rdfaAttrSpec,
__tag: { default: 'span' },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this attribute is necessary anylonger.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll remove it.

},
parseDOM: [
{
tag: 'div',
priority: 55,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment as to why this priority is added/needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this one actually as it wasn't necessary...

) {
return { resource: element.getAttribute('resource') };
const resource = element.getAttribute('resource');
if (hasRDFaAttribute(element, 'typeof', type) && resource) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we could do this check on the properties attribute of the incoming html-element now?
e.g.:

attrs.properties.some((prop) => prop.predicate === 'typeof' && prop.object.resource === type)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean. Do you mean to use getRdfaAttrs() to process the element and use the properties member of that attrs object?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the point prosemirror gets the html, it is already preprocessed to contain the properties and backlinks

parseDOM: [
{
tag: 'h1,h2,h3,h4,h5,h6,span',
priority: 60,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment on the reason of this priority?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note the schema you define for a doc is also priority-ordered, so if we put the structure nodes before the headers, it should also parse correctly with default prio
(gives more flexibility to the host app)

priority: 60,
getAttrs(element: HTMLElement) {
const level = TAG_TO_LEVEL.get(element.tagName.toLowerCase()) ?? 6;
const property = element.getAttribute('property');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do this check with the properties and backlinks attributes now I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I guess you mean rdfa attributes? So using the processed relationships rather than relying on specific html attributes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can also update the parseDOM of these nodes to leverage the properties and backlinks. The toDOM should also be updated to use the renderRdfaAware function. I'm also not sure if it will be necessary to keep all these seperate node-specs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this as a separate task, the only reason I changed these at all was to update the name rdfaAttrs to rdfaAttrSpec to reflect that the constant holds values in the format of a spec ({ [name]:{ default: 'value' } }), rather than in the format of attributes ({ [name]: 'value' }) as that wasn't clear from the original name.

@abeforgit abeforgit merged commit 2bf2680 into feat/rdfa-editing-ui Dec 14, 2023
@abeforgit abeforgit deleted the rdfa/article-structure branch December 14, 2023 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants