@reventlessdev/reventless-ui-slots 3.0.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2018-2026 Martin Lorenz
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # `@reventlessdev/reventless-ui-slots`
2
+
3
+ Types and one runtime helper for writing custom renderers into the regions of
4
+ Reventless AutoUI's standard view modes.
5
+
6
+ **Write your renderers in JavaScript, TypeScript or ReScript — whichever you
7
+ prefer.** All three produce the same module and the shell cannot tell them apart.
8
+ This package declares the one contract twice: `index.d.ts` for JS and TS,
9
+ `ReventlessSlots.resi` for ReScript. A conformance test in the kit checks both
10
+ against the payloads the shell actually builds, so the two declarations cannot
11
+ drift apart behind your back.
12
+
13
+ It publishes public. `@reventlesslab/reventless-ui` publishes restricted, so
14
+ without this package writing *any* custom renderer against these seams would need
15
+ a private token — and "custom rendering is supported" would not be a claim an
16
+ open-source user could act on.
17
+
18
+ ## What a slot is
19
+
20
+ A named region **inside** one of AutoUI's standard view modes. The mode keeps
21
+ everything it owns — paging, the window sentence, the action offers, the drill
22
+ target, the live-update path — and your renderer replaces what is drawn inside
23
+ the region. Every slot is optional and a missing one is not an error: the mode
24
+ draws its own rendering, which is what every deployment already sees.
25
+
26
+ The alternative, before slots, was writing a whole view mode — which meant owning
27
+ all of the above, every bit of which the mode you were happy with already had
28
+ right.
29
+
30
+ ## Writing one
31
+
32
+ A slot module is an ES module with one export. No bundler, no dependency, no
33
+ build step: `h` and the registry arrive as arguments.
34
+
35
+ ```js
36
+ export function register({ h, slots }) {
37
+ slots.row('gallery.tile', ({ row, image, open }) =>
38
+ h('button', { className: 'tile', onClick: open },
39
+ h('img', { src: image?.src, alt: image?.alt ?? '' }),
40
+ h('span', { className: 'tile-name' }, row.name)))
41
+
42
+ slots.view('gallery.empty', () =>
43
+ h('p', { className: 'nothing-yet' }, 'Nothing in this collection yet.'))
44
+ }
45
+ ```
46
+
47
+ Serve that file anywhere the shell's origin policy admits, and point the
48
+ deployment's `config.json` at it:
49
+
50
+ ```json
51
+ { "uiSlotsUrl": "/slots/shop.js" }
52
+ ```
53
+
54
+ The shell fetches it before the first page renders. A 404, a module with no
55
+ `register`, or a `register` that throws is logged once and skipped — a storefront
56
+ that fails to load degrades to the generated console, visibly, not to a white
57
+ page.
58
+
59
+ With this package installed, `defineSlots` type-checks the export without
60
+ changing it:
61
+
62
+ ```js
63
+ import { defineSlots } from '@reventlessdev/reventless-ui-slots'
64
+
65
+ export const register = defineSlots(({ h, slots }) => { /* … */ })
66
+ ```
67
+
68
+ ## In ReScript
69
+
70
+ Add the package to the `dependencies` array in your `rescript.json` — the
71
+ compiler's own dependency list, not the one in `package.json`, though it needs to
72
+ be in both — and write the same module. Compiled with
73
+ `"module": "esmodule"` and an `.mjs` suffix, the output *is* the module the shell
74
+ loads — there is nothing to wrap. Unlike the JS path it needs a bundling step,
75
+ because the compiler emits bare-specifier imports (`@rescript/runtime`, this
76
+ package) that a browser will not resolve from a served file; bundle it with
77
+ esbuild or Vite and serve the one file.
78
+
79
+ ```rescript
80
+ let register = (arg: ReventlessSlots.registerArg) => {
81
+ arg.slots.row(ReventlessSlots.RowSlot.galleryTile, p =>
82
+ ReventlessSlots.h(arg.h, "button", {"className": "tile", "onClick": p.openRow}, [
83
+ ReventlessSlots.h(arg.h, "img", {"src": p.image->Option.mapOr("", i => i.src)}, []),
84
+ ReventlessSlots.h(arg.h, "span", Object.make(), [
85
+ React.string(p.label->Option.getOr("")),
86
+ ]),
87
+ ])
88
+ )
89
+
90
+ arg.slots.view(ReventlessSlots.ViewSlot.galleryEmpty, _ =>
91
+ ReventlessSlots.h(arg.h, "p", Object.make(), [React.string("Nothing here yet.")])
92
+ )
93
+ }
94
+ ```
95
+
96
+ ### Why `h` rather than JSX
97
+
98
+ Because React is the one thing a slot module must **not** bring its own copy of.
99
+
100
+ `h` is the shell's own `React.createElement`, handed to you as an argument, so a
101
+ module built through it never imports `react` at all. Everything else it pulls in
102
+ — `@rescript/runtime`, this package — you can bundle freely: those are ordinary
103
+ code with no shared-instance requirement.
104
+
105
+ JSX is available and nicer to write, but it compiles to `@rescript/react` calls
106
+ that import `react`, which puts you one bundler flag away from shipping a second
107
+ React. Two copies look fine at first — a foreign copy's elements render — right
108
+ up until a renderer calls a hook, where the dispatcher belongs to the other copy
109
+ and it fails with "Invalid hook call". If you want JSX, mark `react` **external**
110
+ and give the page an import map pointing at the shell's copy. `h` simply removes
111
+ the question.
112
+
113
+ ## The slots the shipped surfaces offer
114
+
115
+ | id | arity | drawn in place of |
116
+ | --- | --- | --- |
117
+ | `cards.face` | row | one card's face: the picture, title, badge and summary fields |
118
+ | `cards.empty` | view | the card grid when the view has no rows |
119
+ | `gallery.tile` | row | one tile: the picture, its caption row and the line under it |
120
+ | `gallery.empty` | view | the tile grid when the view has no rows |
121
+ | `board.card` | row | one card on the board: the title and its one meta line |
122
+ | `tracker.steps` | row | one row's whole progress strip: the step circles and their labels |
123
+ | `tracker.summary` | row | the line beside one row's name; its summary fields |
124
+ | `detail.media` | row | the media column of a `detailLayout: "media"` page; the record's picture |
125
+ | `detail.aside` | row | above the field set on a `detailLayout: "media"` page; nothing by default |
126
+
127
+ An id nothing offers is reported to the console at boot — a renderer nothing will
128
+ ever call is a mistake the running app would otherwise never mention.
129
+
130
+ ## What you are handed
131
+
132
+ ```ts
133
+ // row slot
134
+ { row, label?, image?, open?, actions? }
135
+
136
+ // view slot
137
+ { rows, total?, selection?, run? }
138
+ ```
139
+
140
+ `row` is the read model's own JSON. `image` is already resolved for this
141
+ deployment's asset origins. `actions` are already resolved against the
142
+ deployment's declarations, the caller's permissions and the row's lifecycle
143
+ state. `open` drills into the row.
144
+
145
+ `selection` and `run` are declared and filled by nothing yet — cross-row
146
+ selection is its own piece of work. They are in the contract from the start
147
+ because discovering that a region needs a second arity after publishing would be
148
+ a breaking change.
149
+
150
+ ## What a slot may not do
151
+
152
+ **It renders what it was handed and reads nothing else.** No query of its own, no
153
+ hard-coded command name, no route. The moment a renderer issues its own fetch or
154
+ names a command it stops being a rendering of the generated data plane and
155
+ becomes an application sitting in a shell.
156
+
157
+ The payloads are narrow so that this is a mechanism rather than a request. The
158
+ producer is the only party that knows the deployment's declarations, the row's
159
+ true identity and what the caller may do; a renderer that could reach the
160
+ producer's own `source` could re-derive all three and get them wrong.
161
+
162
+ A slot **cannot** add a page, own a route, issue a query or replace a mode. Those
163
+ need compile access to the kit and are not reachable from here.
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@reventlessdev/reventless-ui-slots",
3
+ "version": "3.0.0-alpha.1",
4
+ "description": "Types and one runtime helper for writing custom renderers into the regions of Reventless AutoUI's standard view modes.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "src/index.js",
8
+ "types": "src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.d.ts",
12
+ "default": "./src/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "src/index.js",
17
+ "src/index.d.ts",
18
+ "src/**/*.res",
19
+ "src/**/*.resi",
20
+ "src/**/*.res.mjs",
21
+ "rescript.json",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
25
+ "scripts": {
26
+ "build": "rescript build",
27
+ "start": "rescript build -w",
28
+ "clean": "rescript clean",
29
+ "test": "rescript build"
30
+ },
31
+ "peerDependencies": {
32
+ "react": ">=18",
33
+ "rescript": "^12.3.0"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "react": {
37
+ "optional": true
38
+ },
39
+ "rescript": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "publishConfig": {
44
+ "registry": "https://registry.npmjs.org",
45
+ "access": "public"
46
+ },
47
+ "dependencies": {
48
+ "@rescript/react": "^0.13.1"
49
+ },
50
+ "devDependencies": {
51
+ "react": "^18.3.1",
52
+ "react-dom": "^18.3.1",
53
+ "rescript": "^12.3.0"
54
+ },
55
+ "gitHead": "5877fd93c92d7f3d023e12a9f32e24832b639400"
56
+ }
package/rescript.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@reventlessdev/reventless-ui-slots",
3
+ "jsx": {
4
+ "version": 4
5
+ },
6
+ "sources": [
7
+ {
8
+ "dir": "src",
9
+ "subdirs": true
10
+ },
11
+ {
12
+ "dir": "example",
13
+ "subdirs": true,
14
+ "type": "dev"
15
+ }
16
+ ],
17
+ "package-specs": {
18
+ "module": "esmodule",
19
+ "in-source": true
20
+ },
21
+ "suffix": ".res.mjs",
22
+ "dependencies": [
23
+ "@rescript/react"
24
+ ],
25
+ "ppx-flags": []
26
+ }
@@ -0,0 +1,67 @@
1
+ // See Slots.resi for the contract. This file is the bindings only — there is no
2
+ // registry here and there cannot be one: the registry lives in the shell, and a
3
+ // slot module receives it as an argument. That is what keeps this package
4
+ // publishable in the open while the kit stays restricted.
5
+
6
+ type image = {src: string, alt: string}
7
+
8
+ type action = {label: string, run: unit => unit}
9
+
10
+ type rowPayload = {
11
+ row: JSON.t,
12
+ label?: string,
13
+ image?: image,
14
+ @as("open")
15
+ openRow?: unit => unit,
16
+ actions?: array<action>,
17
+ }
18
+
19
+ type viewPayload = {
20
+ rows: array<JSON.t>,
21
+ total?: int,
22
+ selection?: array<string>,
23
+ run?: string => unit,
24
+ }
25
+
26
+ type hyperscript
27
+
28
+ type slots = {
29
+ row: (string, rowPayload => React.element) => unit,
30
+ view: (string, viewPayload => React.element) => unit,
31
+ }
32
+
33
+ type registerArg = {h: hyperscript, slots: slots}
34
+
35
+ // `React.createElement(tag, props, ...children)` against the function the shell
36
+ // passed in. Written as `%raw` because the callee is a value rather than a
37
+ // module member, which `@variadic` cannot express.
38
+ let h: (hyperscript, 'tag, 'props, array<React.element>) => React.element = %raw(`
39
+ function (h, tag, props, children) {
40
+ return h(tag, props, ...children)
41
+ }
42
+ `)
43
+
44
+ module RowSlot = {
45
+ let cardsFace = "cards.face"
46
+ let galleryTile = "gallery.tile"
47
+ let boardCard = "board.card"
48
+ let trackerSteps = "tracker.steps"
49
+ let trackerSummary = "tracker.summary"
50
+ let detailMedia = "detail.media"
51
+ let detailAside = "detail.aside"
52
+ let all = [
53
+ cardsFace,
54
+ galleryTile,
55
+ boardCard,
56
+ trackerSteps,
57
+ trackerSummary,
58
+ detailMedia,
59
+ detailAside,
60
+ ]
61
+ }
62
+
63
+ module ViewSlot = {
64
+ let cardsEmpty = "cards.empty"
65
+ let galleryEmpty = "gallery.empty"
66
+ let all = [cardsEmpty, galleryEmpty]
67
+ }
@@ -0,0 +1,63 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+
4
+ let h = (function (h, tag, props, children) {
5
+ return h(tag, props, ...children)
6
+ });
7
+
8
+ let cardsFace = "cards.face";
9
+
10
+ let galleryTile = "gallery.tile";
11
+
12
+ let boardCard = "board.card";
13
+
14
+ let trackerSteps = "tracker.steps";
15
+
16
+ let trackerSummary = "tracker.summary";
17
+
18
+ let detailMedia = "detail.media";
19
+
20
+ let detailAside = "detail.aside";
21
+
22
+ let all = [
23
+ cardsFace,
24
+ galleryTile,
25
+ boardCard,
26
+ trackerSteps,
27
+ trackerSummary,
28
+ detailMedia,
29
+ detailAside
30
+ ];
31
+
32
+ let RowSlot = {
33
+ cardsFace: cardsFace,
34
+ galleryTile: galleryTile,
35
+ boardCard: boardCard,
36
+ trackerSteps: trackerSteps,
37
+ trackerSummary: trackerSummary,
38
+ detailMedia: detailMedia,
39
+ detailAside: detailAside,
40
+ all: all
41
+ };
42
+
43
+ let cardsEmpty = "cards.empty";
44
+
45
+ let galleryEmpty = "gallery.empty";
46
+
47
+ let all$1 = [
48
+ cardsEmpty,
49
+ galleryEmpty
50
+ ];
51
+
52
+ let ViewSlot = {
53
+ cardsEmpty: cardsEmpty,
54
+ galleryEmpty: galleryEmpty,
55
+ all: all$1
56
+ };
57
+
58
+ export {
59
+ h,
60
+ RowSlot,
61
+ ViewSlot,
62
+ }
63
+ /* No side effect */
@@ -0,0 +1,129 @@
1
+ /*** The contract a Reventless slot module is written against, for ReScript.
2
+
3
+ The same contract `index.d.ts` describes for JavaScript and TypeScript — same
4
+ payloads, same two registration functions, same module shape. The shell cannot
5
+ tell what compiled a slot module.
6
+
7
+ A slot is a named region *inside* one of AutoUI's standard view modes. The mode
8
+ keeps everything it owns — paging, the window sentence, the action offers, the
9
+ drill target, the live-update path — and your renderer replaces what is drawn
10
+ inside the region. Every slot is optional and a missing one is not an error.
11
+
12
+ ⚠️ A slot renders what it was handed and reads nothing else. No query of its
13
+ own, no hard-coded command name, no route. The payloads are narrow so that this
14
+ is a mechanism rather than a request: the producer is the only party that knows
15
+ the deployment's declarations, the row's true identity and what the caller may
16
+ do, and a renderer that re-derived any of the three would get it wrong. A slot
17
+ cannot add a page, own a route, issue a query or replace a mode. */
18
+
19
+ /** A picture the region draws, already resolved: the reference is rebased for
20
+ this deployment's asset origins, and `alt` is the value's own text where it
21
+ carried one, falling back to the row's label. */
22
+ type image = {src: string, alt: string}
23
+
24
+ /** Something to do with this row that is not "open it" — already resolved
25
+ against the deployment's declarations, the caller's permissions and the row's
26
+ lifecycle state by the time it reaches you. */
27
+ type action = {label: string, run: unit => unit}
28
+
29
+ /** What a per-row region is handed. */
30
+ type rowPayload = {
31
+ /** The row as the producer holds it — the read model's own JSON. */
32
+ row: JSON.t,
33
+ /** What the mode would have titled this row. */
34
+ label?: string,
35
+ /** The row's picture, where the view resolves one and this row has it. */
36
+ image?: image,
37
+ /** Drill into this row. Absent where the producer wired no drill target.
38
+ Serialized as `open`, which is the name the JS and TS contracts use. */
39
+ @as("open")
40
+ openRow?: unit => unit,
41
+ /** Commands this row can start in the state it is in. */
42
+ actions?: array<action>,
43
+ }
44
+
45
+ /** What a per-view region is handed. `selection` and `run` are declared and
46
+ filled by nothing yet — cross-row selection is its own piece of work. They
47
+ are in the contract from the start because discovering that a region needs a
48
+ second arity after publishing would be a breaking change. */
49
+ type viewPayload = {
50
+ /** The rows the mode is currently drawing — its page window, not the table. */
51
+ rows: array<JSON.t>,
52
+ /** How many rows that window holds. */
53
+ total?: int,
54
+ /** Row ids the caller has picked out, where the mode offers picking. */
55
+ selection?: array<string>,
56
+ /** Start the region's one command, by name. */
57
+ run?: string => unit,
58
+ }
59
+
60
+ /** React's `createElement`, as the shell handed it over. */
61
+ type hyperscript
62
+
63
+ /** The two registration functions, one per arity. A slot id is drawn once per
64
+ row or once per view, and which one it is is fixed by the mode offering it. */
65
+ type slots = {
66
+ row: (string, rowPayload => React.element) => unit,
67
+ view: (string, viewPayload => React.element) => unit,
68
+ }
69
+
70
+ /** The one argument `register` receives. */
71
+ type registerArg = {h: hyperscript, slots: slots}
72
+
73
+ /** Build an element with the SHELL's React rather than one of your own.
74
+
75
+ Worth preferring over JSX, because React is the one thing a slot module must
76
+ not bring a second copy of: a foreign copy's elements render fine right up
77
+ until a renderer calls a hook, where the dispatcher belongs to the other copy
78
+ and it fails. Built through `h`, the module never imports `react` at all —
79
+ everything else it pulls in bundles freely.
80
+
81
+ JSX compiles to `@rescript/react` calls that import `react`, so a JSX slot
82
+ module needs `react` marked external plus an import map pointing at the
83
+ shell's copy.
84
+
85
+ ```rescript
86
+ let register = (arg: ReventlessSlots.registerArg) =>
87
+ arg.slots.row("gallery.tile", p =>
88
+ ReventlessSlots.h(arg.h, "button", {"className": "tile"}, [
89
+ ReventlessSlots.h(arg.h, "img", {"src": p.image->Option.mapOr("", i => i.src)}, []),
90
+ ])
91
+ )
92
+ ```
93
+ */
94
+ let h: (hyperscript, 'tag, 'props, array<React.element>) => React.element
95
+
96
+ /** Per-row slots the shipped modes offer. */
97
+ module RowSlot: {
98
+ /** One card's face: the picture, title, badge and summary fields. */
99
+ let cardsFace: string
100
+ /** One tile: the picture, its caption row and the line under it. */
101
+ let galleryTile: string
102
+ /** One card on the board: the title and its one meta line. */
103
+ let boardCard: string
104
+ /** One row's whole progress strip: the step circles and their labels.
105
+
106
+ The strip rather than one step, because a per-node payload would be a third
107
+ arity in a contract that settled on two — and a step slot with no way to
108
+ say WHICH step is not a slot at all. */
109
+ let trackerSteps: string
110
+ /** The line beside one row's name on the tracker; its summary fields. */
111
+ let trackerSummary: string
112
+ /** The media column of a `detailLayout: "media"` page; the record's picture.
113
+
114
+ Offered by the drill detail rather than by a view mode — it is the other
115
+ half of the pair every mode renders under, not a mode itself. */
116
+ let detailMedia: string
117
+ /** Above the field set on a `detailLayout: "media"` page; nothing by default. */
118
+ let detailAside: string
119
+ let all: array<string>
120
+ }
121
+
122
+ /** Per-view slots the shipped modes offer. */
123
+ module ViewSlot: {
124
+ /** The card grid when the view has no rows. */
125
+ let cardsEmpty: string
126
+ /** The tile grid when the view has no rows. */
127
+ let galleryEmpty: string
128
+ let all: array<string>
129
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,146 @@
1
+ /**
2
+ * The contract a Reventless slot module is written against.
3
+ *
4
+ * A slot is a named region *inside* one of AutoUI's standard view modes. The
5
+ * mode keeps everything it owns — paging, the window sentence, the action
6
+ * offers, the drill target, the live-update path — and your renderer replaces
7
+ * what is drawn inside the region. Every slot is optional: register none and the
8
+ * mode draws its own rendering, which is what every deployment already sees.
9
+ *
10
+ * What a slot may NOT do is the whole of its usefulness. **It renders what it
11
+ * was handed and reads nothing else.** No query of its own, no hard-coded
12
+ * command name, no route. The payloads below are narrow on purpose: the producer
13
+ * is the only party that knows the deployment's declarations, the row's true
14
+ * identity and what the caller may do, and a renderer that re-derived any of the
15
+ * three would get it wrong.
16
+ *
17
+ * A slot cannot add a page, own a route, issue a query or replace a mode. Those
18
+ * need compile access to the kit and are not reachable from here.
19
+ */
20
+
21
+ /** A picture the region draws, already resolved: the reference is rebased for
22
+ * this deployment's asset origins, and `alt` is the value's own text where it
23
+ * carried any, falling back to the row's label. */
24
+ export interface SlotImage {
25
+ src: string
26
+ alt: string
27
+ }
28
+
29
+ /** Something to do with this row that is not "open it" — already resolved
30
+ * against the deployment's declarations, the caller's permissions and the row's
31
+ * lifecycle state by the time it reaches you. Call `run` from a click. */
32
+ export interface SlotAction {
33
+ label: string
34
+ run(): void
35
+ }
36
+
37
+ /** What a per-row region is handed. */
38
+ export interface RowPayload<Row = Record<string, unknown>> {
39
+ /** The row as the producer holds it — the read model's own JSON. */
40
+ row: Row
41
+ /** What the mode would have titled this row. */
42
+ label?: string
43
+ /** The row's picture, where the view resolves one and this row has it. */
44
+ image?: SlotImage
45
+ /** Drill into this row. Absent where the producer wired no drill target. */
46
+ open?: () => void
47
+ /** Commands this row can start in the state it is in. */
48
+ actions?: SlotAction[]
49
+ }
50
+
51
+ /** What a per-view region is handed.
52
+ *
53
+ * `selection` and `run` are declared and filled by nothing yet: cross-row
54
+ * selection is its own piece of work. They are here from the start because
55
+ * discovering that a region needs a second arity after the contract is
56
+ * published would be a breaking change. */
57
+ export interface ViewPayload<Row = Record<string, unknown>> {
58
+ /** The rows the mode is currently drawing — its page window, not the table. */
59
+ rows: Row[]
60
+ /** How many rows that window holds. */
61
+ total?: number
62
+ /** Row ids the caller has picked out, where the mode offers picking. */
63
+ selection?: string[]
64
+ /** Start the region's one command, by name. */
65
+ run?: (command: string) => void
66
+ }
67
+
68
+ /** Anything React will render. Deliberately structural — the package declares no
69
+ * dependency on React's types, so a slot module needs no React install. */
70
+ export type SlotNode = unknown
71
+
72
+ export type RowRenderer<Row = Record<string, unknown>> = (payload: RowPayload<Row>) => SlotNode
73
+ export type ViewRenderer<Row = Record<string, unknown>> = (payload: ViewPayload<Row>) => SlotNode
74
+
75
+ /** The registry handed to `register`. Two functions, one per arity; a slot id is
76
+ * drawn once per row or once per view, and which one it is is fixed by the mode
77
+ * that offers it. */
78
+ export interface Slots {
79
+ row(id: RowSlotId | (string & {}), render: RowRenderer): void
80
+ view(id: ViewSlotId | (string & {}), render: ViewRenderer): void
81
+ }
82
+
83
+ /** React's own `createElement`, handed over as-is: `h(tag, props, ...children)`.
84
+ * It arrives as an argument so a slot module needs no bundler, no React import
85
+ * and no version to keep in step with the shell's. */
86
+ export type Hyperscript = (
87
+ type: unknown,
88
+ props?: Record<string, unknown> | null,
89
+ ...children: SlotNode[]
90
+ ) => SlotNode
91
+
92
+ export interface RegisterArg {
93
+ h: Hyperscript
94
+ slots: Slots
95
+ }
96
+
97
+ /** The one export a slot module provides. */
98
+ export type Register = (arg: RegisterArg) => void
99
+
100
+ /**
101
+ * Per-row slots the shipped modes offer.
102
+ *
103
+ * | id | drawn in place of |
104
+ * | --- | --- |
105
+ * | `cards.face` | one card's face: the picture, title, badge and summary fields |
106
+ * | `gallery.tile` | one tile: the picture, its caption row and the line under it |
107
+ * | `board.card` | one card on the board: the title and its one meta line |
108
+ * | `tracker.steps` | one row's whole progress strip: the connected step circles and their labels |
109
+ * | `tracker.summary` | the line beside one row's name; its summary fields |
110
+ * | `detail.media` | the media column of a `detailLayout: "media"` page; the record's picture |
111
+ * | `detail.aside` | above the field set on a `detailLayout: "media"` page; nothing by default |
112
+ */
113
+ export type RowSlotId =
114
+ | 'cards.face'
115
+ | 'gallery.tile'
116
+ | 'board.card'
117
+ | 'tracker.steps'
118
+ | 'tracker.summary'
119
+ | 'detail.media'
120
+ | 'detail.aside'
121
+
122
+ /**
123
+ * Per-view slots the shipped modes offer.
124
+ *
125
+ * | id | drawn in place of |
126
+ * | --- | --- |
127
+ * | `cards.empty` | the card grid when the view has no rows |
128
+ * | `gallery.empty` | the tile grid when the view has no rows |
129
+ */
130
+ export type ViewSlotId = 'cards.empty' | 'gallery.empty'
131
+
132
+ /**
133
+ * Identity helper: type-checks a `register` function without changing it.
134
+ *
135
+ * ```js
136
+ * import { defineSlots } from '@reventlessdev/reventless-ui-slots'
137
+ *
138
+ * export const register = defineSlots(({ h, slots }) => {
139
+ * slots.row('gallery.tile', ({ row, image, open }) =>
140
+ * h('button', { className: 'tile', onClick: open },
141
+ * h('img', { src: image?.src, alt: image?.alt ?? '' }),
142
+ * h('span', null, row.name)))
143
+ * })
144
+ * ```
145
+ */
146
+ export declare function defineSlots(register: Register): Register
package/src/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // The whole runtime of this package. `defineSlots` is the identity function:
2
+ // its only job is to give an editor something to check a `register` export
3
+ // against, which is exactly what a types-and-documentation package is for.
4
+ //
5
+ // A slot module does not need it. `export function register({ h, slots }) {…}`
6
+ // works on its own, because `h` and the registry arrive as arguments and the
7
+ // shell calls the export by name.
8
+ export const defineSlots = register => register