From 7f07d898fd62e4e377ccdcc5dd4f917c0488715b Mon Sep 17 00:00:00 2001 From: kj Date: Tue, 28 May 2024 21:02:40 -0700 Subject: [PATCH 1/6] Update inserts slot for unnamed slot text content --- index.mjs | 19 ++++++++++++++++++- test/enhance.test.mjs | 16 +++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/index.mjs b/index.mjs index 5c00a4d..7aaf7b9 100644 --- a/index.mjs +++ b/index.mjs @@ -265,12 +265,29 @@ function fillSlots(node, template) { const children = nodeChildren.length ? nodeChildren : [ ...slot.childNodes ] + const wrappedChildren = children + .filter(child => child.nodeName === '#text' + ? child.value.trim().length + : true + ) + .map(child => { + return child.nodeName === '#text' + ? { + nodeName: 'span', + tagName: 'span', + attrs: [ + { name: 'slot', value: ' '} + ], + childNodes: [child] + } + : child + }) const slotParentChildNodes = slot.parentNode.childNodes slotParentChildNodes.splice( slotParentChildNodes .indexOf(slot), 1, - ...children + ...wrappedChildren ) }) diff --git a/test/enhance.test.mjs b/test/enhance.test.mjs index 941cc09..05a1852 100644 --- a/test/enhance.test.mjs +++ b/test/enhance.test.mjs @@ -67,7 +67,7 @@ test('default content in unnamed slot', t => { ` const expected = ` - + ` t.equal( @@ -115,7 +115,7 @@ test('should replace default content in unnamed slot', t => { ` const expected = ` - + ` t.equal( @@ -304,12 +304,14 @@ test('add authored children to unnamed slot', t => { const actual = html`

Custom title

+ Just text
` const expected = `

My Content

Custom title

+ Just text
` @@ -883,7 +885,7 @@ test('should support nested custom elements with nested slots', t => {

- My Heading + My Heading

@@ -997,9 +999,9 @@ ${Head()} -first -second -first again + first + second + first again ` @@ -1092,7 +1094,7 @@ test('multiple slots with unnamed slot first', t => { ` const expected = ` - unnamed slot
slot One
+ unnamed slot
slot One
` t.equal( From fd56f30c410542b35359ec566a02c738055b4d9f Mon Sep 17 00:00:00 2001 From: Cole Peters Date: Tue, 23 Apr 2024 13:33:33 -0500 Subject: [PATCH 2/6] Update readme --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cecbda4..bb8a9cc 100644 --- a/README.md +++ b/README.md @@ -213,21 +213,6 @@ function MyTransformScript({ html }) { console.log(html``) ``` -### `bodyContent` -Enhance SSR outputs an entire valid HTML page but you can pass `bodyContent: true` to get the content of the body element. This can be useful for when you want to isolate output HTML to only the Custom Element you are authoring. - -```javaScript -const html = enhance({ - bodyContent: true, - elements: { - 'my-paragraph': MyParagraph, - } -}) -const output = html` - - ` -``` - ### `context` There are times you will need to pass state to nested child custom elements. To avoid the tedium of passing attributes through multiple levels of nested elements Enhance SSR supplies a `context` object to add state to. @@ -283,5 +268,46 @@ export default function MyInstanceID({ html, state }) { ``` +### `bodyContent` +Enhance SSR outputs an entire valid HTML page but you can pass `bodyContent: true` to get just the content of the `` element. This can be useful for when you want to isolate the HTML output to just the Custom Element(s) you are authoring. + +```javaScript +const html = enhance({ + bodyContent: true, + elements: { + 'my-paragraph': MyParagraph, + } +}) +const output = html` + + ` +``` + +### Integration with ``, ``, and `` elements + +Enhance SSR will intelligently merge its rendered ``, ``, and `` elements with any that you provide to it (unless you choose to use the `bodyContent: true` option). + +For example: + +```js +const html = enhance({ + elements: { + 'my-content': MyContent, + } +}) + +html` + + + + My Website + + + + + +` +``` > P.S. Enhance works really well with [Begin](https://begin.com). + From 04c211accc6171302dc8f957e7a5468ebd8dfa22 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Tue, 7 May 2024 14:21:54 -0400 Subject: [PATCH 3/6] Create cla.yml --- .github/workflows/cla.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/cla.yml diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml new file mode 100644 index 0000000..5612162 --- /dev/null +++ b/.github/workflows/cla.yml @@ -0,0 +1,30 @@ +name: "CLA Assistant" +on: + issue_comment: + types: [created] + pull_request_target: + types: [opened,closed,synchronize] + +permissions: + actions: write + contents: write + pull-requests: write + statuses: write + +jobs: + CLAAssistant: + runs-on: ubuntu-latest + steps: + - name: "CLA Assistant" + if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' + uses: contributor-assistant/github-action@v2.4.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + with: + path-to-signatures: 'signatures/v1/cla.json' + path-to-document: 'https://github.com/enhance-dev/.github/blob/main/CLA.md' + branch: 'main' + allowlist: brianleroux,colepeters,kristoferjoseph,macdonst,ryanbethel,ryanblock,tbeseda + remote-organization-name: enhance-dev + remote-repository-name: .github From be8f30c44bf051aea2486c50d3ef691af9a3909d Mon Sep 17 00:00:00 2001 From: kj Date: Thu, 30 May 2024 11:28:01 -0700 Subject: [PATCH 4/6] 4.0.2-next.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5689f89..74ec42d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@enhance/ssr", - "version": "4.0.1", + "version": "4.0.2-next.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@enhance/ssr", - "version": "4.0.1", + "version": "4.0.2-next.0", "license": "Apache-2.0", "dependencies": { "@begin/parse5": "^0.0.4", diff --git a/package.json b/package.json index 79b01c6..414787c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@enhance/ssr", - "version": "4.0.1", + "version": "4.0.2-next.0", "description": "Server-side rendering for custom elements with template and slots support", "engines": { "node": ">=14.0.0" From a5532251fa29bb3b4b1aff115efc8261b6a1a796 Mon Sep 17 00:00:00 2001 From: kj Date: Fri, 31 May 2024 16:10:50 -0700 Subject: [PATCH 5/6] Updates slot attribute set. --- index.mjs | 2 +- test/enhance.test.mjs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/index.mjs b/index.mjs index 7aaf7b9..91012f8 100644 --- a/index.mjs +++ b/index.mjs @@ -276,7 +276,7 @@ function fillSlots(node, template) { nodeName: 'span', tagName: 'span', attrs: [ - { name: 'slot', value: ' '} + { name: 'slot', value: ''} ], childNodes: [child] } diff --git a/test/enhance.test.mjs b/test/enhance.test.mjs index 05a1852..e63339c 100644 --- a/test/enhance.test.mjs +++ b/test/enhance.test.mjs @@ -67,7 +67,7 @@ test('default content in unnamed slot', t => { ` const expected = ` - + ` t.equal( @@ -115,7 +115,7 @@ test('should replace default content in unnamed slot', t => { ` const expected = ` - + ` t.equal( @@ -311,7 +311,7 @@ test('add authored children to unnamed slot', t => {

My Content

Custom title

- Just text + Just text
` @@ -885,7 +885,7 @@ test('should support nested custom elements with nested slots', t => {

- My Heading + My Heading

@@ -999,9 +999,9 @@ ${Head()} - first - second - first again + first + second + first again ` @@ -1094,7 +1094,7 @@ test('multiple slots with unnamed slot first', t => { ` const expected = ` - unnamed slot
slot One
+ unnamed slot
slot One
` t.equal( From 680063cf56988f868699dbb1e64d72f0e200c1be Mon Sep 17 00:00:00 2001 From: kj Date: Fri, 31 May 2024 16:14:11 -0700 Subject: [PATCH 6/6] Updates deps --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 414787c..b1576b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@enhance/ssr", - "version": "4.0.2-next.0", + "version": "4.0.1", "description": "Server-side rendering for custom elements with template and slots support", "engines": { "node": ">=14.0.0" @@ -8,14 +8,14 @@ "type": "module", "main": "index.mjs", "scripts": { - "test": "tape-es ./test/enhance.test.mjs | tap-arc" + "test": "tape ./test/enhance.test.mjs | tap-arc" }, "keywords": [], "author": "kj ", "license": "Apache-2.0", "devDependencies": { - "tap-arc": "^1.2.2", - "tape-es": "^1.2.17" + "tape": "^5.7.5", + "tap-arc": "^1.2.2" }, "dependencies": { "@begin/parse5": "^0.0.4",