@yaks/render 0.0.0-stage → 0.2.36
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 +202 -0
- package/README.md +396 -2
- package/_dist/archetype.d.ts +3 -0
- package/_dist/archetype.d.ts.map +1 -0
- package/_dist/component.d.ts +15 -0
- package/_dist/component.d.ts.map +1 -0
- package/_dist/edit.d.ts +17 -0
- package/_dist/edit.d.ts.map +1 -0
- package/_dist/host.d.ts +59 -0
- package/_dist/host.d.ts.map +1 -0
- package/_dist/mod.d.ts +72 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/namespace.d.ts +12 -0
- package/_dist/namespace.d.ts.map +1 -0
- package/_dist/prepare.d.ts +11 -0
- package/_dist/prepare.d.ts.map +1 -0
- package/_dist/types.d.ts +66 -0
- package/_dist/types.d.ts.map +1 -0
- package/_dist/views.d.ts +88 -0
- package/_dist/views.d.ts.map +1 -0
- package/archetype.js +56 -0
- package/archetype.js.map +1 -0
- package/archetype.ts +76 -0
- package/component.js +39 -0
- package/component.js.map +1 -0
- package/component.ts +84 -0
- package/deno.json +1 -0
- package/edit.js +88 -0
- package/edit.js.map +1 -0
- package/edit.ts +113 -0
- package/host.js +191 -0
- package/host.js.map +1 -0
- package/host.ts +277 -0
- package/mod.js +158 -0
- package/mod.js.map +1 -0
- package/mod.ts +328 -0
- package/namespace.js +90 -0
- package/namespace.js.map +1 -0
- package/namespace.ts +121 -0
- package/package.json +31 -4
- package/prepare.js +32 -0
- package/prepare.js.map +1 -0
- package/prepare.ts +55 -0
- package/prop.js +37 -0
- package/prop.js.map +1 -0
- package/prop.ts +46 -0
- package/types.js +7 -0
- package/types.js.map +1 -0
- package/types.ts +116 -0
- package/views.js +333 -0
- package/views.js.map +1 -0
- package/views.ts +389 -0
- package/vocab.json +29 -0
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 2026 Jeff Peterson
|
|
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
CHANGED
|
@@ -1,3 +1,397 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/render
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Selects views, editors, and actions for [bundles](../graph/README.md#data-model)
|
|
4
|
+
through a query-matched registry independent of the rendering host.
|
|
5
|
+
|
|
6
|
+
A **view** is a name requested by a caller, such as `Tile` or `Board.List.Tile`.
|
|
7
|
+
A **registration** associates a view with a
|
|
8
|
+
[query](../query/README.md#query-model) or `true`:
|
|
9
|
+
`{ view: 'Tile', match: parse('.doc') }` (`Registration`). A **renderer** is a
|
|
10
|
+
registration with a `render(bundle, h, ctx)` function, or a `load()` function
|
|
11
|
+
that prepares it (`Renderer`). A **registry** holds ordered registrations and
|
|
12
|
+
the options used for selection and actions (`Registry`).
|
|
13
|
+
|
|
14
|
+
A **context** holds extra values supplied by the caller (`Context`). A rendering
|
|
15
|
+
host supplies `h(tag, props, ...children)` (`H`), which builds its output nodes.
|
|
16
|
+
It may also supply `ctx.render(view, context?)` for nested views and `ctx.vocab`
|
|
17
|
+
for the [vocabulary](../vocab/README.md#vocabulary) (`RenderContext`).
|
|
18
|
+
[@yaks/preact](../preact/README.md) supplies Preact rendering;
|
|
19
|
+
[@yaks/text](../text/README.md) supplies Markdown and plain text rendering.
|
|
20
|
+
|
|
21
|
+
## Preparation
|
|
22
|
+
|
|
23
|
+
A deferred renderer keeps its selection metadata available while its `load()`
|
|
24
|
+
function imports or prepares the rendering implementation. Selection never calls
|
|
25
|
+
`load`. A host calls `prepared(registry)` before drawing, or supplies the
|
|
26
|
+
selected registrations as its second argument. The returned registry preserves
|
|
27
|
+
all entries, options, and their order; the input registry remains unchanged.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { define, prepared } from '@yaks/render'
|
|
31
|
+
import { equal } from '@yaks/testing'
|
|
32
|
+
import { loadVocab } from '@yaks/vocab'
|
|
33
|
+
import { render } from '@yaks/text'
|
|
34
|
+
|
|
35
|
+
const views = define([{
|
|
36
|
+
view: 'Tile',
|
|
37
|
+
match: true,
|
|
38
|
+
load: async () => (_bundle, h) => h('span', null, 'Ready'),
|
|
39
|
+
}])
|
|
40
|
+
const ready = await prepared(views)
|
|
41
|
+
equal(render(ready, { entity: { eid: 'one' } }, 'Tile', loadVocab([])), 'Ready')
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Browser and terminal hosts prepare the full registry before painting. A portable
|
|
45
|
+
host may supply `ctx.deferred(renderer)` to collect selected and nested deferred
|
|
46
|
+
renderers, prepare those registrations, and draw again. A selected unprepared
|
|
47
|
+
renderer without this boundary throws; it does not silently draw empty content.
|
|
48
|
+
Preparation failures propagate when the host prepares the required renderer.
|
|
49
|
+
|
|
50
|
+
## Use
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { define } from '@yaks/render'
|
|
54
|
+
import { parse } from '@yaks/query'
|
|
55
|
+
import { loadVocab } from '@yaks/vocab'
|
|
56
|
+
import { render } from '@yaks/text'
|
|
57
|
+
import { equal } from '@yaks/testing'
|
|
58
|
+
|
|
59
|
+
let vocab = loadVocab({
|
|
60
|
+
$defs: {
|
|
61
|
+
doc: {
|
|
62
|
+
component: true,
|
|
63
|
+
properties: { title: { type: 'string' } },
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
let bundle = { entity: { eid: 'example' }, doc: { title: 'A document' } }
|
|
68
|
+
let registry = define([{
|
|
69
|
+
view: 'Tile',
|
|
70
|
+
match: parse('.doc'),
|
|
71
|
+
render: (b, h) => h('h2', null, (b.doc as { title: string }).title),
|
|
72
|
+
}])
|
|
73
|
+
equal(render(registry, bundle, 'Board.List.Tile', vocab), '## A document')
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Exports
|
|
77
|
+
|
|
78
|
+
| Module | Exports |
|
|
79
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
80
|
+
| `@yaks/render` | `define`, `extend`, `resolve`, `applicable`, `actions`, `edit`; types `Registration`, `Renderer`, `Registry`, `Selection`, `Options`, `H`, `Child`, `Context`, `RenderContext`, `Action`, `Contributor`, `Patch`, `EditOptions`, `ArchetypeLookup`; re-exported `Bundle` and `Query` |
|
|
81
|
+
| `@yaks/render/views` | `views`, `sheet`, `passage`; types `Shown`, `Related`, `Said` |
|
|
82
|
+
|
|
83
|
+
## Selection
|
|
84
|
+
|
|
85
|
+
`resolve(registry, bundle, view, vocab, ctx?)` returns a registration without
|
|
86
|
+
invoking its renderer. For `Board.List.Tile`, it tries `Board.List.Tile`,
|
|
87
|
+
`List.Tile`, then `Tile`. At the first view with a match, the query with the
|
|
88
|
+
most top-level [clauses](../query/README.md#query-model) wins; registration
|
|
89
|
+
order breaks ties. A `match: true` registration scores 0.5, below every matching
|
|
90
|
+
query, including an empty query. If nothing matches, it tries a matching `JSON`
|
|
91
|
+
registration, then returns `undefined`.
|
|
92
|
+
|
|
93
|
+
An unnamed request considers `options.views`, or all registered views when that
|
|
94
|
+
option is omitted. `applicable` lists matching exact view names in that order,
|
|
95
|
+
or registration order when `views` is omitted; it does not try shorter names or
|
|
96
|
+
use the `JSON` fallback. Registrations using unknown vocabulary names are
|
|
97
|
+
skipped.
|
|
98
|
+
|
|
99
|
+
`define` preserves additional registration fields and their types; a host can
|
|
100
|
+
select its own rendering contract through the same interface. `extend` prepends
|
|
101
|
+
registrations, so they win equal scores without affecting other registries.
|
|
102
|
+
`Selection` is the registry's `renderers`, `views`, and `archetypes` fields.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { applicable, define, extend, resolve } from '@yaks/render'
|
|
106
|
+
import { parse } from '@yaks/query'
|
|
107
|
+
import { loadVocab } from '@yaks/vocab'
|
|
108
|
+
import { equal } from '@yaks/testing'
|
|
109
|
+
|
|
110
|
+
let vocab = loadVocab({
|
|
111
|
+
$defs: {
|
|
112
|
+
doc: { component: true, properties: {} },
|
|
113
|
+
task: { component: true, properties: {} },
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
let bundle = { entity: { eid: 'a' }, doc: {}, task: {} }
|
|
117
|
+
let registry = define([
|
|
118
|
+
{ view: 'Tile', match: true, name: 'any' },
|
|
119
|
+
{ view: 'Tile', match: parse('.doc .task'), name: 'task' },
|
|
120
|
+
{ view: 'Page', match: parse('.doc'), name: 'page' },
|
|
121
|
+
{ view: 'JSON', match: true, name: 'json' },
|
|
122
|
+
], { views: ['Page', 'Tile'] })
|
|
123
|
+
equal(resolve(registry, bundle, 'Board.Tile', vocab)?.name, 'task')
|
|
124
|
+
equal(resolve(registry, bundle, 'Missing', vocab)?.name, 'json')
|
|
125
|
+
equal(resolve(registry, bundle, undefined, vocab)?.name, 'task')
|
|
126
|
+
equal(applicable(registry, bundle, vocab), ['Page', 'Tile'])
|
|
127
|
+
extend(registry, [{ view: 'Tile', match: parse('.doc .task'), name: 'custom' }])
|
|
128
|
+
equal(resolve(registry, bundle, 'Tile', vocab)?.name, 'custom')
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Component presence through archetypes
|
|
132
|
+
|
|
133
|
+
`options.archetypes` accepts an `ArchetypeLookup`: a function from an
|
|
134
|
+
[archetype](../archetype/README.md) eid to its immutable physical table-name
|
|
135
|
+
array. Component-presence queries can match that array through
|
|
136
|
+
`bundle.entity.archetype`, even when component values were omitted. Results are
|
|
137
|
+
cached per query, vocabulary, and table array. Value predicates and property
|
|
138
|
+
selection use ordinary bundle matching; missing or unknown archetype eids fall
|
|
139
|
+
back to it. The caller loads archetypes and keeps their subscription open to
|
|
140
|
+
receive additional table arrays.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { define, resolve } from '@yaks/render'
|
|
144
|
+
import { parse } from '@yaks/query'
|
|
145
|
+
import { loadVocab } from '@yaks/vocab'
|
|
146
|
+
import { equal } from '@yaks/testing'
|
|
147
|
+
|
|
148
|
+
let vocab = loadVocab({
|
|
149
|
+
$defs: {
|
|
150
|
+
doc: { component: true, properties: {} },
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
let tables = Object.freeze(['doc'])
|
|
154
|
+
let registry = define([{ view: 'Tile', match: parse('.doc') }], {
|
|
155
|
+
archetypes: (eid) => eid == 'shape' ? tables : undefined,
|
|
156
|
+
})
|
|
157
|
+
let bundle = { entity: { eid: 'a', archetype: 'shape' } }
|
|
158
|
+
equal(resolve(registry, bundle, 'Tile', vocab)?.view, 'Tile')
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Actions
|
|
162
|
+
|
|
163
|
+
An **action** is an offered operation with a `name`, an optional query `when`,
|
|
164
|
+
and a `run(bundle, input?)` function returning
|
|
165
|
+
[component](../graph/README.md#data-model) changes (`Action`). `Patch` is the
|
|
166
|
+
component-only part of a [patch](../graph/README.md#data-model); the caller
|
|
167
|
+
chooses whether to apply it. Listing actions never invokes `run`.
|
|
168
|
+
|
|
169
|
+
Static actions are keyed by component name. `actions` collects them for
|
|
170
|
+
components present on the bundle, preserving component registration order and
|
|
171
|
+
duplicates. A `when` condition requires a vocabulary, supplied in
|
|
172
|
+
`options.vocab` or directly to `actions`.
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import { actions, define } from '@yaks/render'
|
|
176
|
+
import { parse } from '@yaks/query'
|
|
177
|
+
import { loadVocab } from '@yaks/vocab'
|
|
178
|
+
import { equal } from '@yaks/testing'
|
|
179
|
+
|
|
180
|
+
let vocab = loadVocab({
|
|
181
|
+
$defs: {
|
|
182
|
+
doc: { component: true, properties: { title: { type: 'string' } } },
|
|
183
|
+
},
|
|
184
|
+
})
|
|
185
|
+
let bundle = { entity: { eid: 'a' }, doc: { title: 'Before' } }
|
|
186
|
+
let calls = 0
|
|
187
|
+
let registry = define([], {
|
|
188
|
+
vocab,
|
|
189
|
+
actions: {
|
|
190
|
+
doc: [{
|
|
191
|
+
name: 'clear',
|
|
192
|
+
when: parse('.doc'),
|
|
193
|
+
run: () => {
|
|
194
|
+
calls++
|
|
195
|
+
return { doc: { title: null } }
|
|
196
|
+
},
|
|
197
|
+
}],
|
|
198
|
+
},
|
|
199
|
+
})
|
|
200
|
+
let offered = actions(registry, bundle)
|
|
201
|
+
equal(offered.map((action) => action.name), ['clear'])
|
|
202
|
+
equal(calls, 0)
|
|
203
|
+
equal(offered[0].run(bundle), { doc: { title: null } })
|
|
204
|
+
equal(calls, 1)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
A **contributor** supplies dynamic actions through `{ match, acts(source) }`
|
|
208
|
+
(`Contributor`). `actions` invokes matching contributors in registration order,
|
|
209
|
+
then filters their returned actions by `when`. Queries read the bundle;
|
|
210
|
+
contributors receive the separately supplied source, or the bundle when no
|
|
211
|
+
source is supplied. `define<R, A, E>` preserves custom registration, action, and
|
|
212
|
+
source types; `Registry` defaults to `Renderer`, `Action`, and `Bundle`.
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
import { actions, define, type Registration } from '@yaks/render'
|
|
216
|
+
import { loadVocab } from '@yaks/vocab'
|
|
217
|
+
import { equal } from '@yaks/testing'
|
|
218
|
+
|
|
219
|
+
let registry = define<Registration, { name: string }, { writable: boolean }>(
|
|
220
|
+
[],
|
|
221
|
+
{
|
|
222
|
+
actions: [{
|
|
223
|
+
match: true,
|
|
224
|
+
acts: (source) => source.writable ? [{ name: 'save' }] : [],
|
|
225
|
+
}],
|
|
226
|
+
},
|
|
227
|
+
)
|
|
228
|
+
let bundle = { entity: { eid: 'a' } }
|
|
229
|
+
let vocab = loadVocab([])
|
|
230
|
+
equal(actions(registry, bundle, vocab, { writable: true }), [{ name: 'save' }])
|
|
231
|
+
equal(actions(registry, bundle, vocab, { writable: false }), [])
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Editors
|
|
235
|
+
|
|
236
|
+
An **editor** is a renderer selected by a
|
|
237
|
+
[property](../graph/README.md#data-model)'s declaration rather than an entity's
|
|
238
|
+
current values. Supplying `ctx.comp` and `ctx.prop` to `resolve` or `applicable`
|
|
239
|
+
selects against a **property projection**: a temporary bundle of that property's
|
|
240
|
+
declaration, such as
|
|
241
|
+
`{ entity: { eid: 'doc.title' }, prop: { comp: 'doc', prop: 'title', type: 'string', ref: undefined } }`.
|
|
242
|
+
Rendering still receives the original bundle and context.
|
|
243
|
+
|
|
244
|
+
The property projection's queryable fields are `prop.comp`, `prop.prop`,
|
|
245
|
+
`prop.type`, and `prop.ref`. `prop.type` uses the vocabulary category or scalar
|
|
246
|
+
type, translating `text` to `string` and `bool` to `boolean`. Selection works
|
|
247
|
+
when the property's value is absent; an unknown property or `prop` without
|
|
248
|
+
`comp` throws. A `comp` alone leaves entity selection unchanged. Use separate
|
|
249
|
+
view names for entity queries and property queries. Editors can inspect more
|
|
250
|
+
schema details through `vocab.prop(comp, prop)`; [@yaks/ux](../ux/README.md)
|
|
251
|
+
registers `Edit` controls.
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import { define, resolve } from '@yaks/render'
|
|
255
|
+
import { parse } from '@yaks/query'
|
|
256
|
+
import { loadVocab } from '@yaks/vocab'
|
|
257
|
+
import { equal } from '@yaks/testing'
|
|
258
|
+
|
|
259
|
+
let vocab = loadVocab({
|
|
260
|
+
$defs: {
|
|
261
|
+
doc: { component: true, properties: { title: { type: 'string' } } },
|
|
262
|
+
},
|
|
263
|
+
})
|
|
264
|
+
let registry = define([{ view: 'Edit', match: parse('.prop.type=string') }])
|
|
265
|
+
let bundle = { entity: { eid: 'a' } }
|
|
266
|
+
equal(
|
|
267
|
+
resolve(registry, bundle, 'Edit', vocab, { comp: 'doc', prop: 'title' })
|
|
268
|
+
?.view,
|
|
269
|
+
'Edit',
|
|
270
|
+
)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Parsing edits
|
|
274
|
+
|
|
275
|
+
`edit(vocab, { comp, prop }, options?)` creates a single-property action. Its
|
|
276
|
+
`run` parses input, validates it with the vocabulary, and returns only that
|
|
277
|
+
property. Null clears the property. Numbers and booleans become typed values;
|
|
278
|
+
enum aliases resolve to declared members; timestamps require an explicit
|
|
279
|
+
timezone; JSON text is validated. Computed or stamped properties, and properties
|
|
280
|
+
of components without `wire: true`, reject edits.
|
|
281
|
+
|
|
282
|
+
`options.parse(input, prop, bundle)` replaces the input parser;
|
|
283
|
+
`options.validate(value, prop, bundle)` can reject a parsed, vocabulary-checked
|
|
284
|
+
value by throwing. Creating or listing an action calls neither hook.
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
import { edit } from '@yaks/render'
|
|
288
|
+
import { loadVocab } from '@yaks/vocab'
|
|
289
|
+
import { equal, throws } from '@yaks/testing'
|
|
290
|
+
|
|
291
|
+
let vocab = loadVocab({
|
|
292
|
+
$defs: {
|
|
293
|
+
doc: { component: true, properties: { count: { type: 'number' } } },
|
|
294
|
+
},
|
|
295
|
+
})
|
|
296
|
+
let bundle = { entity: { eid: 'a' }, doc: { count: 2 } }
|
|
297
|
+
let set = edit(vocab, { comp: 'doc', prop: 'count' })
|
|
298
|
+
equal(set.run(bundle, '3'), { doc: { count: 3 } })
|
|
299
|
+
equal(set.run(bundle, null), { doc: { count: null } })
|
|
300
|
+
await throws(() => set.run(bundle, 'many'))
|
|
301
|
+
let custom = edit(vocab, { comp: 'doc', prop: 'count' }, {
|
|
302
|
+
parse: (input) => Number(input) * 2,
|
|
303
|
+
validate: (value) => {
|
|
304
|
+
if (Number(value) > 10) throw new Error('too many')
|
|
305
|
+
},
|
|
306
|
+
})
|
|
307
|
+
equal(custom.run(bundle, '3'), { doc: { count: 6 } })
|
|
308
|
+
await throws(() => custom.run(bundle, '6'))
|
|
309
|
+
equal(bundle.doc.count, 2)
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Shared views
|
|
313
|
+
|
|
314
|
+
`@yaks/render/views` exports the `views` registry: `Title`, `Tile`, `Facts`,
|
|
315
|
+
`Comment`, and `Page`. Register package-specific renderers ahead of these; query
|
|
316
|
+
matches beat catch-all registrations. `Title` falls back to the caller's id, or
|
|
317
|
+
kind inside `Tile`; an [edge](../edge/README.md)'s `Title` states its relation.
|
|
318
|
+
`Tile` combines id, title, and status. `Facts` lists components except `entity`,
|
|
319
|
+
`doc`, `comment`, and `edge`. `Comment` combines author, time, and body. `Page`
|
|
320
|
+
gathers title, body, relations, comments, and facts through nested rendering.
|
|
321
|
+
|
|
322
|
+
**Shown** is the caller-supplied context for these views: `id`, `kind`, `name`,
|
|
323
|
+
`when`, and `show` describe display values and render other entities; optional
|
|
324
|
+
`link`, `relation`, `relations`, and `comments` supply links and related
|
|
325
|
+
content. A **Related** value groups bundles under a title:
|
|
326
|
+
`{ title: 'requires', items: [...] }`. `sheet(colors)` supplies the views'
|
|
327
|
+
terminal styles from `dim`, `heading`, and `muted` colors;
|
|
328
|
+
[@yaks/tui](../tui/README.md) supplies terminal painting.
|
|
329
|
+
|
|
330
|
+
A long text in a list is a passage, never the text whole. `passage(said)` is a
|
|
331
|
+
renderer, with its `needs`, that draws one row: who wrote it (`created.by`),
|
|
332
|
+
when (`created.at`), where it sits, and the words around what was sought (the
|
|
333
|
+
caller's `ctx.words`), every match marked, in the class names of
|
|
334
|
+
[@yaks/ui](../ui/README.md)'s `Passage` and `Match`. A **Said** value says where
|
|
335
|
+
the words are: `texts`, the first matching what was sought giving the passage,
|
|
336
|
+
and optionally a `title`, `what` kind of words they are, and `where` they sit
|
|
337
|
+
(`['in', session]`). A package that owns words registers its `Tile` with it:
|
|
338
|
+
[@yaks/session](../session/README.md) for words said in a transcript,
|
|
339
|
+
[@yaks/kernel](../kernel/README.md) for a comment and
|
|
340
|
+
[@yaks/tools](../tools/README.md) for a kept text.
|
|
341
|
+
|
|
342
|
+
```ts
|
|
343
|
+
import { sheet, type Shown, views } from '@yaks/render/views'
|
|
344
|
+
import { type Node, plain, tree } from '@yaks/text'
|
|
345
|
+
import { loadVocab } from '@yaks/vocab'
|
|
346
|
+
import { equal } from '@yaks/testing'
|
|
347
|
+
|
|
348
|
+
let vocab = loadVocab({
|
|
349
|
+
$defs: {
|
|
350
|
+
task: { component: true, properties: {} },
|
|
351
|
+
comment: { component: true, properties: {} },
|
|
352
|
+
edge: { component: true, properties: {} },
|
|
353
|
+
},
|
|
354
|
+
})
|
|
355
|
+
let bundle = { entity: { eid: 'a' }, task: {} }
|
|
356
|
+
let ctx: Shown<Node> = {
|
|
357
|
+
id: (b) => b.entity.eid,
|
|
358
|
+
kind: () => 'task',
|
|
359
|
+
name: (eid) => eid,
|
|
360
|
+
when: () => 'today',
|
|
361
|
+
relation: () => 'requires',
|
|
362
|
+
show: (b, view) => tree(views, b, view, vocab, ctx),
|
|
363
|
+
relations: [{ title: 'requires', items: [{ entity: { eid: 'b' } }] }],
|
|
364
|
+
comments: [{ entity: { eid: 'c' }, comment: {} }],
|
|
365
|
+
}
|
|
366
|
+
equal(plain(tree(views, bundle, 'Title', vocab, ctx)), 'a')
|
|
367
|
+
let edge = { entity: { eid: 'e' }, edge: { from: 'a', to: 'b' } }
|
|
368
|
+
equal(plain(tree(views, edge, 'Title', vocab, ctx)), 'a requires b')
|
|
369
|
+
equal(plain(tree(views, bundle, 'Tile', vocab, ctx)), 'a task ')
|
|
370
|
+
equal(plain(tree(views, bundle, 'Facts', vocab, ctx)), 'task: ✓')
|
|
371
|
+
equal(plain(tree(views, ctx.comments![0], 'Comment', vocab, ctx)), 'someone')
|
|
372
|
+
let page = plain(tree(views, bundle, 'Page', vocab, ctx))
|
|
373
|
+
for (
|
|
374
|
+
let part of [
|
|
375
|
+
'task a',
|
|
376
|
+
'requires',
|
|
377
|
+
'b task',
|
|
378
|
+
'1 comment',
|
|
379
|
+
'someone',
|
|
380
|
+
'Details',
|
|
381
|
+
'task: ✓',
|
|
382
|
+
]
|
|
383
|
+
) {
|
|
384
|
+
equal(page.includes(part), true)
|
|
385
|
+
}
|
|
386
|
+
equal(sheet({ dim: 'gray', heading: 'blue', muted: 'silver' }).Section_Title, {
|
|
387
|
+
fg: 'blue',
|
|
388
|
+
})
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
## Limits
|
|
392
|
+
|
|
393
|
+
The registry and its caches live in memory. This package opens no graph or
|
|
394
|
+
database, stores no entities, and applies no changes. Rendering hosts build
|
|
395
|
+
output nodes; callers provide related bundles, display values, and write
|
|
396
|
+
handling. It runs in Deno, Node, browsers, and workers without a DOM or UI
|
|
397
|
+
framework.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archetype.d.ts","sources":["../archetype.ts"],"names":[],"mappings":"AAMA;UACU,GACV,YAAY,mBAAmB,KAAK,MAAM,cAAc,MAAM,KAAK,SAAS"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Action, Bundle, Context, Patch } from "./mod.js";
|
|
2
|
+
/** The application applies a successful edit and may display rejected input. */ export type Events = {
|
|
3
|
+
onPatch?: (patch: Patch, bundle: Bundle) => void;
|
|
4
|
+
onError?: (error: unknown, bundle: Bundle) => void;
|
|
5
|
+
};
|
|
6
|
+
/** A synchronous read; absence is allowed so a subscription can announce arrival. */ export type Store = (eid: string) => Bundle | undefined;
|
|
7
|
+
/** Watch one entity and return the cleanup for that listener. */ export type Subscribe = (eid: string, notify: () => void) => () => void;
|
|
8
|
+
/** An entity address and view; all remaining props are renderer context. */ export type EntityProps = Context & Events & {
|
|
9
|
+
eid: string;
|
|
10
|
+
view?: string;
|
|
11
|
+
};
|
|
12
|
+
/** Whether a portable handler contains an action to run. */ export declare let action: (value: unknown) => value is Action;
|
|
13
|
+
/** Adapt a portable edit action to a control event and report its outcome. */ export declare let change: (act: Action, bundle: Bundle, ctx: Events) => (event: Event) => void;
|
|
14
|
+
/** Preserve native change events for handlers in portable renders. */ export declare let committed: (props: Record<string, unknown> | null, bundle: Bundle, ctx: Events) => Record<string, unknown> | null;
|
|
15
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sources":["../component.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,mBAAkB;AAE9D,8EAA8E,GAC9E,YAAY;EACV,WAAW,OAAO,OAAO,QAAQ,WAAW,IAAI;EAChD,WAAW,OAAO,OAAO,EAAE,QAAQ,WAAW,IAAI;;AAGpD,mFAAmF,GACnF,YAAY,SAAS,KAAK,MAAM,KAAK,SAAS,SAAS;AAEvD,+DAA+D,GAC/D,YAAY,aAAa,KAAK,MAAM,EAAE,cAAc,IAAI,WAAW,IAAI;AAEvE,0EAA0E,GAC1E,YAAY,cAAc,UAAU;EAAW,KAAK,MAAM;EAAE,OAAO,MAAM;;AAEzE,0DAA0D,GAC1D,OAAO,YAAI,SAAU,OAAO,OAAO,KAAG,SAAS,OAEf;AAYhC,4EAA4E,GAC5E,OAAO,YAAI,SACR,KAAK,QAAQ,QAAQ,QAAQ,KAAK,YAAU,OAAO,UAAU,IAAI,CAoBjE;AAEH,oEAAoE,GACpE,OAAO,YAAI,YACT,OAAO,OAAO,MAAM,EAAE,OAAO,IAAI,IAAI,EACrC,QAAQ,QACR,KAAK,WACJ,OAAO,MAAM,EAAE,OAAO,IAAI,IAAI,CAsBhC"}
|
package/_dist/edit.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Property actions parse input without touching a store or a rendering
|
|
2
|
+
* backend. */ import type { Bundle } from "@yaks/match";
|
|
3
|
+
import type { Prop, Vocab } from "@yaks/vocab";
|
|
4
|
+
import type { Action } from "./types.js";
|
|
5
|
+
/** Applications may supply their value language and additional validation. */ export type EditOptions = {
|
|
6
|
+
parse?: (input: unknown, prop: Prop, bundle: Bundle) => unknown;
|
|
7
|
+
validate?: (value: unknown, prop: Prop, bundle: Bundle) => void;
|
|
8
|
+
};
|
|
9
|
+
type Address = {
|
|
10
|
+
comp: string;
|
|
11
|
+
prop: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Offer a single-property patch. Construction is inert; run parses, validates
|
|
15
|
+
* and returns only that property. The caller decides whether to apply the patch.
|
|
16
|
+
*/ export declare let edit: (vocab: Vocab, address: Address, options?: EditOptions) => Action;
|
|
17
|
+
//# sourceMappingURL=edit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sources":["../edit.ts"],"names":[],"mappings":"AAAA;YACY,GAEZ,cAAc,MAAM,2BAAgC;AACpD,cAAc,IAAI,EAAE,KAAK,2BAAgC;AAEzD,cAAc,MAAM,qBAAoB;AAExC,4EAA4E,GAC5E,YAAY;EACV,SAAS,OAAO,OAAO,EAAE,MAAM,MAAM,QAAQ,WAAW,OAAO;EAC/D,YAAY,OAAO,OAAO,EAAE,MAAM,MAAM,QAAQ,WAAW,IAAI;;KAG5D;EAAY,MAAM,MAAM;EAAE,MAAM,MAAM;;AA2E3C;;;CAGC,GACD,OAAO,YAAI,OACT,OAAO,OACP,SAAS,SACT,UAAS,gBACR,OAeF"}
|