Skip to content

Commit

Permalink
fix(output): add prop slotContent for default slot content in output …
Browse files Browse the repository at this point in the history
…html
  • Loading branch information
Thorn Walli committed Mar 14, 2021
1 parent b054f24 commit d8f6c5b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 52 deletions.
13 changes: 1 addition & 12 deletions docs/content/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,8 @@ For cross-browser [compatibility](https://github.com/ungap/custom-elements#compa

### Live Example

<client-only>
<custom-element-app-example title="Live Example">
<div>
Live Example Content
</div>
</custom-element-app-example>
</client-only>
<iframe style="width: 100%; height: 320px; border: none;" src="https://nuxt-custom-elements.grabarzundpartner.dev/example/component-app-example/"></iframe>

<script type=text/javascript>
window.customPublicPath = 'https://nuxt-custom-elements.grabarzundpartner.dev/example/component-app-example/';
</script>
<script src="https://nuxt-custom-elements.grabarzundpartner.dev/example/component-app-example/component-app-example.modern.js" type="module"></script>
<script src="https://nuxt-custom-elements.grabarzundpartner.dev/example/component-app-example/component-app-example.client.js" nomodule></script>

#### Code

Expand Down
29 changes: 16 additions & 13 deletions docs/content/en/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,27 @@ Allows the targeted distribution of resources.

### Tag

| Key | Type | Requried | Description | Default |
| --------- | -------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `name` | `String` | yes | Name of the Tag. Value will be converted to ParamCase later.<br><br>Example: `TagName` -> `tag-name` | |
| `async` | `Boolean` | | Components are loaded asynchronously. If there is more than one entry the async will lead to unwanted webpack chunk splitting. | `false` |
| `path` | `String` | | Path to the component to be called by the tag. | `false` |
| `options` | `Function`, `Object` | | Options from custom-element. <br>[Learn more](https://github.com/karol-f/vue-custom-element#options) about `vue-custom-element` options. | `undefined` |
| Key | Type | Requried | Description | Default |
| ------------- | -------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `name` | `String` | yes | Name of the Tag. Value will be converted to ParamCase later.<br><br>Example: `TagName` -> `tag-name` | |
| `async` | `Boolean` | | Components are loaded asynchronously. If there is more than one entry the async will lead to unwanted webpack chunk splitting. | `false` |
| `path` | `String` | | Path to the component to be called by the tag. | `false` |
| `options` | `Function`, `Object` | | Options from custom-element. <br>[Learn more](https://github.com/karol-f/vue-custom-element#options) about `vue-custom-element` options. | `undefined` |
| `slotContent` | `String` | | Default slot content for generated html entry output. | `undefined` |

#### Important

You can set as `object` or when using functions in options, use `function`.

```js
{
name: 'ComponentAppBundle',
name: 'ComponentAppExample',
tags: [
// with function call
{
async: true,
name: 'CustomElementAppI18n',
path: '@/components/apps/AppI18n',
name: 'CustomElementAppExample',
path: '@/components/apps/AppExample',
options () {
return {
props: {
Expand All @@ -117,18 +118,20 @@ You can set as `object` or when using functions in options, use `function`.
console.info('constructorCallback', this);
}
};
}
},
slotContent: '<div>Slot Content!</div>'
},
// without function call
{
async: true,
name: 'CustomElementAppI18n',
path: '@/components/apps/AppI18n',
name: 'CustomElementAppExample',
path: '@/components/apps/AppExample',
options: {
props: {
base: './'
}
}
},
slotContent: '<div>Slot Content!</div>'
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion example/components/apps/AppExample.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ export default {
min-height: 160px;
padding: 15px;
margin-top: 20px;
font-family: sans-serif;
& > div,
& >>> div {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
font-family: sans-serif;
font-size: 30px;
font-weight: 700;
}
Expand Down
5 changes: 3 additions & 2 deletions example/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ module.exports = {
path: '@/components/apps/AppExample',
options: {
props: {
title: 'Prop. Title'
title: 'Live Example'
}
}
},
slotContent: '<div>Live Example Content</div>'
}
]
}]) || []),
Expand Down
26 changes: 3 additions & 23 deletions lib/utils/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,12 @@ function getTagHTMLFromEntry (entry) {
}
}

return `<${tag.name} ${props.join(' ')}></${tag.name}>`;
});
}

function getTagHTMLFromEntries (entries) {
const tags = entries.reduce((result, entry) => {
result.push(...getTagsFromEntry(entry));
return result;
}, []);
return tags.map((tag) => {
const options = tag.options || {};
const props = (Object.keys(options.props || {})).reduce((result, prop) => {
const value = options.props[String(prop)];
if (value) {
result.push(`${paramCase(prop)}="${value}"`);
}
return result;
}, [
''
]);
return `<${tag.name}${props.join(' ')}></${tag.name}>`;
const slotContent = tag.slotContent || '';
return `<${tag.name} ${props.join(' ')}>${slotContent}</${tag.name}>`;
});
}

module.exports = {
getTagsFromEntry,
getTagHTMLFromEntry,
getTagHTMLFromEntries
getTagHTMLFromEntry
};
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"babel-jest": "26.6.3",
"commitlint": "12.0.1",
"core-js": "3.9.1",
"cors": "^2.8.5",
"eslint": "7.22.0",
"eslint-formatter-json-relative": "0.1.0",
"eslint-plugin-no-secrets": "0.8.9",
Expand Down
3 changes: 3 additions & 0 deletions tools/express-server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { paramCase } = require('change-case');
const express = require('express');
const cors = require('cors');
const app = express();

app.use(cors());
app.disable('x-powered-by');

const dist = getDist();
Expand Down

0 comments on commit d8f6c5b

Please sign in to comment.