Skip to content

Commit

Permalink
[patch] export nothing from lit and allow it in HTML interpolations
Browse files Browse the repository at this point in the history
  • Loading branch information
electrovir committed Jan 16, 2024
1 parent 1e3f090 commit e758495
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 31 deletions.
20 changes: 10 additions & 10 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@electrovir/element-vir-mono-repo",
"version": "20.0.1",
"version": "20.0.2",
"private": true,
"license": "(MIT or CC0 1.0)",
"author": {
Expand All @@ -15,7 +15,7 @@
"compile": "mono-vir for-each \"rm -rf dist && rm -f tsconfig.tsbuildinfo && tsc -b --pretty\"",
"docs": "mono-vir for-each-async npm run --if-present docs",
"format": "virmator format",
"publish": "virmator publish \"npm run compile && npm run --workspace @electrovir/scripts update:deps && npm run test:all\"",
"publish": "virmator publish \"npm run compile && npm run --workspace @electrovir/scripts update:deps && npm i && npm run test:all\"",
"test": "mono-vir for-each-async npm test",
"test:all": "concurrently -c auto -m 90% --kill-others-on-fail --colors --names tests,spelling,format,docs,build \"npm run test:coverage\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\" \"npm run build:pages\"",
"test:coverage": "npm run test coverage",
Expand Down
2 changes: 1 addition & 1 deletion packages/element-book-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@electrovir/element-book-example",
"version": "20.0.1",
"version": "20.0.2",
"private": true,
"license": "(MIT or CC0 1.0)",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/element-book/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "element-book",
"version": "20.0.1",
"version": "20.0.2",
"keywords": [
"book",
"design system",
Expand Down Expand Up @@ -49,7 +49,7 @@
"object-shape-tester": "^1.0.3",
"spa-router-vir": "^3.0.3",
"typed-event-target": "^3.0.1",
"vira": "20.0.1"
"vira": "20.0.2"
},
"devDependencies": {
"@augment-vir/browser-testing": "^22.4.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {isLengthAtLeast, mapObjectValues} from '@augment-vir/common';
import {HTMLTemplateResult, HtmlInterpolation, html, repeat} from 'element-vir';
import {HTMLTemplateResult, HtmlInterpolation, html, nothing, repeat} from 'element-vir';
import {BookEntryTypeEnum} from '../../../../data/book-entry/book-entry-type';
import {
BookPageControlsInitBase,
Expand Down Expand Up @@ -123,12 +123,12 @@ export function createNodeTemplates({
fullUrlBreadcrumbs: hiddenAncestorControls.breadcrumbs,
})}></${BookPageControls}>
`
: '';
: nothing;

const templates = repeat(
currentNodes,
(node) => node.fullUrlBreadcrumbs.join('>'),
(currentNode, index): HTMLTemplateResult | string => {
(currentNode, index): HTMLTemplateResult | typeof nothing => {
if (isBookTreeNode(currentNode, BookEntryTypeEnum.Page)) {
return html`
<${BookPageWrapper.assign({
Expand Down Expand Up @@ -156,7 +156,7 @@ export function createNodeTemplates({
></${BookElementExampleWrapper}>
`;
} else if (isBookTreeNode(currentNode, BookEntryTypeEnum.Root)) {
return '';
return nothing;
} else {
return html`
<${BookError.assign({
Expand All @@ -172,5 +172,5 @@ export function createNodeTemplates({
return [
hiddenAncestorControlsTemplate,
templates,
].flat();
];
}
2 changes: 1 addition & 1 deletion packages/element-vir-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@electrovir/element-vir-example",
"version": "20.0.1",
"version": "20.0.2",
"private": true,
"license": "(MIT or CC0 1.0)",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/element-vir/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "element-vir",
"version": "20.0.1",
"version": "20.0.2",
"keywords": [
"custom",
"web",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ export function defineElementNoInputs<
caught,
`Failed to render ${init.tagName}`,
);
console.error(error);
this._lastRenderError = error;
return extractErrorMessage(error);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/element-vir/src/lit-exports/base-lit-exports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {LitElement, noChange, svg, unsafeCSS} from 'lit';
export {LitElement, noChange, nothing, svg, unsafeCSS} from 'lit';
export type {
CSSResult,
CSSResultGroup,
Expand Down
6 changes: 3 additions & 3 deletions packages/element-vir/src/lit-exports/lit-repeat-fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export interface RepeatDirectiveFn {
items: Iterable<T>,
keyFnOrTemplate: KeyFn<T> | ItemTemplate<T>,
template?: ItemTemplate<T>,
): HtmlInterpolation;
<T>(items: Iterable<T>, template: ItemTemplate<T>): HtmlInterpolation;
): HtmlInterpolation[];
<T>(items: Iterable<T>, template: ItemTemplate<T>): HtmlInterpolation[];
<T>(
items: Iterable<T>,
keyFn: KeyFn<T> | ItemTemplate<T>,
template: ItemTemplate<T>,
): HtmlInterpolation;
): HtmlInterpolation[];
}
export const repeat = repeatImport as RepeatDirectiveFn;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {assertTypeOf} from 'run-time-assertions';
import {renderIf} from '../../declarative-element/directives/render-if.directive';
import {RenderCallback} from '../../declarative-element/render-callback';
import {classMap} from '../../lit-exports/all-lit-exports';
import {classMap, ifDefined} from '../../lit-exports/all-lit-exports';
import {DirectiveOutput, HtmlInterpolation} from './html-interpolation';
import {html} from './vir-html';

Expand All @@ -22,6 +22,12 @@ describe('HtmlInterpolation', () => {
assertTypeOf(Symbol('hello')).not.toMatchTypeOf<HtmlInterpolation>();
});

it('allows the ifDefined directive', () => {
html`
<div title=${ifDefined(Math.random() > 0.5 ? undefined : 'hello')}></div>
`;
});

/** In order to support directive results, this must also be the case. */
it('allows empty objects sadly', () => {
assertTypeOf({} as const).toMatchTypeOf<HtmlInterpolation>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {AnyFunction} from '@augment-vir/common';
import {CSSResult, TemplateResult} from 'lit';
import {CSSResult, TemplateResult, nothing} from 'lit';
import {EmptyObject} from 'type-fest';
import {DeclarativeElementDefinition} from '../../declarative-element/declarative-element';
import {MinimalDefinitionWithInputs} from '../minimal-element-definition';
Expand Down Expand Up @@ -28,4 +28,5 @@ export type HtmlInterpolation =
| DeclarativeElementDefinition
| DirectiveOutput
| AnyFunction
| typeof nothing
| HtmlInterpolation[];
2 changes: 1 addition & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@electrovir/scripts",
"version": "20.0.1",
"version": "20.0.2",
"private": true,
"license": "(MIT or CC0 1.0)",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/vira-book/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@electrovir/vira-book",
"version": "20.0.1",
"version": "20.0.2",
"private": true,
"license": "(MIT or CC0 1.0)",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/vira/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vira",
"version": "20.0.1",
"version": "20.0.2",
"description": "A simple and highly versatile design system using element-vir.",
"keywords": [
"design",
Expand Down

0 comments on commit e758495

Please sign in to comment.