cellery 1.0.1 → 1.1.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/index.d.ts CHANGED
@@ -1 +1,197 @@
1
- declare module 'cellery'
1
+ declare module 'cellery' {
2
+ import Iambus from 'iambus'
3
+
4
+ // --- Decorations ---
5
+
6
+ export class Alignment {
7
+ direction: string
8
+ justify: string
9
+ items: string
10
+
11
+ constructor(direction: string, justify: string, items: string)
12
+
13
+ static Horizontal(opts: { justify?: string; items?: string }): Alignment
14
+ static Vertical(opts: { justify?: string; items?: string }): Alignment
15
+ }
16
+
17
+ export class Spacing {
18
+ left: number
19
+ top: number
20
+ right: number
21
+ bottom: number
22
+
23
+ constructor(left: number, top: number, right: number, bottom: number)
24
+
25
+ static all(value: number): Spacing
26
+ static symmetric(opts: { vertical?: number; horizontal?: number }): Spacing
27
+ static only(opts: { left?: number; right?: number; top?: number; bottom?: number }): Spacing
28
+
29
+ toString(): string
30
+ }
31
+
32
+ export class Color {
33
+ red: number
34
+ green: number
35
+ blue: number
36
+ alpha: number
37
+
38
+ constructor(red?: number, green?: number, blue?: number, alpha?: number)
39
+
40
+ toString(): string
41
+ toRGBA(): string
42
+ toRGB(): string
43
+
44
+ static from(
45
+ value: string | { red?: number; green?: number; blue?: number; alpha?: number },
46
+ alpha?: number
47
+ ): Color | null
48
+ }
49
+
50
+ export interface BorderOptions {
51
+ width?: number
52
+ color?: Color | null
53
+ }
54
+
55
+ export class Border {
56
+ width: number
57
+ color: Color | null
58
+
59
+ constructor(opts?: BorderOptions)
60
+
61
+ static all(opts?: BorderOptions): Border
62
+
63
+ toString(): string
64
+ }
65
+
66
+ export interface BoxDecorationOptions {
67
+ border?: Border | null
68
+ }
69
+
70
+ export class BoxDecoration {
71
+ border: Border | null
72
+
73
+ constructor(opts?: BoxDecorationOptions)
74
+
75
+ toString(): string
76
+ }
77
+
78
+ export const Size: {
79
+ readonly XS: 'xs'
80
+ readonly S: 's'
81
+ readonly M: 'm'
82
+ readonly L: 'l'
83
+ readonly XL: 'xl'
84
+ }
85
+
86
+ export type SizeValue = (typeof Size)[keyof typeof Size]
87
+
88
+ // --- Cells ---
89
+
90
+ export interface CellOptions {
91
+ id?: string
92
+ children?: Cell[] // lunte-disable-line
93
+ cellery?: Cellery // lunte-disable-line
94
+ padding?: Spacing
95
+ margin?: Spacing
96
+ color?: Color
97
+ alignment?: Alignment
98
+ decoration?: BoxDecoration
99
+ size?: SizeValue
100
+ onclick?: (...args: any[]) => void
101
+ }
102
+
103
+ export class Cell {
104
+ id: string | undefined
105
+ children: Cell[]
106
+ cellery: Cellery | undefined // lunte-disable-line
107
+ padding: Spacing | undefined
108
+ margin: Spacing | undefined
109
+ color: Color | undefined
110
+ alignment: Alignment | undefined
111
+ decoration: BoxDecoration | undefined
112
+ size: SizeValue | undefined
113
+ onclick: ((...args: any[]) => void) | undefined
114
+
115
+ constructor(opts?: CellOptions)
116
+
117
+ static Styled<T extends typeof Cell>(this: T, styledOpts?: CellOptions): T
118
+
119
+ sub(pattern: any, cb: (cell: this, data: any) => void): void
120
+
121
+ _render(): this
122
+ render(opts?: Record<string, any>): void
123
+ destroy(): void
124
+ register(cellery: Cellery): void // lunte-disable-line
125
+ }
126
+
127
+ export interface ContainerOptions extends CellOptions {
128
+ scroll?: string
129
+ flex?: string
130
+ }
131
+
132
+ export class Container extends Cell {
133
+ static ScrollAll: 'all'
134
+ static ScrollVertical: 'vertical'
135
+ static ScrollHorizontal: 'horizontal'
136
+ static ScrollNone: 'none'
137
+ static FlexAuto: 'auto'
138
+ static FlexNone: 'none'
139
+
140
+ scroll: string
141
+ flex: string
142
+
143
+ constructor(opts?: ContainerOptions) // lunte-disable-line
144
+ }
145
+
146
+ export class App extends Cell {
147
+ constructor(opts?: Omit<CellOptions, 'id'>) // lunte-disable-line
148
+ }
149
+
150
+ export interface TextOptions extends CellOptions {
151
+ value?: string
152
+ }
153
+
154
+ export class Text extends Cell {
155
+ value: string
156
+
157
+ constructor(opts?: TextOptions) // lunte-disable-line
158
+ }
159
+
160
+ export class Paragraph extends Cell {
161
+ constructor(opts?: CellOptions) // lunte-disable-line
162
+ }
163
+
164
+ export interface InputOptions extends CellOptions {
165
+ multiline?: boolean
166
+ placeholder?: string
167
+ type?: string
168
+ }
169
+
170
+ export class Input extends Cell {
171
+ multiline: boolean
172
+ placeholder: string | undefined
173
+ type: string
174
+
175
+ constructor(opts?: InputOptions) // lunte-disable-line
176
+ }
177
+
178
+ // --- Adapter ---
179
+
180
+ export interface Adapter {
181
+ render(cell: Cell): any
182
+ }
183
+
184
+ // --- Cellery ---
185
+
186
+ export class Cellery extends Iambus {
187
+ app: App
188
+ adapter: Adapter
189
+
190
+ constructor(app: App, adapter: Adapter) // lunte-disable-line
191
+
192
+ write(data: any): void
193
+ on(type: string, cb: (...args: any[]) => void): void
194
+ emit(type: string, stream: any): void
195
+ render(): void
196
+ }
197
+ }
package/lib/cellery.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const Iambus = require('iambus')
2
+ const { Cell } = require('./cells')
2
3
 
3
4
  class Cellery extends Iambus {
4
5
  constructor(app, adapter) {
@@ -6,6 +7,7 @@ class Cellery extends Iambus {
6
7
  this.app = app
7
8
  this.adapter = adapter
8
9
 
10
+ Cell.cellery = this
9
11
  this.app.register(this)
10
12
  }
11
13
 
package/lib/cells.js CHANGED
@@ -2,13 +2,23 @@ class Cell {
2
2
  constructor(opts = {}) {
3
3
  this.id = opts.id
4
4
  this.children = opts.children || []
5
- this.cellery = opts.cellery
5
+ this.cellery = opts.cellery || Cell.cellery
6
6
  this.padding = opts.padding
7
7
  this.margin = opts.margin
8
8
  this.color = opts.color
9
9
  this.alignment = opts.alignment
10
10
  this.decoration = opts.decoration
11
11
  this.size = opts.size
12
+ this.onclick = opts.onclick
13
+ }
14
+
15
+ static Styled(styledOpts = {}) {
16
+ const Parent = this
17
+ return class extends Parent {
18
+ constructor(opts = {}) {
19
+ super({ ...styledOpts, ...opts })
20
+ }
21
+ }
12
22
  }
13
23
 
14
24
  sub(pattern, cb) {
@@ -62,7 +62,7 @@ class Color {
62
62
  }
63
63
 
64
64
  toString() {
65
- return `Color(${Object.entries(this).map(([k, v]) => `${k}: ${v}`)})`
65
+ return `Color(${Object.entries(this).map(([k, v]) => `${k}:${v}`)})`
66
66
  }
67
67
 
68
68
  toRGBA() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cellery",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "cellery",
5
5
  "exports": {
6
6
  "./package": "./package.json",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "scripts": {
26
26
  "format": "prettier . --write",
27
- "test": "prettier . --check && lunte && brittle-bare test/index.js",
27
+ "test": "prettier . --check && lunte && brittle-bare test/all.js",
28
28
  "lint": "lunte"
29
29
  },
30
30
  "repository": {