@knowark/componarkjs 1.9.1 → 1.10.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.
|
@@ -18,6 +18,8 @@ export class Component extends globalThis.HTMLElement {
|
|
|
18
18
|
define(tag, element, styles)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
static format = Symbol.for('format')
|
|
22
|
+
|
|
21
23
|
/**
|
|
22
24
|
* @param {object} styleMap
|
|
23
25
|
* @return {string} **/
|
|
@@ -43,7 +45,11 @@ export class Component extends globalThis.HTMLElement {
|
|
|
43
45
|
|
|
44
46
|
/** @param {string} content */
|
|
45
47
|
set content (content) {
|
|
46
|
-
|
|
48
|
+
const format = globalThis[Component.format]
|
|
49
|
+
let template = document.createElement('template')
|
|
50
|
+
template.innerHTML = content
|
|
51
|
+
template = format ? format(template) : template
|
|
52
|
+
this.replaceChildren(template.content)
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
/** @return {string} */
|
|
@@ -34,6 +34,14 @@ class MockComponent extends Component {
|
|
|
34
34
|
}
|
|
35
35
|
Component.define('mock-component', MockComponent)
|
|
36
36
|
|
|
37
|
+
class MockContentComponent extends Component {
|
|
38
|
+
render () {
|
|
39
|
+
this.content = '<p>MOCK_CONTENT</p>'
|
|
40
|
+
return super.render()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
Component.define('mock-content-component', MockContentComponent)
|
|
44
|
+
|
|
37
45
|
describe('Component', () => {
|
|
38
46
|
let container = null
|
|
39
47
|
let component = null
|
|
@@ -488,4 +496,25 @@ describe('Component', () => {
|
|
|
488
496
|
|
|
489
497
|
expect(result).toEqual('background-primary shadow-small')
|
|
490
498
|
})
|
|
499
|
+
|
|
500
|
+
it('allows to use a globally provided template formatter', () => {
|
|
501
|
+
let formattedCalled = false
|
|
502
|
+
globalThis[Component.format] = (template) => {
|
|
503
|
+
formattedCalled = true
|
|
504
|
+
const paragraph = document.createElement('p')
|
|
505
|
+
paragraph.textContent = 'FORMATTED_CONTENT'
|
|
506
|
+
template.content.replaceChildren(paragraph)
|
|
507
|
+
return template
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
container.innerHTML = `
|
|
511
|
+
<mock-content-component class></mock-content-component>
|
|
512
|
+
`
|
|
513
|
+
|
|
514
|
+
const element = container.querySelector('mock-content-component p')
|
|
515
|
+
|
|
516
|
+
expect(formattedCalled).toBe(true)
|
|
517
|
+
expect(element.textContent).toEqual('FORMATTED_CONTENT')
|
|
518
|
+
delete globalThis[Component.format]
|
|
519
|
+
})
|
|
491
520
|
})
|
|
@@ -7,7 +7,7 @@ export class List extends Component {
|
|
|
7
7
|
constructor () {
|
|
8
8
|
super()
|
|
9
9
|
this.addEventListener('click', this._onSelected.bind(this))
|
|
10
|
-
this.addEventListener('delete', this.
|
|
10
|
+
this.addEventListener('delete', this._onDeleted.bind(this))
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/** @param {Object} context */
|
|
@@ -84,7 +84,7 @@ export class List extends Component {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/** @param {MouseEvent} event */
|
|
87
|
-
|
|
87
|
+
_onDeleted (event) {
|
|
88
88
|
event.stopImmediatePropagation()
|
|
89
89
|
|
|
90
90
|
const target = /** @type {HTMLElement} */ (event.target)
|
|
@@ -241,8 +241,7 @@ describe('List', () => {
|
|
|
241
241
|
<template>
|
|
242
242
|
<span>
|
|
243
243
|
<strong>\${this}</strong></span>
|
|
244
|
-
<button data-\${this}
|
|
245
|
-
new CustomEvent('delete', { bubbles: true }))">
|
|
244
|
+
<button data-\${this}>
|
|
246
245
|
DELETE
|
|
247
246
|
</button>
|
|
248
247
|
</template>
|
|
@@ -254,7 +253,7 @@ describe('List', () => {
|
|
|
254
253
|
let items = list.selectAll('ark-list-item')
|
|
255
254
|
expect(items.length).toEqual(4)
|
|
256
255
|
|
|
257
|
-
button.
|
|
256
|
+
button.dispatchEvent(new CustomEvent('delete', { bubbles: true }))
|
|
258
257
|
|
|
259
258
|
button = list.querySelector('[data-colombia]')
|
|
260
259
|
items = list.selectAll('ark-list-item')
|