cellery 1.3.0 → 1.4.1
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/index.d.ts +0 -1
- package/lib/cellery.js +0 -1
- package/lib/cells.js +22 -58
- package/lib/compat.js +18 -0
- package/lib/template.js +14 -4
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/lib/cellery.js
CHANGED
package/lib/cells.js
CHANGED
|
@@ -11,8 +11,10 @@ class Cell {
|
|
|
11
11
|
this.alignment = opts.alignment
|
|
12
12
|
this.decoration = opts.decoration
|
|
13
13
|
this.size = opts.size
|
|
14
|
-
this.
|
|
14
|
+
this.events = opts.events
|
|
15
15
|
this.style = opts.style
|
|
16
|
+
|
|
17
|
+
this._eventsRegistered = false
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
static Styled(styledOpts = {}) {
|
|
@@ -39,14 +41,21 @@ class Cell {
|
|
|
39
41
|
|
|
40
42
|
render(opts = {}) {
|
|
41
43
|
const cell = this._render()
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
|
|
45
|
+
if (!this.cellery) {
|
|
46
|
+
this.cellery = Cell.cellery
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// @todo explore - 'ready' style first time setup?
|
|
50
|
+
if (this.events?.length && this.id && !this._eventsRegistered) {
|
|
51
|
+
this._eventsRegistered = true
|
|
52
|
+
this.cellery.pub({ event: 'register', id: this.id, targets: this.events })
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
this.cellery.pub({
|
|
47
56
|
event: 'render',
|
|
48
57
|
id: cell.id,
|
|
49
|
-
content: this.cellery.adapter
|
|
58
|
+
content: this.cellery.adapter?.render(cell),
|
|
50
59
|
...opts
|
|
51
60
|
})
|
|
52
61
|
}
|
|
@@ -58,13 +67,6 @@ class Cell {
|
|
|
58
67
|
destroy: true
|
|
59
68
|
})
|
|
60
69
|
}
|
|
61
|
-
|
|
62
|
-
register(cellery) {
|
|
63
|
-
this.cellery = cellery
|
|
64
|
-
for (const c of this.children) {
|
|
65
|
-
c.register(cellery)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
class Style {
|
|
@@ -96,48 +98,17 @@ class Style {
|
|
|
96
98
|
return value
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
addScope(
|
|
101
|
+
addScope(parent) {
|
|
100
102
|
walk(this.content, {
|
|
101
103
|
visit: 'Rule',
|
|
102
104
|
enter(rule) {
|
|
103
105
|
rule.prelude.children.forEach((selector) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const items = [...selector.children]
|
|
108
|
-
let inserted = false
|
|
109
|
-
for (let i = 0; i < items.length; i++) {
|
|
110
|
-
const node = items[i]
|
|
111
|
-
if (node.type === 'PseudoClassSelector' || node.type === 'PseudoElementSelector') {
|
|
112
|
-
selector.children.insertData({ type: 'IdSelector', name: parent }, items[i])
|
|
113
|
-
inserted = true
|
|
114
|
-
break
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (!inserted) {
|
|
118
|
-
selector.children.appendData({ type: 'IdSelector', name: parent })
|
|
119
|
-
}
|
|
106
|
+
selector.children.prependData({ type: 'Combinator', name: ' ' })
|
|
107
|
+
selector.children.prependData({ type: 'IdSelector', name: parent })
|
|
120
108
|
})
|
|
121
109
|
}
|
|
122
110
|
})
|
|
123
111
|
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
class StyleHTML extends Style {
|
|
127
|
-
constructor(opts = {}) {
|
|
128
|
-
super(opts)
|
|
129
|
-
|
|
130
|
-
const cellNames = new Set(Object.keys(opts.cells))
|
|
131
|
-
|
|
132
|
-
walk(this.content, {
|
|
133
|
-
visit: 'TypeSelector',
|
|
134
|
-
enter(node) {
|
|
135
|
-
if (cellNames.has(node.name)) {
|
|
136
|
-
node.name = `[data-cellery-cell="${node.name}"]`
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
}
|
|
141
112
|
|
|
142
113
|
toCSS() {
|
|
143
114
|
return generate(this.content)
|
|
@@ -160,9 +131,9 @@ class Container extends Cell {
|
|
|
160
131
|
}
|
|
161
132
|
}
|
|
162
133
|
|
|
163
|
-
class
|
|
134
|
+
class Fragment extends Cell {
|
|
164
135
|
constructor(opts = {}) {
|
|
165
|
-
super({ ...opts
|
|
136
|
+
super({ ...opts })
|
|
166
137
|
}
|
|
167
138
|
}
|
|
168
139
|
|
|
@@ -170,12 +141,8 @@ class Text extends Cell {
|
|
|
170
141
|
constructor(opts = {}) {
|
|
171
142
|
super(opts)
|
|
172
143
|
this.value = opts.value || this.children.filter((c) => typeof c === 'string').join('') || ''
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
class Paragraph extends Cell {
|
|
177
|
-
constructor(opts = {}) {
|
|
178
|
-
super(opts)
|
|
144
|
+
this.paragraph = !!opts.paragraph
|
|
145
|
+
this.heading = opts.heading
|
|
179
146
|
}
|
|
180
147
|
}
|
|
181
148
|
|
|
@@ -191,11 +158,8 @@ class Input extends Cell {
|
|
|
191
158
|
module.exports = {
|
|
192
159
|
Cell,
|
|
193
160
|
Container,
|
|
194
|
-
|
|
161
|
+
Fragment,
|
|
195
162
|
Text,
|
|
196
|
-
Paragraph,
|
|
197
163
|
Input,
|
|
198
|
-
|
|
199
|
-
Style,
|
|
200
|
-
StyleHTML
|
|
164
|
+
Style
|
|
201
165
|
}
|
package/lib/compat.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { Text, Input, Container, Fragment, Style } = require('./cells')
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
'': Fragment,
|
|
5
|
+
h1: Text.Styled({ heading: 1 }),
|
|
6
|
+
h2: Text.Styled({ heading: 2 }),
|
|
7
|
+
h3: Text.Styled({ heading: 3 }),
|
|
8
|
+
h4: Text.Styled({ heading: 4 }),
|
|
9
|
+
h5: Text.Styled({ heading: 5 }),
|
|
10
|
+
h6: Text.Styled({ heading: 6 }),
|
|
11
|
+
div: Container,
|
|
12
|
+
input: Input.Styled({ multiline: false }),
|
|
13
|
+
textbox: Input.Styled({ multiline: true }),
|
|
14
|
+
span: Text,
|
|
15
|
+
button: Container.Styled({ events: ['click'] }),
|
|
16
|
+
p: Text.Styled({ paragraph: true }),
|
|
17
|
+
style: Style
|
|
18
|
+
}
|
package/lib/template.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
const { Cell, Container,
|
|
1
|
+
const { Cell, Container, Fragment, Text, Paragraph, Input, Style } = require('./cells')
|
|
2
|
+
const compat = require('./compat')
|
|
2
3
|
|
|
3
4
|
const SENTINEL = '\x00'
|
|
4
5
|
|
|
5
|
-
const registry = {
|
|
6
|
+
const registry = {
|
|
7
|
+
...compat,
|
|
8
|
+
Cell,
|
|
9
|
+
Container,
|
|
10
|
+
Fragment,
|
|
11
|
+
Text,
|
|
12
|
+
Paragraph,
|
|
13
|
+
Input,
|
|
14
|
+
Style
|
|
15
|
+
}
|
|
6
16
|
|
|
7
17
|
function register(cells) {
|
|
8
18
|
Object.assign(registry, cells)
|
|
@@ -146,7 +156,7 @@ function parse(input, slots) {
|
|
|
146
156
|
while (!eof() && !/[\s>\/]/.test(peek())) val += advance()
|
|
147
157
|
}
|
|
148
158
|
|
|
149
|
-
attrs[name] = resolveValue(val)
|
|
159
|
+
attrs[name] = name === 'events' ? resolveValue(val).split(',') : resolveValue(val)
|
|
150
160
|
} else {
|
|
151
161
|
attrs[name] = true
|
|
152
162
|
}
|
|
@@ -181,7 +191,7 @@ function build(node, slots) {
|
|
|
181
191
|
...node.attrs,
|
|
182
192
|
children,
|
|
183
193
|
style,
|
|
184
|
-
cells: node.tag.
|
|
194
|
+
cells: node.tag.toLowerCase() === 'style' ? registry : undefined
|
|
185
195
|
})
|
|
186
196
|
}
|
|
187
197
|
|