@yaks/draft 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 +157 -2
- package/_dist/browser.d.ts +30 -0
- package/_dist/browser.d.ts.map +1 -0
- package/_dist/desk.d.ts +55 -0
- package/_dist/desk.d.ts.map +1 -0
- package/_dist/gateway.d.ts +42 -0
- package/_dist/gateway.d.ts.map +1 -0
- package/_dist/graph.d.ts +6 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/input.d.ts +22 -0
- package/_dist/input.d.ts.map +1 -0
- package/_dist/merge.d.ts +15 -0
- package/_dist/merge.d.ts.map +1 -0
- package/_dist/mod.d.ts +24 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/plugin.d.ts +29 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/browser.js +300 -0
- package/browser.js.map +1 -0
- package/browser.ts +350 -0
- package/deno.json +1 -0
- package/desk.js +383 -0
- package/desk.js.map +1 -0
- package/desk.ts +477 -0
- package/gateway.js +112 -0
- package/gateway.js.map +1 -0
- package/gateway.ts +129 -0
- package/graph.js +13 -0
- package/graph.js.map +1 -0
- package/graph.ts +17 -0
- package/input.js +65 -0
- package/input.js.map +1 -0
- package/input.ts +90 -0
- package/merge.js +60 -0
- package/merge.js.map +1 -0
- package/merge.ts +65 -0
- package/mod.js +24 -0
- package/mod.js.map +1 -0
- package/mod.ts +38 -0
- package/package.json +37 -4
- package/plugin.js +157 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +122 -0
- package/vocab.js +17 -0
- package/vocab.js.map +1 -0
- package/vocab.json +119 -0
- package/vocab.ts +18 -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,158 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/draft
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
What a person has typed and not yet sent. A draft is graph data like anything
|
|
4
|
+
else: kept by the store, one per person and place, and seen by every interface
|
|
5
|
+
the person uses (another tab, a terminal, another device) until it is sent or
|
|
6
|
+
discarded. It is never swept or given a lifetime; it ends when its text is
|
|
7
|
+
emptied, and the journal keeps every text it held, so a discard can be undone.
|
|
8
|
+
|
|
9
|
+
## Components
|
|
10
|
+
|
|
11
|
+
| component | what it is |
|
|
12
|
+
| --------- | --------------------------------------------------------------------------- |
|
|
13
|
+
| `draft` | `by` (the person), `place` (where it is typed), `text`, `rev` (stamped) |
|
|
14
|
+
| `typed` | an event beside a write of `draft.text`: `over`, the text it was typed over |
|
|
15
|
+
|
|
16
|
+
A draft's entity is `draftEid(by, place)`, so every interface finds the same
|
|
17
|
+
one. A place is whatever the interface names it: `<eid>.comment`,
|
|
18
|
+
`edit:<eid>:doc.title`, `search`.
|
|
19
|
+
|
|
20
|
+
## Two interfaces at once
|
|
21
|
+
|
|
22
|
+
Each write of a draft's text says what it was typed over. The store's hook
|
|
23
|
+
(`merging`, in `drafts()`) merges that write with what the store holds
|
|
24
|
+
(`merge`): changes to different parts of the text both apply; changes to the
|
|
25
|
+
same part keep both versions, the incoming first, unless one already holds the
|
|
26
|
+
other (a write sent again, or typed on from what the other side has), which is
|
|
27
|
+
taken once. Nothing either side typed is dropped. Every write counts one more
|
|
28
|
+
`rev`, so an interface hearing two answers keeps the newer.
|
|
29
|
+
|
|
30
|
+
## An interface's side
|
|
31
|
+
|
|
32
|
+
```ts ignore
|
|
33
|
+
import { desk } from '@yaks/draft'
|
|
34
|
+
|
|
35
|
+
let drafts = desk(client, { by: () => person, stash: localStorage })
|
|
36
|
+
drafts.type('T-5.comment', 'looks good') // text() answers at once
|
|
37
|
+
drafts.text('T-5.comment') // 'looks good', here and, soon, everywhere
|
|
38
|
+
drafts.spend('T-5.comment', commentBundles) // sent: emptied in one batch
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
A keystroke costs no round trip. The text is kept in the stash (Web Storage,
|
|
42
|
+
which answers at once) until the store has it, so a crash, a closed tab or a
|
|
43
|
+
store out of reach loses nothing: the next load finds it there and sends it. The
|
|
44
|
+
store is written at most once a pace (`pace`, 500 ms) per draft, one write in
|
|
45
|
+
flight at a time; what was typed while one flew is merged onto its answer, and
|
|
46
|
+
so is every text another interface makes the store hold. A spend goes at once,
|
|
47
|
+
in the same batch as the send it went into, so a refused send leaves the draft.
|
|
48
|
+
A spend keeps its emptied text in the stash until its write is accepted, even
|
|
49
|
+
while the person types the next draft. A refusal or an unknown transport outcome
|
|
50
|
+
restores those words; a reload recovers them from the stash.
|
|
51
|
+
|
|
52
|
+
`spend` resolves to `true` on acknowledgement or `false` on refusal or an
|
|
53
|
+
unknown outcome, which is also passed to `report`. `restore(place, text, over)`
|
|
54
|
+
imports preserved text from another source, merging its changes over `over`
|
|
55
|
+
(empty by default) with the current draft.
|
|
56
|
+
|
|
57
|
+
`client` is anything with a `mutate` answered by the server-applied bundles and
|
|
58
|
+
a `watch`: a @yaks/client `client()` is one. `by` is read reactively; while it
|
|
59
|
+
is unknown, typing is kept and written once it is.
|
|
60
|
+
|
|
61
|
+
## Files
|
|
62
|
+
|
|
63
|
+
| file | owns |
|
|
64
|
+
| ------------ | ---------------------------------------------- |
|
|
65
|
+
| `vocab.json` | the `draft` component and the `typed` event |
|
|
66
|
+
| `merge.ts` | `merge`: two texts typed over one, made one |
|
|
67
|
+
| `plugin.ts` | `drafts()`: the plugin, and its `merging` hook |
|
|
68
|
+
| `desk.ts` | `desk`, `draftEid`: an interface's drafts |
|
|
69
|
+
|
|
70
|
+
## Compatibility
|
|
71
|
+
|
|
72
|
+
Deno, browsers and Workers: the package reaches no runtime API beyond
|
|
73
|
+
`setTimeout` and the Web Storage a caller passes it.
|
|
74
|
+
|
|
75
|
+
## Interface drafts
|
|
76
|
+
|
|
77
|
+
`./input` owns the interface's `drafts`, `lone` and `useDraft` hook. Its **draft
|
|
78
|
+
host** supplies the desk's watch/write client, actor, person query and storage
|
|
79
|
+
through `configureDrafts`; it has no dependency on the application.
|
|
80
|
+
`useDraft(place, ref)` mirrors durable text into a kit `Field`, and its
|
|
81
|
+
`spend(bundles)` clears that text in the same write as what it became.
|
|
82
|
+
|
|
83
|
+
Binding needs the interface's client and identity; this sketch is not run
|
|
84
|
+
because it stands in for a connected interface:
|
|
85
|
+
|
|
86
|
+
```ts ignore
|
|
87
|
+
import { configureDrafts, drafts } from '@yaks/draft/input'
|
|
88
|
+
configureDrafts({
|
|
89
|
+
client,
|
|
90
|
+
by: () => actor,
|
|
91
|
+
people: () => people(),
|
|
92
|
+
stash: () => storage,
|
|
93
|
+
})
|
|
94
|
+
drafts.type('task.comment', 'Please check the result')
|
|
95
|
+
drafts.spend('task.comment', [{
|
|
96
|
+
entity: { eid: 'note' },
|
|
97
|
+
comment: { target: 'task' },
|
|
98
|
+
doc: { body: drafts.text('task.comment') },
|
|
99
|
+
}])
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Plain browser fields
|
|
103
|
+
|
|
104
|
+
The `./browser` entry binds an input or textarea to the same `desk`, without
|
|
105
|
+
requiring a UI framework. yaks.app publishes it through the app's existing
|
|
106
|
+
`./api/client.js` door:
|
|
107
|
+
|
|
108
|
+
```js ignore
|
|
109
|
+
import { drafts } from './api/client.js'
|
|
110
|
+
const desk = drafts()
|
|
111
|
+
desk.bind(document.querySelector('textarea'), 'recipe:notes')
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
A stable place finds the person's text on every device and tab. The binding
|
|
115
|
+
listens for typing, preserves composition, and mirrors newer store revisions. It
|
|
116
|
+
returns an unbind function: call it before replacing the element, then bind its
|
|
117
|
+
replacement to the same place. Keep the desk across rerenders; `close()` unbinds
|
|
118
|
+
its fields and stops its subscription and timers when the page unmounts. Every
|
|
119
|
+
input is stashed synchronously, so closing before a paced write completes leaves
|
|
120
|
+
a recovery copy for the next load. Accepted text lives in the store;
|
|
121
|
+
localStorage holds only pending recovery, scoped to this app's API address and
|
|
122
|
+
person. Each pending field retains its owner through sign-in recovery. A failed
|
|
123
|
+
target copy leaves that person’s copy readable in place; later guest input at
|
|
124
|
+
the same field is separate, so another person cannot inherit it.
|
|
125
|
+
|
|
126
|
+
`has(place)` distinguishes an existing empty edit from a place never held.
|
|
127
|
+
`text(place)`, `type(place, text)` and `restore(place, text, over)` are the
|
|
128
|
+
desk's same methods, and `places()` lists every place holding text. A page that
|
|
129
|
+
draws drafts itself rather than into a field calls `follow(fn)`: `fn` runs now
|
|
130
|
+
and again whenever a text or place it read changes, here or on another device,
|
|
131
|
+
until the function it returns is called. `ready` settles once it is known who is
|
|
132
|
+
typing and typing is kept. A visitor `me()` names no person for types too: their
|
|
133
|
+
text is kept in the page and in this browser's recovery copy under `GUEST`
|
|
134
|
+
(`'guest'`), never written to the store as a draft, and `spend` writes only the
|
|
135
|
+
bundles it is given. `spend(place, bundles)` clears a draft in the same write as
|
|
136
|
+
the thing made from it, and resolves to a boolean: a refusal restores the text.
|
|
137
|
+
The public client retries pending receipts with the same write identity; a watch
|
|
138
|
+
never substitutes for durable acceptance. Pass `drafts({report(error) {
|
|
139
|
+
… }})`
|
|
140
|
+
to show a persistence refusal; without one it is raised for the page's error
|
|
141
|
+
reporter. `by`, `stash` (or `false`) and `pace` may be supplied when a host
|
|
142
|
+
already knows identity, supplies its own recovery storage, or needs a different
|
|
143
|
+
write pace. The ordinary app needs none of them.
|
|
144
|
+
|
|
145
|
+
A host that vouches an earlier principal may pass `recover: [principal]`, for
|
|
146
|
+
example the same browser's guest instrument after sign-in. Each pending field
|
|
147
|
+
changes ownership before recovery tries another storage location. The desk can
|
|
148
|
+
keep using that copy in place until the store accepts it. Fresh guest input in
|
|
149
|
+
the same field has separate ownership; it can pass to a later signed-in person
|
|
150
|
+
without exposing the earlier person's pending text. Recovery merges copies held
|
|
151
|
+
by the current person and never opens another app's scope.
|
|
152
|
+
|
|
153
|
+
Private app Workers relay their draft route through the caller's `STORE` binding
|
|
154
|
+
at `/drafts`. Its GET snapshot and POST `{principal, place, text, over}` use the
|
|
155
|
+
platform-vouched identity, not the app's own grant. Personal drafts keep
|
|
156
|
+
`draft.by`; guest drafts keep `draft.via` and retain guest authorship until the
|
|
157
|
+
directory's sign-in receipt attributes it. Explicit logout starts fresh guest
|
|
158
|
+
work, while earlier receipts and recovery copies remain with their person.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Bundle } from "@yaks/graph";
|
|
2
|
+
import { type Desk, type DeskOpts, type Stash } from "./desk.js";
|
|
3
|
+
export { draftEid } from "./desk.js";
|
|
4
|
+
/** The published store client, without any platform implementation here. */ export type Store = {
|
|
5
|
+
apply: (bundles: Bundle[]) => Promise<{
|
|
6
|
+
bundles: Bundle[];
|
|
7
|
+
pending?: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
me: () => Promise<{
|
|
10
|
+
person: string | null;
|
|
11
|
+
}>;
|
|
12
|
+
subscribe: (query: string, hear: (rows: Bundle[]) => void) => () => void;
|
|
13
|
+
};
|
|
14
|
+
export type BrowserOpts = Pick<DeskOpts, 'pace' | 'report' | 'line' | 'writer'> & {
|
|
15
|
+
/** Supply identity when the page already knows it; otherwise ask me(). */ by?: string;
|
|
16
|
+
/** Earlier principals vouched by this host, such as this browser's guest
|
|
17
|
+
* instrument after sign-in. Their pending text moves before it is removed. */ recover?: string[];
|
|
18
|
+
/** A recovery copy, not the source of truth. false disables it. */ stash?: Stash | false;
|
|
19
|
+
/** Places whose unacknowledged input may stay only in this tab. */ volatile?: (place: string) => boolean;
|
|
20
|
+
};
|
|
21
|
+
/** Whose recovery copy a visitor nobody knows types into. */ export declare let GUEST: string;
|
|
22
|
+
/** A durable desk with plain DOM bindings. */ export type BrowserDrafts = Desk & {
|
|
23
|
+
bind: (field: HTMLInputElement | HTMLTextAreaElement, place: string) => () => void;
|
|
24
|
+
/** Settles once it is known who is typing (a person, or a visitor nobody
|
|
25
|
+
* knows) and their drafts may be typed. */ ready: Promise<void>;
|
|
26
|
+
/** Run `fn` now and again whenever a text, place or identity it read
|
|
27
|
+
* changes, until the returned function is called. */ follow: (fn: () => void) => () => void;
|
|
28
|
+
};
|
|
29
|
+
/** Bind fields with one line; all merging, receipts and recovery belong to desk. */ export declare let browserDrafts: (client: Store, scope: string, opts?: BrowserOpts) => BrowserDrafts;
|
|
30
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sources":["../browser.ts"],"names":[],"mappings":"AAEA,cAAc,MAAM,2BAAgC;AACpD,SAAS,KAAK,IAAI,EAAQ,KAAK,QAAQ,EAAE,KAAK,KAAK,oBAAmB;AAEtE,SAAS,QAAQ,oBAAmB;AAEpC,0EAA0E,GAC1E,YAAY;EACV,QACE,SAAS,aACN;IAAU,SAAS;IAAU,UAAU,OAAO;;EACnD,UAAU;IAAU,QAAQ,MAAM,GAAG,IAAI;;EACzC,YAAY,OAAO,MAAM,EAAE,OAAO,MAAM,aAAa,IAAI,WAAW,IAAI;;AAE1E,YAAY,cACR,KAAK,UAAU,SAAS,WAAW,SAAS;EAE5C,wEAAwE,GACxE,KAAK,MAAM;EACX;gFAC4E,GAC5E,UAAU,MAAM;EAChB,iEAAiE,GACjE,QAAQ,QAAQ,KAAK;EACrB,iEAAiE,GACjE,YAAY,OAAO,MAAM,KAAK,OAAO;;AAGzC,2DAA2D,GAC3D,OAAO,YAAI,cAAe;AA6I1B,4CAA4C,GAC5C,YAAY,gBAAgB;EAC1B,OACE,OAAO,mBAAmB,qBAC1B,OAAO,MAAM,WACJ,IAAI;EACf;2CACyC,GACzC,OAAO,QAAQ,IAAI;EACnB;qDACmD,GACnD,SAAS,UAAU,IAAI,WAAW,IAAI;;AAGxC,kFAAkF,GAClF,OAAO,YAAI,gBACT,QAAQ,OACR,OAAO,MAAM,EACb,OAAM,gBACL,cA+JF"}
|
package/_dist/desk.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Bundle } from "@yaks/graph";
|
|
2
|
+
/** The eid of the draft `by` types in `place`: the same in every interface,
|
|
3
|
+
* so each finds the one the others write.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { assertEquals, assertNotEquals } from '@std/assert'
|
|
7
|
+
* import { draftEid } from '@yaks/draft'
|
|
8
|
+
*
|
|
9
|
+
* assertEquals(draftEid('jo', 'search'), draftEid('jo', 'search'))
|
|
10
|
+
* assertNotEquals(draftEid('jo', 'search'), draftEid('al', 'search'))
|
|
11
|
+
* ```
|
|
12
|
+
*/ export declare let draftEid: (by: string, place: string) => string;
|
|
13
|
+
/** As much of a graph as a desk needs: a write answered with the batch as
|
|
14
|
+
* the store took it, and a watch. A @yaks/client `client()` is one. */ export type Client = {
|
|
15
|
+
mutate: (bundles: Bundle[]) => Bundle[] | Promise<Bundle[]>;
|
|
16
|
+
watch: (query: string) => {
|
|
17
|
+
value: Bundle[];
|
|
18
|
+
subscribe: (fn: (rows: Bundle[]) => void) => () => void;
|
|
19
|
+
close?: () => void;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/** Where what the store has not taken yet is kept across a reload: the part
|
|
23
|
+
* of Web Storage a desk uses. `localStorage` is one. */ export type Stash = Pick<Storage, 'length' | 'key' | 'getItem' | 'setItem' | 'removeItem'>;
|
|
24
|
+
/** What a desk offers each place a person types in. */ export type Drafts = {
|
|
25
|
+
/** Whether this place has been held, including an intentionally empty edit. */ has: (place: string) => boolean;
|
|
26
|
+
/** Every place holding text, in the order first held, read reactively. */ places: () => string[];
|
|
27
|
+
/** what is typed in `place` and not yet sent ('' for nothing), read
|
|
28
|
+
* reactively */ text: (place: string) => string;
|
|
29
|
+
/** the person typed: keep it */ type: (place: string, text: string) => void;
|
|
30
|
+
/** it was sent, or discarded: empty it at once, in one batch with `also`
|
|
31
|
+
* (the send it went into) */ spend: (place: string, also?: Bundle[], opts?: {
|
|
32
|
+
optimistic?: boolean;
|
|
33
|
+
}) => Promise<boolean>;
|
|
34
|
+
/** Restore text from another source, preserving subsequent typing.
|
|
35
|
+
* `over` is the source text already imported (default: empty). */ restore: (place: string, text: string, over?: string) => void;
|
|
36
|
+
/** Run `fn` now and again whenever a text or place it read changes, until
|
|
37
|
+
* the returned function is called. */ follow: (fn: () => void) => () => void;
|
|
38
|
+
};
|
|
39
|
+
/** A desk can tell a recovery source when it can release its own copy. */ export interface Desk extends Drafts {
|
|
40
|
+
/** Whether the restored draft is durable across reload. */ restore: (place: string, text: string, over?: string) => boolean;
|
|
41
|
+
/** Settle the current draft with the store before opening another surface. */ flush: (place: string) => Promise<boolean>;
|
|
42
|
+
close: () => void;
|
|
43
|
+
}
|
|
44
|
+
/** What a desk is bound with. */ export type DeskOpts = {
|
|
45
|
+
/** whose drafts they are: the person, read reactively, and nobody yet
|
|
46
|
+
* while it is not known (typing is kept, and written once it is) */ by: () => string | undefined;
|
|
47
|
+
/** where untaken text waits across a reload (default: nowhere) */ stash?: Stash;
|
|
48
|
+
/** the least time between two writes of one draft, in ms (default 500) */ pace?: number;
|
|
49
|
+
/** a write the store refused; the text stays, and goes with the next */ report?: (err: unknown) => void;
|
|
50
|
+
/** the line the store answers `by`'s drafts on (default `.draft.by=<by>`),
|
|
51
|
+
* where it names them otherwise, as a page graph of several stores does */ line?: (by: string) => string;
|
|
52
|
+
/** Identify this desk's writes when saves and spends use separate doors. */ writer?: string;
|
|
53
|
+
};
|
|
54
|
+
/** Bind a person's drafts to the graph that keeps them. */ export declare let desk: (client: Client, opts: DeskOpts) => Desk;
|
|
55
|
+
//# sourceMappingURL=desk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"desk.d.ts","sources":["../desk.ts"],"names":[],"mappings":"AA2BA,cAAc,MAAM,2BAAgC;AAIpD;;;;;;;;;;CAUC,GACD,OAAO,YAAI,WAAY,IAAI,MAAM,EAAE,OAAO,MAAM,KAAG,MAAM,CACb;AAE5C;qEACqE,GACrE,YAAY;EACV,SAAS,SAAS,aAAa,WAAW,QAAQ;EAClD,QAAQ,OAAO,MAAM;IACnB,OAAO;IACP,YAAY,KAAK,MAAM,aAAa,IAAI,WAAW,IAAI;IACvD,cAAc,IAAI;;;AAItB;sDACsD,GACtD,YAAY,QAAQ,KAClB,SACA,WAAW,QAAQ,YAAY,YAAY;AAG7C,qDAAqD,GACrD,YAAY;EACV,6EAA6E,GAC7E,MAAM,OAAO,MAAM,KAAK,OAAO;EAC/B,wEAAwE,GACxE,cAAc,MAAM;EACpB;gBACc,GACd,OAAO,OAAO,MAAM,KAAK,MAAM;EAC/B,8BAA8B,GAC9B,OAAO,OAAO,MAAM,EAAE,MAAM,MAAM,KAAK,IAAI;EAC3C;6BAC2B,GAC3B,QACE,OAAO,MAAM,EACb,OAAO,UACP;IAAS,aAAa,OAAO;QAC1B,QAAQ,OAAO;EACpB;kEACgE,GAChE,UAAU,OAAO,MAAM,EAAE,MAAM,MAAM,EAAE,OAAO,MAAM,KAAK,IAAI;EAC7D;sCACoC,GACpC,SAAS,UAAU,IAAI,WAAW,IAAI;;AAGxC,wEAAwE,GACxE,iBAAiB,aAAa;EAC5B,yDAAyD,GACzD,UAAU,OAAO,MAAM,EAAE,MAAM,MAAM,EAAE,OAAO,MAAM,KAAK,OAAO;EAChE,4EAA4E,GAC5E,QAAQ,OAAO,MAAM,KAAK,QAAQ,OAAO;EACzC,aAAa,IAAI;;AAGnB,+BAA+B,GAC/B,YAAY;EACV;oEACkE,GAClE,UAAU,MAAM,GAAG,SAAS;EAC5B,gEAAgE,GAChE,QAAQ;EACR,wEAAwE,GACxE,OAAO,MAAM;EACb,sEAAsE,GACtE,UAAU,KAAK,OAAO,KAAK,IAAI;EAC/B;2EACyE,GACzE,QAAQ,IAAI,MAAM,KAAK,MAAM;EAC7B,0EAA0E,GAC1E,SAAS,MAAM;;AA4EjB,yDAAyD,GAUzD,OAAO,YAAI,OACT,QAAQ,QACR,MAAM,aACL,KAkRF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Bundle } from "@yaks/graph";
|
|
2
|
+
export type DraftDoor = {
|
|
3
|
+
query(q: string): Promise<Bundle[]>;
|
|
4
|
+
apply(rows: Bundle[]): Promise<{
|
|
5
|
+
bundles: Bundle[];
|
|
6
|
+
}>;
|
|
7
|
+
};
|
|
8
|
+
export type DraftIdentity = {
|
|
9
|
+
person?: string | null;
|
|
10
|
+
via?: string | null;
|
|
11
|
+
browsers?: string[];
|
|
12
|
+
};
|
|
13
|
+
export declare class DraftRefused extends Error {
|
|
14
|
+
}
|
|
15
|
+
type DraftRow = Bundle & {
|
|
16
|
+
draft: {
|
|
17
|
+
by?: string;
|
|
18
|
+
via?: string;
|
|
19
|
+
place: string;
|
|
20
|
+
text: string;
|
|
21
|
+
rev?: number;
|
|
22
|
+
};
|
|
23
|
+
created?: {
|
|
24
|
+
by?: string;
|
|
25
|
+
via?: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type DraftSnapshot = {
|
|
29
|
+
principal: string;
|
|
30
|
+
via?: string | null;
|
|
31
|
+
drafts: DraftRow[];
|
|
32
|
+
recover: string[];
|
|
33
|
+
};
|
|
34
|
+
export type DraftGateway = {
|
|
35
|
+
snapshot(): Promise<DraftSnapshot>;
|
|
36
|
+
write(value: Record<string, unknown>): Promise<{
|
|
37
|
+
bundles: Bundle[];
|
|
38
|
+
}>;
|
|
39
|
+
};
|
|
40
|
+
/** A private application's vouched draft door, using the same desk and merge
|
|
41
|
+
* protocol as a page whose graph is directly accessible. */ export declare let draftGateway: (db: DraftDoor, who: DraftIdentity) => DraftGateway;
|
|
42
|
+
//# sourceMappingURL=gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sources":["../gateway.ts"],"names":[],"mappings":"AAAA,SAAS,KAAK,MAAM,2BAAuC;AAI3D,YAAY;EACV,MAAM,GAAG,MAAM,GAAG,QAAQ;EAC1B,MAAM,MAAM,WAAW;IAAU,SAAS;;;AAE5C,YAAY;EACV,SAAS,MAAM,GAAG,IAAI;EACtB,MAAM,MAAM,GAAG,IAAI;EACnB,WAAW,MAAM;;AAEnB,OAAO,cAAM,qBAAqB;AAAO;KACpC,WAAW;EACd;IACE,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,OAAO,MAAM;IACb,MAAM,MAAM;IACZ,MAAM,MAAM;;EAEd;IAAY,KAAK,MAAM;IAAE,MAAM,MAAM;;;AAEvC,YAAY;EACV,WAAW,MAAM;EACjB,MAAM,MAAM,GAAG,IAAI;EACnB,QAAQ;EACR,SAAS,MAAM;;AAEjB,YAAY;EACV,YAAY,QAAQ;EACpB,MAAM,OAAO,OAAO,MAAM,EAAE,OAAO,IAAI;IAAU,SAAS;;;AAS5D;0DAC0D,GAC1D,OAAO,YAAI,eAAgB,IAAI,WAAW,KAAK,kBAAgB,aAqF9D"}
|
package/_dist/graph.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAIA,cAAc,MAAM,2BAAgC;AACpD,cAAc,KAAK,2BAAgC;AAGnD,qEAAqE,GACrE,OAAO,YAAI,UAAW;EAAa,OAAO;CAAO,KAAG,SAO5C"}
|
package/_dist/input.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Bundle } from "@yaks/graph";
|
|
2
|
+
import { type Client, type Drafts, type Stash } from "./desk.js";
|
|
3
|
+
export type DraftHost = {
|
|
4
|
+
client: Client;
|
|
5
|
+
by: () => string | undefined;
|
|
6
|
+
people: () => Promise<Bundle[]>;
|
|
7
|
+
stash: () => Stash | undefined;
|
|
8
|
+
};
|
|
9
|
+
/** Bind once before the interface reads or types a draft. */ export declare let configureDrafts: (value: DraftHost) => void;
|
|
10
|
+
/** A terminal without a client identity may type as the graph's lone person. */ export declare let lone: () => Promise<void>;
|
|
11
|
+
export declare let currentPerson: () => string | undefined;
|
|
12
|
+
/** The person's drafts, keyed by where they type. */ export declare let drafts: Drafts;
|
|
13
|
+
type Box = HTMLInputElement | HTMLTextAreaElement;
|
|
14
|
+
/** Mirror the durable draft into an uncontrolled Field; sending spends it
|
|
15
|
+
* atomically with the bundles its words became. */ export declare let useDraft: (key: string, ref: {
|
|
16
|
+
current: Box | null;
|
|
17
|
+
}, seed?: (v: string) => void) => {
|
|
18
|
+
text: string;
|
|
19
|
+
sync: (el: Box) => void;
|
|
20
|
+
spend: (also?: Bundle[]) => void | false | 0 | Promise<boolean>;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sources":["../input.ts"],"names":[],"mappings":"AAIA,cAAc,MAAM,2BAAgC;AACpD,SAAS,KAAK,MAAM,EAAQ,KAAK,MAAM,EAAE,KAAK,KAAK,oBAAmB;AAEtE,YAAY;EACV,QAAQ;EACR,UAAU,MAAM,GAAG,SAAS;EAC5B,cAAc,QAAQ;EACtB,aAAa,QAAQ,SAAS;;AAKhC,2DAA2D,GAC3D,OAAO,YAAI,kBAAmB,OAAO,cAAY,IAAI,CAIpD;AACD,8EAA8E,GAC9E,OAAO,YAAI,YAAW,QAAQ,IAAI,EAGd;AACpB,OAAO,YAAI,qBAAoB,MAAM,GAAG,SAAS,CAA4B;AAO7E,mDAAmD,GACnD,OAAO,YAAI,QAAQ,OAQlB;KAEI,MAAM,mBAAmB;AAC9B;iDACiD,GACjD,OAAO,YAAI,WACT,KAAK,MAAM,EACX;EAAO,SAAS,MAAM,IAAI;GAC1B,QAAQ,GAAG,MAAM,KAAK,IAAI;EAE1B,MAAM,MAAM;EACZ,OAAO,IAAI,QAAQ,IAAI;EACvB,QAAQ,OAAO,aAAa,IAAI,GAAG,KAAK,GAAG,IAAI,QAAQ,OAAO;EAkC/D"}
|
package/_dist/merge.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mine` and `theirs`, each typed over `base`, as one text keeping both.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { assertEquals } from '@std/assert'
|
|
6
|
+
* import { merge } from '@yaks/draft'
|
|
7
|
+
*
|
|
8
|
+
* assertEquals(merge('ship it', 'ship it now', 'Ship it'), 'Ship it now')
|
|
9
|
+
* assertEquals(merge('', 'a', 'b'), 'ab') // both typed at once: mine first
|
|
10
|
+
* assertEquals(merge('abc', 'aXc', 'aYc'), 'aXYc') // one span: both kept
|
|
11
|
+
* assertEquals(merge('', 'hello', 'hell'), 'hello') // typed on: taken once
|
|
12
|
+
* assertEquals(merge('a b', 'b', 'a b c'), 'b c') // a deletion holds
|
|
13
|
+
* ```
|
|
14
|
+
*/ export declare let merge: (base: string, mine: string, theirs: string) => string;
|
|
15
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sources":["../merge.ts"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,QAAS,MAAM,MAAM,EAAE,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,MAAM,CAqBtE"}
|
package/_dist/mod.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yaks/draft: what a person has typed and not yet sent. A draft is graph
|
|
3
|
+
* data, kept by the store like anything else, one per person and place, on an
|
|
4
|
+
* entity whose eid both derive (`draftEid`), so every interface the person
|
|
5
|
+
* uses (another tab, a terminal, another device) finds and shows the same one
|
|
6
|
+
* until it is sent or discarded, which empties its text in the journal, where
|
|
7
|
+
* it can be undone.
|
|
8
|
+
*
|
|
9
|
+
* - `draftDoc`, `docs`: `draft{by, via, place, text, rev}` and the `typed{over}`
|
|
10
|
+
* event (vocab.json).
|
|
11
|
+
* - `drafts()`: the plugin a store composes; its hook (`merging`) merges a
|
|
12
|
+
* write over what another interface wrote meanwhile (plugin.ts).
|
|
13
|
+
* - `merge(base, mine, theirs)`: two texts typed over one, made one, losing
|
|
14
|
+
* neither (merge.ts).
|
|
15
|
+
* - `desk(client, opts)`: an interface's drafts, typed into at once, kept
|
|
16
|
+
* across a reload, written to the store at a pace (desk.ts).
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/ export { docs, draftDoc } from "./vocab.js";
|
|
20
|
+
export { drafts, merging } from "./plugin.js";
|
|
21
|
+
export { merge } from "./merge.js";
|
|
22
|
+
export { type Client, desk, type DeskOpts, draftEid, type Drafts, type Stash } from "./desk.js";
|
|
23
|
+
export { type DraftDoor, draftGateway, type DraftIdentity, DraftRefused } from "./gateway.js";
|
|
24
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;CAkBC,GAED,SAAS,IAAI,EAAE,QAAQ,qBAAoB;AAC3C,SAAS,MAAM,EAAE,OAAO,sBAAqB;AAC7C,SAAS,KAAK,qBAAoB;AAClC,SACE,KAAK,MAAM,EACX,IAAI,EACJ,KAAK,QAAQ,EACb,QAAQ,EACR,KAAK,MAAM,EACX,KAAK,KAAK,oBACM;AAElB,SACE,KAAK,SAAS,EACd,YAAY,EACZ,KAAK,aAAa,EAClB,YAAY,uBACO"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Hook, Plugin } from "@yaks/graph";
|
|
2
|
+
/**
|
|
3
|
+
* The hook: each draft whose text is written is merged over what the store
|
|
4
|
+
* holds when it says what it was typed over, and counted.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { assertEquals } from '@std/assert'
|
|
8
|
+
* import { graph } from '@yaks/graph'
|
|
9
|
+
* import { ram } from '@yaks/ram'
|
|
10
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
11
|
+
* import { draftDoc, drafts } from '@yaks/draft'
|
|
12
|
+
*
|
|
13
|
+
* let vocab = loadVocab([draftDoc])
|
|
14
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins: [drafts()] })
|
|
15
|
+
* let write = (text: string, over: string) =>
|
|
16
|
+
* g.apply([{ entity: { eid: 'd' }, draft: { text }, typed: { over } }])
|
|
17
|
+
* await write('ship it', '')
|
|
18
|
+
* await write('ship it now', 'ship it') // one interface typed on
|
|
19
|
+
* await write('Ship it', 'ship it') // another, not having heard it
|
|
20
|
+
* let [d] = await g.get(['d'])
|
|
21
|
+
* assertEquals(d.draft, { text: 'Ship it now', rev: 3 })
|
|
22
|
+
* ```
|
|
23
|
+
*/ export declare let merging: Hook;
|
|
24
|
+
/**
|
|
25
|
+
* The draft plugin: `draft{by, place, text, rev}`, the `typed{over}` event,
|
|
26
|
+
* and {@link merging}. Compose it wherever drafts are stored: the server an
|
|
27
|
+
* interface writes to, or a page's own graph that keeps them itself.
|
|
28
|
+
*/ export declare let drafts: () => Plugin;
|
|
29
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sources":["../plugin.ts"],"names":[],"mappings":"AAaA,cAAsB,IAAI,EAAE,MAAM,2BAAgC;AAsBlE;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,YAAI,SAAS,KAkDnB;AAED;;;;CAIC,GACD,OAAO,YAAI,cAAa,OAOtB"}
|
package/_dist/vocab.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
/** The draft vocabulary: `draft{by, place, text, rev}` and the `typed{over}`
|
|
3
|
+
* event, in the form `loadVocab` accepts. */ export declare let draftDoc: VocabDoc;
|
|
4
|
+
/** What this package is: its manifest's description, the one place it is
|
|
5
|
+
* written, which a host stamps on each document here. */ export declare let description: string;
|
|
6
|
+
/** Every document this package declares. */ export declare let docs: VocabDoc[];
|
|
7
|
+
//# sourceMappingURL=vocab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,2BAAgC;AAItD;2CAC2C,GAC3C,OAAO,YAAI,UAAU,SAA0B;AAE/C;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,0CAA0C,GAC1C,OAAO,YAAI,MAAM,WAAuB"}
|