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

import and export components (v4.2.0) #40

Merged
merged 30 commits into from
Oct 8, 2023
Merged

Conversation

JRJurman
Copy link
Member

@JRJurman JRJurman commented Oct 7, 2023

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

<script src="https://unpkg.com/tram-lite@4/output/import-components.js" tl-components="./x-button.html"></script>

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

npx tram-lite@4 export-components x-button.html

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

  • PR Summary
  • PR Annotations
  • Tests
  • Version Bump

@JRJurman JRJurman changed the title import-component script import-component script (v4.2.0) Oct 7, 2023
Copy link
Member Author

@JRJurman JRJurman left a 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

Comment on lines +47 to +53
<!-- 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>
Copy link
Member Author

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

image

@JRJurman JRJurman marked this pull request as ready for review October 8, 2023 16:58
Copy link
Member Author

@JRJurman JRJurman left a 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 😅

Comment on lines +1 to +5
// 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
Copy link
Member Author

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', () => {
Copy link
Member Author

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>
Copy link
Member Author

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 😅

Comment on lines +1 to +2
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
Copy link
Member Author

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">
Copy link
Member Author

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)', () => {
Copy link
Member Author

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>
Copy link
Member Author

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]
Copy link
Member Author

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) {
Copy link
Member Author

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.

@JRJurman JRJurman changed the title import-component script (v4.2.0) import and export components (v4.2.0) Oct 8, 2023
Copy link
Collaborator

@chtinahow chtinahow left a comment

Choose a reason for hiding this comment

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

Lgtm

@JRJurman JRJurman merged commit ae0348d into main Oct 8, 2023
@JRJurman JRJurman deleted the import-export-component branch October 8, 2023 22:21
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.

2 participants