Skip to content

Commit 6e59fd6

Browse files
committed
upgrade
1 parent cdc1d72 commit 6e59fd6

5 files changed

Lines changed: 55 additions & 35 deletions

File tree

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,40 @@ use repeat:nameOfItem=[[enumerableExpression]] on a Template Element to repeat i
7171
You could also use 'index' variable in the repeat binding for the current number. The attribute "repeat-index" could be used to change the name of the index variable.
7272
on a repeat you could use the repeat-changed-item-callback="[[this.itemCreated(item, nodes)]]
7373
!!caution!! => the repeat binding is only a preview at the moment, it redraws all items on array change
74-
74+
75+
## Event Code Bindings
76+
77+
with for example @click="[[this.aa(event)]]" you could create a event binding wich could run any javascript code inside of the brackets.
78+
79+
7580
### Binding extensions
7681

7782
- Null/Undefined Extension {{? }} - If you start a binding with a questionmark (like this: {{?), the value of the binding is assigned as an empty string when null or undefined.
7883
- Invert extension {{! }} - If you use "!" on the start of a Binding, the bool value is inverted, and also asigned inverted (not yet developed, will do if needed)
7984

85+
## Declaritive Custom Element
86+
87+
With the node-projects-dce element you could create a custom elment declaritively, see:
88+
89+
Sample:
90+
91+
<node-projects-dce name="simple-dce-demo" properties='{"list":"Array", "list2":"Array", "ctx":{"type":"String","reflect":true}}' enable-bindings >
92+
<template>
93+
<style>h1 {color: red}</style>
94+
<h1>Hello World</h1>
95+
<div style="border: solid 3px black">Ctx: [[this.ctx]]</div>
96+
<template repeat:myitem="[[this.list]]">
97+
<button>[[myitem.toUpperCase()]] - <b>[[myitem.toLowerCase()]]</b> - [[index]]</button>
98+
<ul>
99+
<template repeat:myitem2="[[this.list2]]" repeat-index="inneridx">
100+
<button @click="[[this.ctx = myitem2]]" >[[myitem.toUpperCase()]] - <b>[[myitem2.toLowerCase()]]</b> - [[inneridx * 100]]</button>
101+
</template>
102+
</ul>
103+
</template>
104+
</template>
105+
</node-projects-dce>
106+
<simple-dce-demo list='["aa","bb","cc"]' list2='["hello", "you"]' ctx="TestCtx" style="position:absolute;left:184px;top:-53px;"></simple-dce-demo>
107+
80108
## Developing
81109

82110
* Install dependencies

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"description": "Base Custom Webcomponent",
33
"name": "@node-projects/base-custom-webcomponent",
4-
"version": "0.25.8",
4+
"version": "0.25.9",
55
"type": "module",
66
"main": "./dist/index.js",
77
"author": "",

sample/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ <h1>Hello World</h1>
7070
<h1>Hello World</h1>
7171
<div>[[this.ctx]]</div>
7272
<template repeat:myitem="[[this.list]]">
73-
<button @click="{{this.ctx = myitem}}">[[myitem]] - [[index]]</button>
73+
<button @click="[[this.ctx = myitem]]">[[myitem]] - [[index]]</button>
7474
</template>
7575
</template>
7676
</node-projects-dce>

src/BaseCustomWebComponent.ts

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -232,37 +232,29 @@ export class BaseCustomWebComponentNoAttachedTemplate extends HTMLElement {
232232
b(true, false);
233233
}
234234
} else if (a.value[0] === '{' && a.value[1] === '{' && a.value[a.value.length - 1] === '}' && a.value[a.value.length - 2] === '}') {
235-
if (a.name[0] === '@') {
236-
const event = a.name.substring(1);
237-
if (node[event] instanceof TypedEvent)
238-
(<TypedEvent<void>>node[event]).on((e) => this._bindingRunEvalInt(a.value.substring(2, a.value.length - 2), repeatBindingItems, <any>e, context));
239-
else
240-
node.addEventListener(event, (e) => this._bindingRunEvalInt(a.value.substring(2, a.value.length - 2), repeatBindingItems, e, context));
241-
} else {
242-
const attributeValues = a.value.substring(2, a.value.length - 2).split('::');
243-
let nm = a.name;
244-
if (nm[0] == '.')
245-
nm = nm.substring(1);
246-
let value = attributeValues[0];
247-
let event = (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) ? 'input' : (node instanceof HTMLSelectElement ? 'change' : nm + '-changed');
248-
if (attributeValues.length > 1 && attributeValues[1])
249-
event = attributeValues[1];
250-
const camelCased = nm.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
251-
let noNull = false;
252-
if (value[0] === '?') {
253-
value = value.substring(1);
254-
noNull = true;
255-
}
256-
const b = (firstRun?: boolean, onlyWhenChanged?: boolean) => this._bindingSetNodeValue(firstRun, node, a, camelCased, value, repeatBindingItems, removeAttributes, host, context, noNull, onlyWhenChanged);
257-
this._bindings.push([b, null]);
258-
b(true, false);
259-
if (event) {
260-
for (let x of event.split(';')) {
261-
if (node[x] instanceof TypedEvent)
262-
(<TypedEvent<void>>node[x]).on((e) => this._bindingsSetValue(host ?? this, value.replaceAll('?', ''), (<HTMLInputElement>node)[camelCased], context, repeatBindingItems));
263-
else
264-
node.addEventListener(x, (e) => this._bindingsSetValue(host ?? this, value.replaceAll('?', ''), (<HTMLInputElement>node)[camelCased], context, repeatBindingItems));
265-
}
235+
const attributeValues = a.value.substring(2, a.value.length - 2).split('::');
236+
let nm = a.name;
237+
if (nm[0] == '.')
238+
nm = nm.substring(1);
239+
let value = attributeValues[0];
240+
let event = (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) ? 'input' : (node instanceof HTMLSelectElement ? 'change' : nm + '-changed');
241+
if (attributeValues.length > 1 && attributeValues[1])
242+
event = attributeValues[1];
243+
const camelCased = nm.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
244+
let noNull = false;
245+
if (value[0] === '?') {
246+
value = value.substring(1);
247+
noNull = true;
248+
}
249+
const b = (firstRun?: boolean, onlyWhenChanged?: boolean) => this._bindingSetNodeValue(firstRun, node, a, camelCased, value, repeatBindingItems, removeAttributes, host, context, noNull, onlyWhenChanged);
250+
this._bindings.push([b, null]);
251+
b(true, false);
252+
if (event) {
253+
for (let x of event.split(';')) {
254+
if (node[x] instanceof TypedEvent)
255+
(<TypedEvent<void>>node[x]).on((e) => this._bindingsSetValue(host ?? this, value.replaceAll('?', ''), (<HTMLInputElement>node)[camelCased], context, repeatBindingItems));
256+
else
257+
node.addEventListener(x, (e) => this._bindingsSetValue(host ?? this, value.replaceAll('?', ''), (<HTMLInputElement>node)[camelCased], context, repeatBindingItems));
266258
}
267259
}
268260
}

src/DeclaritiveBaseCustomWebcomponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ customElements.define("node-projects-dce", DeclaritiveBaseCustomWebcomponent);
161161
<button>[[myitem.toUpperCase()]] - <b>[[myitem.toLowerCase()]]</b> - [[index]]</button>
162162
<ul>
163163
<template repeat:myitem2="[[this.list2]]" repeat-index="inneridx">
164-
<button @click="{{this.ctx = myItem2}}" >[[myitem.toUpperCase()]] - <b>[[myitem2.toLowerCase()]]</b> - [[inneridx * 100]]</button>
164+
<button @click="[[this.ctx = myitem2]]" >[[myitem.toUpperCase()]] - <b>[[myitem2.toLowerCase()]]</b> - [[inneridx * 100]]</button>
165165
</template>
166166
</ul>
167167
</template>

0 commit comments

Comments
 (0)