Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

VDOM Util #53

Merged
merged 23 commits into from
Oct 1, 2018
Merged

VDOM Util #53

merged 23 commits into from
Oct 1, 2018

Conversation

trieloff
Copy link
Contributor

For #43

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #53 into master will increase coverage by 0.1%.
The diff coverage is 97.64%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #53     +/-   ##
=========================================
+ Coverage    97.1%   97.21%   +0.1%     
=========================================
  Files          18       20      +2     
  Lines         346      431     +85     
  Branches       58       68     +10     
=========================================
+ Hits          336      419     +83     
- Misses         10       12      +2
Impacted Files Coverage Δ
src/utils/index.js 100% <100%> (ø) ⬆️
src/html/make-html.js 100% <100%> (ø) ⬆️
src/utils/image-handler.js 100% <100%> (ø)
src/utils/mdast-to-vdom.js 100% <100%> (ø)
src/html/output-debug.js 88.88% <33.33%> (-11.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4494127...82b34fe. Read the comment docs.

@trieloff trieloff changed the title WIP: VDOM Util VDOM Util Sep 24, 2018
@trieloff
Copy link
Contributor Author

@kptdobe please have a look.

If we merge this, we can remove content.htast and content.html (and probably content.children) as they are redundant with content.document, content.document.innerHTML and content.document.children.

@kptdobe
Copy link
Contributor

kptdobe commented Sep 24, 2018

ok, I'll review this afternoon.

Copy link
Contributor

@tripodsan tripodsan left a comment

Choose a reason for hiding this comment

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

in VDOMTRansformer:

  • do you really want to export all static methods?
  • it would be good to add js doc to all methods and declare the ones considered private with @private.

});
}

static toHTAST(htmlstr, cb, node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

jsdoc?

return cb(node, 'div', {}, htast.children);
}

static handle(cb, node, parent, that) {
Copy link
Contributor

Choose a reason for hiding this comment

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

jsdoc?

return result;
}

static default(node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

jsdoc?

return handlers[node.type];
}

match(matcher, processor) {
Copy link
Contributor

Choose a reason for hiding this comment

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

jsdoc?

this._matchers.push([matchfn, processor]);
}

matches(node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

jsdoc?

return processors[0];
}

static matchfn(ast, pattern) {
Copy link
Contributor

Choose a reason for hiding this comment

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

jsdoc?

};
}

process() {
Copy link
Contributor

Choose a reason for hiding this comment

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

jsdoc?

return tohyper(h, tohast(this._root, { handlers: this._handlers }));
}

getDocument() {
Copy link
Contributor

Choose a reason for hiding this comment

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

jsdoc?

@kptdobe
Copy link
Contributor

kptdobe commented Sep 24, 2018

I tried the code with the initial project (hlx demo test) and the document object contains only an "blank" location object (no children, no innerHTML...)
I tested by using the console output of the payload requesting: http://localhost:3000/index.html?debug=true

@kptdobe
Copy link
Contributor

kptdobe commented Sep 24, 2018

It is the "JSONification" of the document object which does not work. A breakpoint in the pre.js shows me the content.document object full of stuff!

@trieloff trieloff dismissed tripodsan’s stale review September 25, 2018 08:56

Implemented all suggestions.

@kptdobe
Copy link
Contributor

kptdobe commented Sep 25, 2018

I started to look into this PR and I really do not understand where we go with this:

  • we now have a huge content.document object which is a representation of the browser DOM, including all events (onmousemove...) which is completely useless. Just for the sake of having some helper methods like 'querySelector' or 'querySelectorAll' there are millions of useless stuff around.
  • I still do not understand who is going to use things like content.document.getElementsByTagName('h1') and to do what... My assumption is that a web developer will want to work with HTL and a developer preparing the data or convertir the sections into something project specific might want to go more for a simplified version of the mdast, basically a json representation.

This looks sooo complicated for the needs we have at the moment.

If you could illustrate how this would be used, that would be great.

@trieloff
Copy link
Contributor Author

The basic motivation for this is outlined in @simonwex's issue adobe/project-helix#305:

Mark

Mark is using Helix to power the adobe.io website by outputting HTML
Mark needs to restructure the content to efficiently produce attractive layouts without the adobe.io content authors having to have special formatting knowledge

  • When styling the content, he uses CSS selectors to identify content
  • When manipulating the content structure, he works with the DOM API

So the idea is to give Mark an API for manipulating HTML that he is familiar with, instead of forcing him to learn HTAST (as great as it might be with all the unist-utils) or any new content structure (that we haven't defined in more than a couple of months, see #24)

we now have a huge content.document object which is a representation of the browser DOM, including all events (onmousemove…) which is completely useless.

It might be useless, but I'd argue there is little harm done and it can increase compatibility when the developer is introducing their favorite library that happens to access onmousemove without any guards.

I still do not understand who is going to use things like content.document.getElementsByTagName('h1') and to do what... My assumption is that a web developer will want to work with HTL and a developer preparing the data or convertir the sections into something project specific might want to go more for a simplified version of the mdast, basically a json representation.

Below are a couple of examples of how I could see this play out. They all have in common that the developer does not want to touch anything that looks like Markdown, but is very familiar with the DOM.

Super Simple

Mark is fine with the HTML content and just wants it printed as is:

<body>
${content.document.innerHTML}
</body>

Easy.

Wrapping top-level elements

This replaces the it.children iterator.

<div data-sly-list="${content.document.childNodes}">${item.innerHTML}</div>

Adjusting Headlines

This takes a little work in pre.js:

// remove the first heading
const firstheading = content.document.querySelector('h1');
firstheading.parentNode.removeChild(firstheading);

// downgrade all remaining h1 to h2
content.document.getElementsByTagName('h1').map(heading => {
  heading.outerHTML = '<h2>' + heading.innerHTML + '</h2>';
});
<body>
<h1 class="myheading">${content.meta.title}</h1>
${content.document.innerHTML}
</body>

In all examples, you could even prototype the code on the client, in the web developer console before moving it server-side.

@simonwex
Copy link

This is much tidier than I thought it would be. You nailed the use-case. Nice work!

I'll try to use it for real at some point this week, but from my static inspection, it looks like a great candidate to merge.

@trieloff trieloff changed the title VDOM Util WIP: VDOM Util Sep 26, 2018
@trieloff
Copy link
Contributor Author

@kptdobe @simonwex I'm putting this back in WIP, as I noticed that the PR would break the image responsifyer, which is working on HTAST. I will need to re-implement that on top of the new DOM.

@trieloff trieloff changed the title WIP: VDOM Util VDOM Util Sep 26, 2018
@trieloff
Copy link
Contributor Author

Some more documentation to describe how custom sizes for responsive images can be created.

@trieloff trieloff mentioned this pull request Sep 27, 2018
@trieloff trieloff merged commit 3b1dcab into master Oct 1, 2018
@tripodsan tripodsan deleted the util-vdomino branch October 2, 2018 00:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants