@inglorious/web 4.0.6 → 4.0.7

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/README.md CHANGED
@@ -261,7 +261,6 @@ import { createStore, html } from "@inglorious/web"
261
261
  const types = {
262
262
  counter: {
263
263
  increment(entity, id) {
264
- if (entity.id !== id) return
265
264
  entity.value++
266
265
  },
267
266
 
@@ -270,7 +269,9 @@ const types = {
270
269
  return html`
271
270
  <div>
272
271
  <span>Count: ${entity.value}</span>
273
- <button @click=${() => api.notify("increment", entity.id)}>+1</button>
272
+ <button @click=${() => api.notify(`#${entity.id}:increment`)}>
273
+ +1
274
+ </button>
274
275
  </div>
275
276
  `
276
277
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/web",
3
- "version": "4.0.6",
3
+ "version": "4.0.7",
4
4
  "description": "A new web framework that leverages the power of the Inglorious Store combined with the performance and simplicity of lit-html.",
5
5
  "author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
package/src/list/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { html } from "lit-html"
2
2
  import { ref } from "lit-html/directives/ref.js"
3
+ import { repeat } from "lit-html/directives/repeat.js"
3
4
  import { styleMap } from "lit-html/directives/style-map.js"
4
5
 
5
6
  const LIST_START = 0
@@ -108,23 +109,31 @@ export const list = {
108
109
  position: "relative",
109
110
  })}
110
111
  >
111
- ${visibleItems.map((item, idx) => {
112
- const absoluteIndex = visibleRange.start + idx
113
- const top = absoluteIndex * height
114
-
115
- return html`
116
- <div
117
- style=${styleMap({
118
- position: "absolute",
119
- top: `${top}px`,
120
- width: "100%",
121
- })}
122
- data-index=${absoluteIndex}
123
- >
124
- ${type.renderItem(item, absoluteIndex, api)}
125
- </div>
126
- `
127
- })}
112
+ ${repeat(
113
+ visibleItems,
114
+ (item) => item.id,
115
+ (item, index) => {
116
+ const absoluteIndex = visibleRange.start + index
117
+ const top = absoluteIndex * height
118
+
119
+ return html`
120
+ <div
121
+ style=${styleMap({
122
+ position: "absolute",
123
+ top: `${top}px`,
124
+ width: "100%",
125
+ })}
126
+ data-index=${absoluteIndex}
127
+ >
128
+ ${type.renderItem(
129
+ entity,
130
+ { item, index: absoluteIndex },
131
+ api,
132
+ )}
133
+ </div>
134
+ `
135
+ },
136
+ )}
128
137
  </div>
129
138
  </div>
130
139
  `
@@ -138,8 +147,10 @@ export const list = {
138
147
  * @returns {TemplateResult}
139
148
  */
140
149
  // eslint-disable-next-line no-unused-vars
141
- renderItem(item, index, api) {
142
- return html`<div>${index + PRETTY_INDEX}. ${JSON.stringify(item)}</div>`
150
+ renderItem(entity, { item, index }, api) {
151
+ return html`<div class="iw-list-item">
152
+ ${index + PRETTY_INDEX}. ${JSON.stringify(item)}
153
+ </div>`
143
154
  },
144
155
  }
145
156
 
@@ -226,7 +226,7 @@ export const rendering = {
226
226
  ${repeat(
227
227
  filteredOptions,
228
228
  (option) => getOptionValue(option),
229
- (option, index) => type.renderOption(entity, option, index, api),
229
+ (option, index) => type.renderOption(entity, { option, index }, api),
230
230
  )}
231
231
  </div>`
232
232
  },
@@ -239,7 +239,7 @@ export const rendering = {
239
239
  * @param {Api} api
240
240
  * @returns {TemplateResult}
241
241
  */
242
- renderOption(entity, option, index, api) {
242
+ renderOption(entity, { option, index }, api) {
243
243
  const optionLabel = getOptionLabel(option)
244
244
  const isSelected = isOptionSelected(
245
245
  option,
@@ -1,6 +1,7 @@
1
1
  import { html } from "lit-html"
2
2
  import { classMap } from "lit-html/directives/class-map.js"
3
3
  import { ref } from "lit-html/directives/ref.js"
4
+ import { repeat } from "lit-html/directives/repeat.js"
4
5
 
5
6
  import { filters } from "./filters.js"
6
7
  import { getPaginationInfo, getRows, getSortDirection } from "./logic.js"
@@ -45,8 +46,11 @@ export const rendering = {
45
46
  }
46
47
  })}
47
48
  >
48
- ${entity.columns.map((column) =>
49
- type.renderHeaderColumn(entity, column, api),
49
+ ${repeat(
50
+ entity.columns,
51
+ (column) => column.id,
52
+ (column, index) =>
53
+ type.renderHeaderColumn(entity, { column, index }, api),
50
54
  )}
51
55
  </div>
52
56
 
@@ -54,7 +58,7 @@ export const rendering = {
54
58
  </div>`
55
59
  },
56
60
 
57
- renderHeaderColumn(entity, column, api) {
61
+ renderHeaderColumn(entity, { column }, api) {
58
62
  return html`<div
59
63
  class="iw-table-header-column"
60
64
  style=${getColumnStyle(column)}
@@ -88,13 +92,15 @@ export const rendering = {
88
92
  const type = api.getType(entity.type)
89
93
 
90
94
  return html`<div class="iw-table-body">
91
- ${getRows(entity).map((row, index) =>
92
- type.renderRow(entity, row, index, api),
95
+ ${repeat(
96
+ getRows(entity),
97
+ (row) => row.id,
98
+ (row, index) => type.renderRow(entity, { row, index }, api),
93
99
  )}
94
100
  </div>`
95
101
  },
96
102
 
97
- renderRow(entity, row, index, api) {
103
+ renderRow(entity, { row, index }, api) {
98
104
  const type = api.getType(entity.type)
99
105
  const rowId = row[entity.rowId ?? "id"]
100
106
 
@@ -105,13 +111,16 @@ export const rendering = {
105
111
  "iw-table-row-selected": entity.selection?.includes(rowId),
106
112
  })}"
107
113
  >
108
- ${entity.columns.map((column, index) =>
109
- type.renderCell(entity, row[column.id], index, api),
114
+ ${repeat(
115
+ entity.columns,
116
+ (column) => column.id,
117
+ (column, index) =>
118
+ type.renderCell(entity, { cell: row[column.id], index }, api),
110
119
  )}
111
120
  </div>`
112
121
  },
113
122
 
114
- renderCell(entity, cell, index, api) {
123
+ renderCell(entity, { cell, index }, api) {
115
124
  const type = api.getType(entity.type)
116
125
  const column = entity.columns[index]
117
126
 
@@ -123,11 +132,11 @@ export const rendering = {
123
132
  })}"
124
133
  style=${getColumnStyle(column)}
125
134
  >
126
- ${type.renderValue(cell, column, api)}
135
+ ${type.renderValue(entity, { value: cell, column, index }, api)}
127
136
  </div>`
128
137
  },
129
138
 
130
- renderValue(value) {
139
+ renderValue(_, { value }) {
131
140
  return value
132
141
  },
133
142