als-layout 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/0-change-log.md +8 -1
- package/docs/4-render.md +2 -2
- package/lib/layout.js +8 -6
- package/lib/render/component-hierarchy.js +7 -7
- package/package.json +1 -1
- package/readme.md +11 -3
- package/tests/build-app.test.js +2 -2
- package/tests/component-hierarchy.test.js +1 -1
- package/tests/layout.test.js +5 -5
package/docs/0-change-log.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
## Change Log
|
|
2
|
+
* V2.3.0
|
|
3
|
+
* Default, component will not be included in $App, if not [publish] attribute
|
|
4
|
+
* When cloning, components and other staff cloned too
|
|
5
|
+
* Reference does not change
|
|
6
|
+
|
|
2
7
|
* V2.2.0
|
|
3
8
|
* fixed empty update function if no components for $App
|
|
4
9
|
* if component function return string, it will element.innerHTML = string
|
|
@@ -9,8 +14,10 @@
|
|
|
9
14
|
* lang method instead
|
|
10
15
|
* no layout.cached
|
|
11
16
|
* charset meta tag allready exists by default
|
|
17
|
+
|
|
12
18
|
* V2.1.0
|
|
13
19
|
* updated als-document version
|
|
14
20
|
* [part] attribute for static components
|
|
15
21
|
* onload() method
|
|
16
|
-
* bugs fixed
|
|
22
|
+
* bugs fixed
|
|
23
|
+
|
package/docs/4-render.md
CHANGED
|
@@ -52,7 +52,7 @@ layout.actions = {
|
|
|
52
52
|
// Add buttons and the counter display to the body
|
|
53
53
|
layout.body.innerHTML = /*html*/`
|
|
54
54
|
<button onclick="$App.actions.increase()">Increase</button>
|
|
55
|
-
<span component="counter"></span>
|
|
55
|
+
<span component="counter" publish></span>
|
|
56
56
|
<button onclick="$App.actions.decrease()">Decrease</button>
|
|
57
57
|
`
|
|
58
58
|
|
|
@@ -68,4 +68,4 @@ fs.writeFileSync('counter.html', rawHtml, 'utf-8')
|
|
|
68
68
|
|
|
69
69
|
### Advanced Rendering Details
|
|
70
70
|
- **Component Indexing:** Each component is assigned a `componentIndex` during rendering, providing a unique index within its parent component.
|
|
71
|
-
- **
|
|
71
|
+
- **Publish Attribute:** Using the `publish` attribute in a component make it being added to `$App.components`, unless it is nested within another component.
|
package/lib/layout.js
CHANGED
|
@@ -8,15 +8,17 @@ const {
|
|
|
8
8
|
} = require('./elements/index')
|
|
9
9
|
|
|
10
10
|
class Layout extends Document {
|
|
11
|
-
constructor(html,url) {
|
|
11
|
+
constructor(html,url,doc = {}) {
|
|
12
12
|
super(html,url)
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
13
|
+
const {components = {},data = {},actions = {},utils = {}} = doc
|
|
14
|
+
this.components = components
|
|
15
|
+
this.data = data
|
|
16
|
+
this.actions = actions
|
|
17
|
+
this.utils = utils
|
|
17
18
|
this.root = this.html
|
|
18
19
|
this.update = update
|
|
19
20
|
}
|
|
21
|
+
|
|
20
22
|
onload() {this.script({},onload); return this}
|
|
21
23
|
lang(lang) {this.html.setAttribute('lang',lang); return this}
|
|
22
24
|
version(v) { this.v = v; return this; }
|
|
@@ -32,7 +34,7 @@ class Layout extends Document {
|
|
|
32
34
|
link(href, v = this.v) { return addLink(href, v, this) }
|
|
33
35
|
viewport(newViewport = 'width=device-width, initial-scale=1.0') { return viewport(newViewport, this) }
|
|
34
36
|
get rawHtml() {return this.innerHTML}
|
|
35
|
-
get clone() {return new Layout(new Document(this),this.URL)}
|
|
37
|
+
get clone() {return new Layout(new Document(this),this.URL,this)}
|
|
36
38
|
render() {
|
|
37
39
|
const done = []
|
|
38
40
|
this.update(this.root, done)
|
|
@@ -7,19 +7,19 @@ function componentHierarchy(elements) {
|
|
|
7
7
|
const result = []
|
|
8
8
|
while(entries.length > 0) {
|
|
9
9
|
const [element, componentName, ancestors] = entries.shift()
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
element.removeAttribute('part')
|
|
13
|
-
continue
|
|
14
|
-
}
|
|
15
|
-
const partsInside = element.$$('[component][part]')
|
|
16
|
-
partsInside.forEach(element => { element.removeAttribute('part') });
|
|
10
|
+
const partsInside = element.$$('[component]')
|
|
11
|
+
partsInside.forEach(element => { element.setAttribute('publish','') });
|
|
17
12
|
entries.forEach(entry => {
|
|
18
13
|
if(entry[1] !== componentName) return
|
|
19
14
|
if(entry[2].includes(element)) {
|
|
20
15
|
throw new Error(`The component '${componentName}' acts as both a parent and a child, which may complicate rendering.`);
|
|
21
16
|
}
|
|
22
17
|
});
|
|
18
|
+
if(element.getAttribute('publish') === null) {
|
|
19
|
+
element.removeAttribute('component')
|
|
20
|
+
element.removeAttribute('publish')
|
|
21
|
+
continue
|
|
22
|
+
}
|
|
23
23
|
if(!result.includes(componentName)) result.push(componentName)
|
|
24
24
|
}
|
|
25
25
|
return result
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -27,6 +27,11 @@ const Layout = require('als-layout')
|
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
## Change Log
|
|
30
|
+
* V2.3.0
|
|
31
|
+
* Default, component will not be included in $App, if not [publish] attribute
|
|
32
|
+
* When cloning, components and other staff cloned too
|
|
33
|
+
* Reference does not change
|
|
34
|
+
|
|
30
35
|
* V2.2.0
|
|
31
36
|
* fixed empty update function if no components for $App
|
|
32
37
|
* if component function return string, it will element.innerHTML = string
|
|
@@ -37,11 +42,14 @@ const Layout = require('als-layout')
|
|
|
37
42
|
* lang method instead
|
|
38
43
|
* no layout.cached
|
|
39
44
|
* charset meta tag allready exists by default
|
|
45
|
+
|
|
40
46
|
* V2.1.0
|
|
41
47
|
* updated als-document version
|
|
42
48
|
* [part] attribute for static components
|
|
43
49
|
* onload() method
|
|
44
|
-
* bugs fixed
|
|
50
|
+
* bugs fixed
|
|
51
|
+
|
|
52
|
+
|
|
45
53
|
## Basic Usage
|
|
46
54
|
|
|
47
55
|
### Initialization
|
|
@@ -209,7 +217,7 @@ layout.actions = {
|
|
|
209
217
|
// Add buttons and the counter display to the body
|
|
210
218
|
layout.body.innerHTML = /*html*/`
|
|
211
219
|
<button onclick="$App.actions.increase()">Increase</button>
|
|
212
|
-
<span component="counter"></span>
|
|
220
|
+
<span component="counter" publish></span>
|
|
213
221
|
<button onclick="$App.actions.decrease()">Decrease</button>
|
|
214
222
|
`
|
|
215
223
|
|
|
@@ -225,4 +233,4 @@ fs.writeFileSync('counter.html', rawHtml, 'utf-8')
|
|
|
225
233
|
|
|
226
234
|
### Advanced Rendering Details
|
|
227
235
|
- **Component Indexing:** Each component is assigned a `componentIndex` during rendering, providing a unique index within its parent component.
|
|
228
|
-
- **
|
|
236
|
+
- **Publish Attribute:** Using the `publish` attribute in a component make it being added to `$App.components`, unless it is nested within another component.
|
package/tests/build-app.test.js
CHANGED
|
@@ -17,13 +17,13 @@ describe('build-$App Functionality', () => {
|
|
|
17
17
|
const called = []
|
|
18
18
|
const done = [
|
|
19
19
|
{
|
|
20
|
-
getAttribute: (attr) => attr === 'component' ? 'comp1' : null,
|
|
20
|
+
getAttribute: (attr) => attr === 'component' ? 'comp1' : attr === 'publish' ? '' : null,
|
|
21
21
|
removeAttribute(att) {called.push(att)},
|
|
22
22
|
$$(){return []},
|
|
23
23
|
ancestors:2
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
|
-
getAttribute: (attr) => attr === 'component' ? 'comp2' : null,
|
|
26
|
+
getAttribute: (attr) => attr === 'component' ? 'comp2' : attr === 'publish' ? '' : null,
|
|
27
27
|
removeAttribute(att) {called.push(att)},
|
|
28
28
|
$$(){return []},
|
|
29
29
|
ancestors:2
|
|
@@ -13,7 +13,7 @@ function shuffleArray(array) {
|
|
|
13
13
|
|
|
14
14
|
describe('Basic tests', () => {
|
|
15
15
|
it('should build correct hierarchy', () => {
|
|
16
|
-
const root = parseHTML(/*html*/`<div component="some">
|
|
16
|
+
const root = parseHTML(/*html*/`<div component="some" publish>
|
|
17
17
|
<div>
|
|
18
18
|
<div component="some1"></div>
|
|
19
19
|
<div>
|
package/tests/layout.test.js
CHANGED
|
@@ -111,7 +111,7 @@ describe('Component Updating', () => {
|
|
|
111
111
|
element.insert(2, 'test1 success')
|
|
112
112
|
}
|
|
113
113
|
layout.data.test = 'hello'
|
|
114
|
-
layout.body.innerHTML = /*html*/`<div component="test1">
|
|
114
|
+
layout.body.innerHTML = /*html*/`<div component="test1" publish>
|
|
115
115
|
<div component="test2">failed</div>
|
|
116
116
|
</div>`
|
|
117
117
|
|
|
@@ -132,8 +132,8 @@ describe('Component Updating', () => {
|
|
|
132
132
|
|
|
133
133
|
it('should add part to $App if it is component`s descendant', () => {
|
|
134
134
|
layout.body.innerHTML = /*html*/`
|
|
135
|
-
<div component="parent">
|
|
136
|
-
<div component="child"
|
|
135
|
+
<div component="parent" publish>
|
|
136
|
+
<div component="child"></div>
|
|
137
137
|
</div>`;
|
|
138
138
|
layout.components.parent = (element, $App) => {};
|
|
139
139
|
layout.components.child = (element, $App) => {};
|
|
@@ -151,8 +151,8 @@ describe('Component Updating', () => {
|
|
|
151
151
|
|
|
152
152
|
it('should not add part to $App if it has no component ancestor', () => {
|
|
153
153
|
layout.body.innerHTML = /*html*/`
|
|
154
|
-
<div component="comp1"></div>
|
|
155
|
-
<div component="comp2"
|
|
154
|
+
<div component="comp1" publish></div>
|
|
155
|
+
<div component="comp2"></div>
|
|
156
156
|
`;
|
|
157
157
|
layout.components.comp1 = (element, $App) => {};
|
|
158
158
|
layout.components.comp2 = (element, $App) => {};
|