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

Release 1.5.0 #22

Merged
merged 20 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ coverage
examples
jest.config.js
.github
**.js.map
12 changes: 6 additions & 6 deletions dist/cwco.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/cwco.min.js.map

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions docs/examples/attr-default.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@
"readonly",
"sub-type"
];
/**
* Inside the component is a safe place to define your
* attribute default values
*/
subType = "primary";
type = "button";


get template() {
/**
* Inside the template is a safe place to define your
* attribute default values since it won't trigger the
* onUpdate lifecycle callback
*/
this.subType = this.subType || "primary";
this.type = this.type || "button";

/**
* Every attribute with value will be parsed to
* their respective Javascript object or primitive value
Expand Down
1,023 changes: 607 additions & 416 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cwco",
"version": "1.4.8",
"description": "Contextful Web Component Library",
"version": "1.5.0",
"description": "Powerful and Fast Web Component Library with a Simple API",
"main": "dist/index.js",
"scripts": {
"test": "jest",
Expand Down Expand Up @@ -32,11 +32,11 @@
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/jsdom": "^16.2.13",
"esbuild": "^0.14.2",
"esbuild": "^0.14.18",
"jest": "^27.4.4",
"jest-environment-jsdom": "^27.4.4",
"nodemon": "^2.0.13",
"ts-jest": "^27.1.1",
"typescript": "^4.5.3"
"typescript": "^4.5.5"
}
}
9 changes: 4 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// cwco, copyright (c) by Elson Correia
// cwco, copyright (c) by Elson Correia / Before Semicolon
// Distributed under an MIT license: https://github.com/beforesemicolon/cwco/blob/master/LICENSE

import {WebComponent} from './web-component';
import {Directive} from './directive';
import {ContextProviderComponent} from './context-provider-component';
import {WebComponent} from './core/web-component';
import {Directive} from './core/directive';
import {ContextProviderComponent} from './core/context-provider-component';
import {html} from "./utils/html";

// @ts-ignore
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ContextProviderComponent} from "./context-provider-component";
import {WebComponent} from "./web-component";
import {ShadowRootModeExtended} from "./enums/ShadowRootModeExtended.enum";
import {ShadowRootModeExtended} from "../enums/ShadowRootModeExtended.enum";

describe('ContextProviderComponent', () => {
describe('slot', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ShadowRootModeExtended} from "./enums/ShadowRootModeExtended.enum";
import {ShadowRootModeExtended} from "../enums/ShadowRootModeExtended.enum";
import {WebComponent} from "./web-component";
import {CWCO} from "./cwco";
import {CWCO} from "../cwco";

/**
* a special WebComponent that handles slot tag differently allowing for render template right into HTML files
Expand Down
6 changes: 3 additions & 3 deletions src/directive.ts → src/core/directive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {directiveRegistry} from "./directives/registry";
import {directiveRegistry} from "../directives/registry";
import {$} from "./metadata";
import {defineNodeContextMetadata} from "./utils/define-node-context-metadata";
import {CWCO} from "./cwco";
import {defineNodeContextMetadata} from "../tracker/utils/define-node-context-metadata";
import {CWCO} from "../cwco";

export class Directive implements CWCO.Directive {
constructor(component: CWCO.WebComponent) {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {proxify} from './proxify';
import boolAttr from './boolean-attributes.json';
import {directives} from "../directives";
import {jsonParse} from "./json-parse";
import {proxify} from '../../utils/proxify';
import boolAttr from '../boolean-attributes.json';
import {directives} from "../../directives";
import {jsonParse} from "../../utils/json-parse";
import {$} from "../metadata";
import {CWCO} from "../cwco";
import {isPrimitive} from "./is-primitive";
import {CWCO} from "../../cwco";
import {isPrimitive} from "../../utils/is-primitive";

export function setComponentPropertiesFromObservedAttributes(
comp: CWCO.WebComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {turnCamelToKebabCasing} from "./turn-camel-to-kebab-casing";
import {directives} from "../directives";
import {proxify} from "./proxify";
import {CWCO} from "../cwco";
import {isPrimitive} from "./is-primitive";
import {turnCamelToKebabCasing} from "../../utils/turn-camel-to-kebab-casing";
import {directives} from "../../directives";
import {proxify} from "../../utils/proxify";
import {CWCO} from "../../cwco";
import {isPrimitive} from "../../utils/is-primitive";

export function setupComponentPropertiesForAutoUpdate(comp: CWCO.WebComponent, onUpdate: CWCO.onUpdateCallback): string[] {
const properties: string[] = [];
Expand Down
111 changes: 87 additions & 24 deletions src/web-component.spec.ts → src/core/web-component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {WebComponent} from './web-component';
import {ShadowRootModeExtended} from "./enums/ShadowRootModeExtended.enum";
import {ShadowRootModeExtended} from "../enums/ShadowRootModeExtended.enum";

describe('WebComponent', () => {

Expand Down Expand Up @@ -800,27 +800,27 @@ describe('WebComponent', () => {
s.data = 12;

expect(updateSpy).toHaveBeenCalledWith(12);
updateSpy.mockClear()

s.data = '{"x": 12}';

expect(updateSpy).toHaveBeenCalledWith({x: 12});
updateSpy.mockClear()

s.data = {x: 12};

expect(updateSpy).toHaveBeenCalledWith({x: 12});
updateSpy.mockClear()

s.data = new Set([12]);

expect(updateSpy).toHaveBeenCalledWith(expect.any(Set));
updateSpy.mockClear()

s.data = () => 12

expect(updateSpy).toHaveBeenCalledWith(expect.any(Function));
updateSpy.mockClear()
// updateSpy.mockClear()
//
// s.data = '{"x": 12}';
//
// expect(updateSpy).toHaveBeenCalledWith({x: 12});
// updateSpy.mockClear()
//
// s.data = {x: 12};
//
// expect(updateSpy).toHaveBeenCalledWith({x: 12});
// updateSpy.mockClear()
//
// s.data = new Set([12]);
//
// expect(updateSpy).toHaveBeenCalledWith(expect.any(Set));
// updateSpy.mockClear()
//
// s.data = () => 12
//
// expect(updateSpy).toHaveBeenCalledWith(expect.any(Function));
// updateSpy.mockClear()
});
})

Expand Down Expand Up @@ -906,7 +906,7 @@ describe('WebComponent', () => {
title: 'Updated Text App'
});

expect(target?.root?.innerHTML).toBe('Text App');
expect(target?.root?.innerHTML).toBe('');

// should update the DOM to grab new context and data
app.root?.appendChild(target);
Expand Down Expand Up @@ -1629,7 +1629,70 @@ describe('WebComponent', () => {
expect(s.root?.innerHTML).toBe('<p>2</p><p>4</p><p>6</p><p>2</p><p>4</p><p>6</p>')
});

it.todo('should handle nested component repeats')
it('should handle nested component repeats', () => {
class SmallR extends WebComponent {
static observedAttributes = ['value'];

get template() {
return '{value}';
}
}

class RepeatF extends WebComponent {
static observedAttributes = ['obj'];
obj = {}

get template() {
return '<div name="{attr.name}" repeat="(obj.observedAttrs || []) as attr">' +
'<small-r if="attr.type === 2" value="{attr.value}"></small-r>' +
'</div>';
}
}

class ContainerP extends WebComponent {
val = {
observedAttrs: [
{name: 'A', type: 2, value: 'a'},
{name: 'B', type: 1, value: 'b'},
{name: 'C', type: 2, value: 'c'},
{name: 'D', type: 2, value: 'd'},
{name: 'E', type: 1, value: 'e'},
]
};

get template() {
return '<repeat-f obj="{val}"></repeat-f>';
}
}

SmallR.register();
RepeatF.register();
ContainerP.register();

const p = new ContainerP();

document.body.appendChild(p);

const r = p.root?.children[0] as WebComponent

expect(r.root?.innerHTML).toBe(
'<div name="A"><small-r value="a"></small-r></div>' +
'<div name="B"><!-- if: false --></div>' +
'<div name="C"><small-r value="c"></small-r></div>' +
'<div name="D"><small-r value="d"></small-r></div>' +
'<div name="E"><!-- if: false --></div>');

p.val = {
observedAttrs: [
{name: 'C', type: 2, value: 'c'},
{name: 'E', type: 1, value: 'e'},
]
};

expect(r.root?.innerHTML).toBe(
'<div name="C"><small-r value="c"></small-r></div>' +
'<div name="E"><!-- if: false --></div>')
})
});

describe('should allow mix of directives', () => {
Expand Down