-
Notifications
You must be signed in to change notification settings - Fork 5
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
import and export components (v4.2.0) #40
Conversation
792b86f
to
35b8c1e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline Comments for Peer Review
<!-- styles --> | ||
<style> | ||
:root { | ||
background: rgb(31, 44, 57); | ||
background: linear-gradient(140deg, rgba(31, 44, 57, 1) 0%, rgba(49, 49, 26, 1) 100%); | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding a nice gradient to the background of the main website - including this here so that we always have this (even if the external stylesheet doesn't load).
The gradient itself was created with cssgradient.io
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving comments inline so that they are available for review 😅
// This script contains all the steps for generating the output results. | ||
// This can be triggered by running `npm run build` | ||
// | ||
// A majority of this file uses the UglifyJS API | ||
// https://www.npmjs.com/package/uglify-js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this new build.js
replaces the set of scripts that were in the package.json
. This is a more organized way to bundle and expose all the different scripts that we need, allows us to write comments, and have more consistent behavior across all the generated scripts.
Candidly, this is slightly more error prone, compared to the CLI interface (which is better documented), but all in all, worth the migration.
@@ -1,65 +0,0 @@ | |||
describe('Tram-Lite Example Components', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was moved to inline.cy.js
@@ -0,0 +1,120 @@ | |||
<h2>Importing And Exporting Components</h2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New documentation for the functionality added in this PR! 📝
I would advocate reviewing this locally, over reading the source code 😅
node output/export-components.js examples/components/ex-progressbar.html examples/components/ex-temperature.html examples/components/ex-container.html examples/components/ex-colorpicker.html -o examples/components/example-components.js | ||
node output/export-components.js examples/components/ex-colorpicker.html -o examples/components/ex-colorpicker.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, this is just a shell script, but we should migrate this with a JS API (separate issue #41)
@@ -0,0 +1,15 @@ | |||
<ex-colorpicker width="100px"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a copy-paste of the inline colorpicker example. Some thinking should happen around making this more consistent (see #42)
@@ -0,0 +1,29 @@ | |||
describe('Tram-Lite Example Components (via export)', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along with making the new example/test pages, we've also moved the cypress tests to be adjacent to the page files. This mimics the pattern common with unit-tests (where the tests are adjacent to the source code).
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<title>Tram-Lite Example Components</title> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was renamed to inline/index.html
@@ -194,18 +194,18 @@ class TramLite { | |||
* {@link https://tram-one.io/tram-lite/#appendShadowRootProcessor Read the full docs here.} | |||
* @param {string} matcher | |||
* @param {{ connect: function }} componentClass | |||
* @param {(node: Node) => boolean} [rootNodeTest=() => true] | |||
* @param {ShadowRoot} [shadowRoot=ShadowRoot.prototype] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The major change here is the update to appendShadowRootProcessor
, which for a short while supported a rootNodeTest
- this was never documented though, so not considering this a breaking change.
Instead, we are supporting a shadowRoot
parameter, which lets people focus the processor on a single component (useful when we don't want to update the behavior of all components everywhere).
/** | ||
* utility function to extract js template strings, so that they can be passed into a template tag function | ||
*/ | ||
static extractTemplateVariables(templateString) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracting out the template variable parsing so we can use that in the ImportComponent logic. This is otherwise unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
Summary
This version is available by pointing to tram-lite@beta.
https://unpkg.com/tram-lite@beta
This PR adds the ability for developers to import and export component definitions.
This allows developers to organize components, create libraries of components, and allow other developers to consume the components without needing Tram-Lite.
Importing Component Definitions
This method allows another developer to point to an HTML component definition, and load it directly in their page. It requires no other build steps.
Exporting Component Definitions
This method is a build step that transforms an html component definition into javascript that can be imported like any other JS library.
There is full documentation that can be read by cloning this branch and loading
npm run docs
.Other Changes
As part of the above changes, I've updated the build tooling to be a separate
build.js
script, and moved some of the tests around. This will likely continue to evolve over time, but was needed here to reign-in on some of the complexity that we have for all the different ways people can use components 👏Checklist