@inglorious/web 4.0.5 → 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/LICENSE +9 -9
- package/README.md +88 -2
- package/package.json +1 -1
- package/src/list/index.js +30 -19
- package/src/select/rendering.js +2 -2
- package/src/table/rendering.js +20 -11
package/LICENSE
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright © 2025 Inglorious Coderz Srl.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2025 Inglorious Coderz Srl.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
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(
|
|
272
|
+
<button @click=${() => api.notify(`#${entity.id}:increment`)}>
|
|
273
|
+
+1
|
|
274
|
+
</button>
|
|
274
275
|
</div>
|
|
275
276
|
`
|
|
276
277
|
},
|
|
@@ -940,6 +941,91 @@ See `src/list.js` in the package for the implementation details and the `example
|
|
|
940
941
|
|
|
941
942
|
---
|
|
942
943
|
|
|
944
|
+
## Using Third-Party Web Components
|
|
945
|
+
|
|
946
|
+
Inglorious Web works seamlessly with any Web Component library, such as Shoelace, Material Web Components, or Lion. Thanks to lit-html's efficient diffing algorithm, Web Components maintain their internal state even when the full tree re-renders - the component only updates when its properties change.
|
|
947
|
+
|
|
948
|
+
### ⚠️ SSG/SSR Considerations
|
|
949
|
+
|
|
950
|
+
**Inglorious Web's built-in components** (`table`, `list`, `select`, `form`) are fully compatible with [@inglorious/ssx](https://npmjs.com/package/@inglorious/ssx) for static site generation. They render to complete HTML at build time and hydrate seamlessly on the client.
|
|
951
|
+
|
|
952
|
+
**Third-party Web Components** currently have limited SSR/SSG support. Most Web Component libraries (including Shoelace and Material Web Components) require client-side JavaScript to initialize and render, which means:
|
|
953
|
+
|
|
954
|
+
- They won't appear in the pre-rendered HTML
|
|
955
|
+
- They're not SEO-friendly in their initial state
|
|
956
|
+
- They may cause FOUC (Flash of Unstyled Content)
|
|
957
|
+
- They should be treated as client-only enhancements
|
|
958
|
+
|
|
959
|
+
**Recommendation for SSX projects:**
|
|
960
|
+
|
|
961
|
+
- Use Inglorious Web components for content that needs to be pre-rendered (product listings, blog posts, documentation)
|
|
962
|
+
- Use Web Components for interactive, client-only features (color pickers, rich text editors, admin tools)
|
|
963
|
+
|
|
964
|
+
**Use Inglorious Web's built-in components when:**
|
|
965
|
+
|
|
966
|
+
✅ You want full architectural consistency
|
|
967
|
+
✅ You need fine-grained control over behavior
|
|
968
|
+
✅ You want to compose behaviors via type composition
|
|
969
|
+
✅ You need time-travel debugging of component state
|
|
970
|
+
✅ You want minimal bundle size
|
|
971
|
+
✅ You're building a core pattern used throughout your app
|
|
972
|
+
✅ You want the simplest possible tests
|
|
973
|
+
✅ You need custom behavior that third-party components don't provide
|
|
974
|
+
✅ You're using SSX for static site generation
|
|
975
|
+
|
|
976
|
+
**Use Web Components (like Shoelace) when:**
|
|
977
|
+
|
|
978
|
+
✅ You need complex, battle-tested UI (date pickers, rich text editors)
|
|
979
|
+
✅ You want a comprehensive design system out of the box
|
|
980
|
+
✅ Speed of development matters more than architectural purity
|
|
981
|
+
✅ You need features you don't want to build yourself (color pickers, tree views)
|
|
982
|
+
✅ The component is isolated or used infrequently
|
|
983
|
+
✅ You're okay with some state living outside the store
|
|
984
|
+
✅ You're building a client-only application (not using SSX)
|
|
985
|
+
|
|
986
|
+
### Example: Hybrid Approach
|
|
987
|
+
|
|
988
|
+
```javascript
|
|
989
|
+
import { table } from "@inglorious/web/table"
|
|
990
|
+
import "@shoelace-style/shoelace/dist/components/color-picker/color-picker.js"
|
|
991
|
+
|
|
992
|
+
const types = {
|
|
993
|
+
// Inglorious Web component - full store integration
|
|
994
|
+
productTable: {
|
|
995
|
+
...table,
|
|
996
|
+
data: products,
|
|
997
|
+
columns: [
|
|
998
|
+
{ id: "name", label: "Product Name" },
|
|
999
|
+
{ id: "price", label: "Price" },
|
|
1000
|
+
],
|
|
1001
|
+
},
|
|
1002
|
+
|
|
1003
|
+
// Web Component - for specialized UI
|
|
1004
|
+
themeEditor: {
|
|
1005
|
+
colorChange(entity, color) {
|
|
1006
|
+
entity.primaryColor = color
|
|
1007
|
+
},
|
|
1008
|
+
|
|
1009
|
+
render(entity, api) {
|
|
1010
|
+
return html`
|
|
1011
|
+
<div>
|
|
1012
|
+
<label>Primary Color</label>
|
|
1013
|
+
<sl-color-picker
|
|
1014
|
+
value=${entity.primaryColor}
|
|
1015
|
+
@sl-change=${(e) =>
|
|
1016
|
+
api.notify("#themeEditor:colorChange", e.target.value)}
|
|
1017
|
+
></sl-color-picker>
|
|
1018
|
+
</div>
|
|
1019
|
+
`
|
|
1020
|
+
},
|
|
1021
|
+
},
|
|
1022
|
+
}
|
|
1023
|
+
```
|
|
1024
|
+
|
|
1025
|
+
This hybrid approach gives you the best of both worlds: architectural consistency for core patterns, and battle-tested components for complex UI.
|
|
1026
|
+
|
|
1027
|
+
---
|
|
1028
|
+
|
|
943
1029
|
## API Reference
|
|
944
1030
|
|
|
945
1031
|
**`mount(store, renderFn, element)`**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/web",
|
|
3
|
-
"version": "4.0.
|
|
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
|
-
${
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
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
|
|
package/src/select/rendering.js
CHANGED
|
@@ -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,
|
package/src/table/rendering.js
CHANGED
|
@@ -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
|
-
${
|
|
49
|
-
|
|
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
|
-
${
|
|
92
|
-
|
|
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
|
-
${
|
|
109
|
-
|
|
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
|
|