@open-artifact/editor-kit 0.0.0-stage → 0.1.0
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/NOTICE +5 -0
- package/README.md +128 -2
- package/package.json +58 -4
- package/src/Announcer.d.ts +2 -0
- package/src/Announcer.js +8 -0
- package/src/FindBar.d.ts +31 -0
- package/src/FindBar.js +34 -0
- package/src/agent.d.ts +20 -0
- package/src/agent.js +40 -0
- package/src/announce.d.ts +18 -0
- package/src/announce.js +21 -0
- package/src/chrome.d.ts +180 -0
- package/src/chrome.js +108 -0
- package/src/collab/CommentList.d.ts +23 -0
- package/src/collab/CommentList.js +117 -0
- package/src/collab/CommentViews.d.ts +116 -0
- package/src/collab/CommentViews.js +531 -0
- package/src/collab/HistoryViews.d.ts +38 -0
- package/src/collab/HistoryViews.js +103 -0
- package/src/collab/PresenceViews.d.ts +52 -0
- package/src/collab/PresenceViews.js +46 -0
- package/src/collab/cds/cds.d.ts +148 -0
- package/src/collab/cds/cds.js +230 -0
- package/src/collab/cds/comment-card.d.ts +93 -0
- package/src/collab/cds/comment-card.js +211 -0
- package/src/collab/cds/comment-composer.d.ts +28 -0
- package/src/collab/cds/comment-composer.js +101 -0
- package/src/collab/cds/comments-css.d.ts +2 -0
- package/src/collab/cds/comments-css.js +3 -0
- package/src/collab/cds/comments.css +497 -0
- package/src/collab/cds/edge-piles.d.ts +69 -0
- package/src/collab/cds/edge-piles.js +178 -0
- package/src/collab/cds/layer.d.ts +41 -0
- package/src/collab/cds/layer.js +143 -0
- package/src/collab/cds/markdown.d.ts +17 -0
- package/src/collab/cds/markdown.js +507 -0
- package/src/collab/cds/shield.d.ts +28 -0
- package/src/collab/cds/shield.js +114 -0
- package/src/collab/cds/time.d.ts +2 -0
- package/src/collab/cds/time.js +41 -0
- package/src/collab/collab.d.ts +100 -0
- package/src/collab/collab.js +119 -0
- package/src/collab/comments.d.ts +147 -0
- package/src/collab/comments.js +287 -0
- package/src/collab/history-wiring.d.ts +32 -0
- package/src/collab/history-wiring.js +53 -0
- package/src/collab/history.d.ts +53 -0
- package/src/collab/history.js +94 -0
- package/src/collab/peer-colors.d.ts +123 -0
- package/src/collab/peer-colors.js +273 -0
- package/src/collab/pins.d.ts +70 -0
- package/src/collab/pins.js +44 -0
- package/src/collab/presence.d.ts +92 -0
- package/src/collab/presence.js +158 -0
- package/src/design-systems.d.ts +46 -0
- package/src/design-systems.js +61 -0
- package/src/downloads.d.ts +24 -0
- package/src/downloads.js +36 -0
- package/src/find.d.ts +64 -0
- package/src/find.js +147 -0
- package/src/index.d.ts +25 -0
- package/src/index.js +25 -0
- package/src/keys.d.ts +13 -0
- package/src/keys.js +20 -0
- package/src/merge.d.ts +23 -0
- package/src/merge.js +116 -0
- package/src/page-link.d.ts +33 -0
- package/src/page-link.js +75 -0
- package/src/project-sync.d.ts +118 -0
- package/src/project-sync.js +174 -0
- package/src/react.d.ts +16 -0
- package/src/react.js +16 -0
- package/src/roles.d.ts +33 -0
- package/src/roles.js +26 -0
- package/src/session.d.ts +42 -0
- package/src/session.js +37 -0
- package/src/shell.d.ts +56 -0
- package/src/shell.js +96 -0
- package/src/stash.d.ts +26 -0
- package/src/stash.js +66 -0
- package/src/styles.css +17 -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 [yyyy] [name of copyright owner]
|
|
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/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,129 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @open-artifact/editor-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
What the artifact editors (`design-editor`, `slides-editor`,
|
|
4
|
+
`whiteboard-editor`, `design-system-editor`) share beyond the UI primitives of
|
|
5
|
+
`@open-artifact/ui`. It is private and is not built on its own: each editor's
|
|
6
|
+
Vite build compiles the sources it imports.
|
|
7
|
+
|
|
8
|
+
The kit holds behavior and views. Each editor keeps its document model and
|
|
9
|
+
stores, and connects them to the kit through a small **adapter**: an object of
|
|
10
|
+
callbacks the kit calls. The kit never imports an editor.
|
|
11
|
+
|
|
12
|
+
## Entries
|
|
13
|
+
|
|
14
|
+
| Import | What | Rules |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| `@open-artifact/editor-kit` | Pure modules: stores, controllers, helpers (`src/index.ts`) | `.ts` only. No React views, no `@open-artifact/ui`, lucide or Base UI. Loads in `node --test`. |
|
|
17
|
+
| `@open-artifact/editor-kit/react` | The shared views (`src/react.ts`) | May import `@open-artifact/ui`, React, lucide. |
|
|
18
|
+
| `@open-artifact/editor-kit/styles.css` | `@source "./"`, so Tailwind scans the kit for class names | Import it after the UI kit's sheet. |
|
|
19
|
+
|
|
20
|
+
`test/isolation.test.ts` enforces these rules: it checks every import in
|
|
21
|
+
`src/`, keeps the pure modules free of views, and loads the pure entry in
|
|
22
|
+
node.
|
|
23
|
+
|
|
24
|
+
## What lives where
|
|
25
|
+
|
|
26
|
+
Pure entry (`src/`):
|
|
27
|
+
|
|
28
|
+
| Module | Contents |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `collab/comments.ts` | `createComments(adapter)`: the comments store and actions (threads, drafts, replies, resolve, send to agent). |
|
|
31
|
+
| `collab/history.ts` | `createHistory(adapter)`: the version history store (list, preview, restore, notices). |
|
|
32
|
+
| `collab/history-wiring.ts` | `wireVersionHistory`, `readVersionFiles`: history over the `history` capability with a files store. |
|
|
33
|
+
| `collab/presence.ts` | `createPresence(adapter)`, peer colors (`PEER_COLORS`, `AGENT_COLOR`, `peerColor`), `peerValue`. |
|
|
34
|
+
| `collab/collab.ts` | `createCollab`: the glue between comments, history and the Shell (chrome report, commands, the right-hand panel, Esc and comment-mode keys). |
|
|
35
|
+
| `collab/pins.ts` | Camera math for comment pins and cards. |
|
|
36
|
+
| `merge.ts` | `mergeLines(base, ours, theirs, { adjacent })`: three-way line merge. `adjacent: 'conflict'` (slides) refuses changes on touching lines; the default `'merge'` (design system) takes both. |
|
|
37
|
+
| `find.ts` | `occurrences`, `excerpt`, `stepIndex`, `createFind(adapter)`, `highlightText`, `clearFindHighlights` (CSS Custom Highlight API). |
|
|
38
|
+
| `roles.ts` | `roleAbilities(role)`, `readOnlyLabel(role)`. |
|
|
39
|
+
| `session.ts` | `connectHost(names)`, `sessionSlot()`, `GUEST_VIEWER`, `artifactPath`, `projectPath`. |
|
|
40
|
+
| `shell.ts` | `agentChrome`, `chromeReporter` (deduped reports), `createShellBridge` (a bridge with a React hook for what the Shell draws). |
|
|
41
|
+
| `agent.ts` | `agentResultMessage(result, subject)`, `sendFailure`, `watchAgentStatus`. |
|
|
42
|
+
| `downloads.ts` | `saveFile` (host downloads, else the browser), `browserDownload`, `browserDownloadUrl`. |
|
|
43
|
+
| `design-systems.ts` | `createSystemsLoader(adapter)`: reads installed design systems under `project/ds/` and reloads them when they change. |
|
|
44
|
+
| `stash.ts` | `storedJson`, `stashFresh`, `STASH_KEEP_MS`, `normalizeJson`: recovery stashes in `localStorage`. |
|
|
45
|
+
| `page-link.ts` | `#page=` links and browser history for pages. |
|
|
46
|
+
| `announce.ts` | `announce(message)` for the screen reader live region. |
|
|
47
|
+
| `keys.ts` | `isApplePlatform`, `MOD`, `ALT`, `SHIFT`, `modKey`, `isTextField`. |
|
|
48
|
+
|
|
49
|
+
React entry: `CommentViews` (pins, capture, cards), `CommentList`,
|
|
50
|
+
`HistoryViews` (aside, preview bar), `PresenceViews` (avatars, cursors, peer
|
|
51
|
+
boxes), `Announcer`, `chrome.tsx` (`ChromeButton`, `ChromeMenu*`, `Card`,
|
|
52
|
+
`Tip`, `POPUP`…) and `FindBar`.
|
|
53
|
+
|
|
54
|
+
Token helpers for installed design systems (`styleDeclarations`, `styleTag`,
|
|
55
|
+
`installedKey`, `lengthPx`) live in `@open-artifact/design-system-core`
|
|
56
|
+
(`installed.ts`) because they describe the token format, not an editor.
|
|
57
|
+
|
|
58
|
+
## Adopting a module
|
|
59
|
+
|
|
60
|
+
1. Add `"@open-artifact/editor-kit": "0.1.0"` to the editor's `dependencies`
|
|
61
|
+
and run `npm install` (the workspace symlink resolves it; no Vite alias is
|
|
62
|
+
needed).
|
|
63
|
+
2. In the editor's `styles.css`, after `@import "@open-artifact/ui/styles.css";`,
|
|
64
|
+
add `@import "@open-artifact/editor-kit/styles.css";`. Define the chrome
|
|
65
|
+
tokens the shared views use in the editor's `@theme`: the colors
|
|
66
|
+
`--color-chrome`, `-fg`, `-muted`, `-accent`, `-hover`, `-line`,
|
|
67
|
+
`-pressed`, `-pressed-fg` and `-focus` (the focus outline), and the
|
|
68
|
+
shadows `--shadow-chrome` and `--shadow-chrome-popup`.
|
|
69
|
+
3. Write the adapter next to the editor's store, usually in
|
|
70
|
+
`src/services/<module>.ts`, and export what the rest of the editor uses
|
|
71
|
+
from there. Components import views from `/react`.
|
|
72
|
+
4. Delete the editor's own copy and its tests; the kit's tests cover the
|
|
73
|
+
shared part. Keep tests for what the adapter adds.
|
|
74
|
+
|
|
75
|
+
## Adapter contracts
|
|
76
|
+
|
|
77
|
+
- **`CommentsAdapter<A>`** (`A`: the editor's anchor). Required: `parse`,
|
|
78
|
+
`serialize`, `label`, `canComment`, `canSendToAgent`. Optional: `location`
|
|
79
|
+
(stored for the agent), `state` (`ok`/`moved`/`detached`/`orphaned`),
|
|
80
|
+
`stateNote`, `reveal`, `notify`, `agentName`, `onModeChange`, `noun`,
|
|
81
|
+
`maxThreads`.
|
|
82
|
+
- **`HistoryAdapter<P>`** (`P`: a loaded preview). `loadPreview(history, n)`
|
|
83
|
+
reads version `n`; optional `notify` and `noun`.
|
|
84
|
+
- **`PresenceAdapter<S>`** (`S`: what the editor publishes besides the
|
|
85
|
+
pointer). `key`, `snapshot`, `parse`, `watch(changed)` (returns an
|
|
86
|
+
unsubscribe), `pointer(event)` (world point or `null`), optional
|
|
87
|
+
`wrotePath`.
|
|
88
|
+
- **`createCollab({ comments, history, adapter })`**. `comments` and `history`
|
|
89
|
+
are a kit controller or an editor's own store of the same shape
|
|
90
|
+
(`CollabComments`, `CollabHistory`). `CollabAdapter`: `onSurface`,
|
|
91
|
+
`readOnly`, optional `showSurface`, `commentOnSelection` and `pageButton`.
|
|
92
|
+
- **`FindAdapter<M>`** (`M`: a match). `search(query)`, `reveal(match, index,
|
|
93
|
+
count)`, `onClose`, optional `start(matches)` and `noResults`. Stepping
|
|
94
|
+
searches again, so matches follow edits. For highlights, call
|
|
95
|
+
`highlightText(doc, root, query, ownerOf, occurrence)`; `ownerOf(parent)`
|
|
96
|
+
says which element owns a text node (its key and whether it is the current
|
|
97
|
+
match) or `null` to skip it.
|
|
98
|
+
- **`SystemsLoaderAdapter<R, S>`**. `artifact()`, `records()`,
|
|
99
|
+
`subscribe(listener)`, `read(record, tokens)` and `loaded(result)`. Call
|
|
100
|
+
`start()` once the session is connected. The loader reloads when the
|
|
101
|
+
installed records change or a copy's `tokens.json` changes, and drops reads
|
|
102
|
+
that a newer reload overtook.
|
|
103
|
+
- **Session**. `connectHost(['artifact', 'agent', …])` installs the page
|
|
104
|
+
provider, then connects the user, the named capabilities and the Shell, and
|
|
105
|
+
returns `{ viewer, abilities, shell, ...capabilities }`. Keep the result in
|
|
106
|
+
a `sessionSlot()`.
|
|
107
|
+
- **Shell**. Use `chromeReporter(shell, build)` when the editor subscribes
|
|
108
|
+
its own stores and handles commands itself (design, slides, design
|
|
109
|
+
system). Use `createShellBridge(() => shell)` when several modules
|
|
110
|
+
contribute parts of the report and register command handlers
|
|
111
|
+
(whiteboard).
|
|
112
|
+
- **Downloads**. `saveFile(downloads, name, blob)` returns `{ to: 'host' }`
|
|
113
|
+
or `{ to: 'browser' }`, so the editor can choose its toast.
|
|
114
|
+
|
|
115
|
+
## Left in the editors
|
|
116
|
+
|
|
117
|
+
These look alike but are not shared yet, because they depend on each
|
|
118
|
+
editor's document store, file kinds or look:
|
|
119
|
+
|
|
120
|
+
- `services/sync.ts` (the debounced publish, conflict merge and offline
|
|
121
|
+
retry). The loop has the same shape everywhere, but what is sent, how it is
|
|
122
|
+
acknowledged and when it saves again differ per store.
|
|
123
|
+
- Each editor's `systemFromTokens` and recovery banner.
|
|
124
|
+
- The whiteboard's chrome, find and announcer, and the slides comments
|
|
125
|
+
service. They have their own views and comment semantics.
|
|
126
|
+
- The design system's history and presence, and its markdown, live-props,
|
|
127
|
+
type and comment-anchor helpers. They have no second user yet.
|
|
128
|
+
|
|
129
|
+
Move one into the kit when a second editor needs the same thing.
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-artifact/editor-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "What every artifact editor shares: collaboration (comments, presence, history), roles and host session, Shell chrome reports, find, recovery stashes, line merge, announcements, chrome primitives and design-system loading.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./src/index.d.ts",
|
|
9
|
+
"default": "./src/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./react": {
|
|
12
|
+
"types": "./src/react.d.ts",
|
|
13
|
+
"default": "./src/react.js"
|
|
14
|
+
},
|
|
15
|
+
"./styles.css": "./src/styles.css",
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"src",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"NOTICE"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@base-ui/react": "^1.8.0",
|
|
25
|
+
"@open-artifact/design-system-core": "0.1.0",
|
|
26
|
+
"@open-artifact/runtime": "0.1.0",
|
|
27
|
+
"@open-artifact/ui": "0.1.0",
|
|
28
|
+
"clsx": "^2.1.1",
|
|
29
|
+
"lucide-react": "^1.65.0",
|
|
30
|
+
"zustand": "^5.0.10",
|
|
31
|
+
"@fontsource-variable/inter": "^5.3.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": "^19.2.4",
|
|
35
|
+
"react-dom": "^19.2.4",
|
|
36
|
+
"tailwindcss": "^4.3.3"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"tailwindcss": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"license": "Apache-2.0",
|
|
44
|
+
"author": {
|
|
45
|
+
"name": "Jim Liu 宝玉",
|
|
46
|
+
"url": "https://github.com/JimLiu"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/JimLiu/open-artifact#readme",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/JimLiu/open-artifact.git",
|
|
52
|
+
"directory": "packages/editor-kit"
|
|
53
|
+
},
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/JimLiu/open-artifact/issues"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/Announcer.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** The polite live region screen readers hear (`announce.ts`). Render it once per page. */
|
|
3
|
+
import { useAnnouncer } from "./announce.js";
|
|
4
|
+
export function Announcer() {
|
|
5
|
+
const message = useAnnouncer((s) => s.message);
|
|
6
|
+
const serial = useAnnouncer((s) => s.serial);
|
|
7
|
+
return (_jsx("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", className: "sr-only", style: { position: 'absolute', width: 1, height: 1, overflow: 'hidden', clip: 'rect(0 0 0 0)', whiteSpace: 'nowrap' }, children: _jsx("span", { children: message }, serial) }));
|
|
8
|
+
}
|
package/src/FindBar.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The find bar: a search field, "n of m", previous / next and close. Enter
|
|
3
|
+
* goes to the next match, ⇧Enter to the previous one, Escape closes. The
|
|
4
|
+
* editor renders it while find is open and passes its find store's state.
|
|
5
|
+
*/
|
|
6
|
+
import { type ReactNode } from 'react';
|
|
7
|
+
/** Props of {@link FindBar}. */
|
|
8
|
+
export interface FindBarProps {
|
|
9
|
+
/** Label and placeholder of the field ("Find in design"). */
|
|
10
|
+
label: string;
|
|
11
|
+
query: string;
|
|
12
|
+
count: number;
|
|
13
|
+
/** The match shown, or -1. */
|
|
14
|
+
index: number;
|
|
15
|
+
onQuery(query: string): void;
|
|
16
|
+
onStep(delta: 1 | -1): void;
|
|
17
|
+
onClose(): void;
|
|
18
|
+
/** A window event (⌘F while open) that focuses the field again. */
|
|
19
|
+
focusEvent: string;
|
|
20
|
+
/** Classes of the card (placement). */
|
|
21
|
+
className?: string;
|
|
22
|
+
/** Label of the close button (default "Close"). */
|
|
23
|
+
closeLabel?: string;
|
|
24
|
+
/** F3 / ⇧F3 step too. */
|
|
25
|
+
f3?: boolean;
|
|
26
|
+
/** Escape stops at the field (the editor's own Escape handling never sees it). */
|
|
27
|
+
stopEscape?: boolean;
|
|
28
|
+
/** Announce "n of m" through a polite live region. */
|
|
29
|
+
liveStatus?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function FindBar({ label, query, count, index, onQuery, onStep, onClose, focusEvent, className, closeLabel, f3, stopEscape, liveStatus }: FindBarProps): ReactNode;
|
package/src/FindBar.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The find bar: a search field, "n of m", previous / next and close. Enter
|
|
4
|
+
* goes to the next match, ⇧Enter to the previous one, Escape closes. The
|
|
5
|
+
* editor renders it while find is open and passes its find store's state.
|
|
6
|
+
*/
|
|
7
|
+
import { ChevronDown, ChevronUp, Search, X } from 'lucide-react';
|
|
8
|
+
import { useEffect, useRef } from 'react';
|
|
9
|
+
import { Card, ChromeButton, Tip } from "./chrome.js";
|
|
10
|
+
export function FindBar({ label, query, count, index, onQuery, onStep, onClose, focusEvent, className, closeLabel = 'Close', f3, stopEscape, liveStatus }) {
|
|
11
|
+
const input = useRef(null);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const focus = () => {
|
|
14
|
+
input.current?.focus();
|
|
15
|
+
input.current?.select();
|
|
16
|
+
};
|
|
17
|
+
focus();
|
|
18
|
+
window.addEventListener(focusEvent, focus);
|
|
19
|
+
return () => window.removeEventListener(focusEvent, focus);
|
|
20
|
+
}, [focusEvent]);
|
|
21
|
+
const status = !query.trim() ? '' : count === 0 ? 'No results' : `${index + 1} of ${count}`;
|
|
22
|
+
return (_jsxs(Card, { role: "search", className: className, children: [_jsx(Search, { className: "size-4 shrink-0 text-chrome-muted", strokeWidth: 1.5 }), _jsx("input", { ref: input, "aria-label": label, placeholder: label, value: query, className: "w-48 bg-transparent text-[13px] text-chrome-fg outline-none placeholder:text-chrome-muted", onChange: (event) => onQuery(event.target.value), onKeyDown: (event) => {
|
|
23
|
+
if (event.key === 'Enter' || (f3 && event.key === 'F3')) {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
onStep(event.shiftKey ? -1 : 1);
|
|
26
|
+
}
|
|
27
|
+
else if (event.key === 'Escape') {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
if (stopEscape)
|
|
30
|
+
event.stopPropagation();
|
|
31
|
+
onClose();
|
|
32
|
+
}
|
|
33
|
+
} }), _jsx("span", { "aria-live": liveStatus ? 'polite' : undefined, className: "min-w-14 text-right text-[12px] tabular-nums text-chrome-muted", children: status }), _jsx(Tip, { label: "Previous match", shortcut: "\u21E7\u21B5", children: _jsx(ChromeButton, { square: true, "aria-label": "Previous match", disabled: count === 0, onClick: () => onStep(-1), children: _jsx(ChevronUp, { className: "size-4", strokeWidth: 1.5 }) }) }), _jsx(Tip, { label: "Next match", shortcut: "\u21B5", children: _jsx(ChromeButton, { square: true, "aria-label": "Next match", disabled: count === 0, onClick: () => onStep(1), children: _jsx(ChevronDown, { className: "size-4", strokeWidth: 1.5 }) }) }), _jsx(Tip, { label: "Close", shortcut: "Esc", children: _jsx(ChromeButton, { square: true, "aria-label": closeLabel, onClick: onClose, children: _jsx(X, { className: "size-4", strokeWidth: 1.5 }) }) })] }));
|
|
34
|
+
}
|
package/src/agent.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent's side of every editor: following its status, and telling the
|
|
3
|
+
* person how the host took a request ("Send to agent", "Ask agent to fix").
|
|
4
|
+
* Pure; the editor shows the message (a toast).
|
|
5
|
+
*/
|
|
6
|
+
import type { AgentCapability, AgentSendResult, AgentStatus } from '@open-artifact/runtime';
|
|
7
|
+
/** A message for the person. */
|
|
8
|
+
export interface AgentResultMessage {
|
|
9
|
+
title: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* How the host took a request, for a toast. `subject` names what the agent
|
|
14
|
+
* checks next ("this design", "this deck", "this board").
|
|
15
|
+
*/
|
|
16
|
+
export declare function agentResultMessage(result: AgentSendResult, subject: string): AgentResultMessage;
|
|
17
|
+
/** A failed send result for an error thrown while sending. */
|
|
18
|
+
export declare function sendFailure(error: unknown): AgentSendResult;
|
|
19
|
+
/** Follows the agent's status (none without an agent); returns a function that stops. */
|
|
20
|
+
export declare function watchAgentStatus(agent: AgentCapability | null | undefined, onStatus: (status: AgentStatus) => void): () => void;
|
package/src/agent.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent's side of every editor: following its status, and telling the
|
|
3
|
+
* person how the host took a request ("Send to agent", "Ask agent to fix").
|
|
4
|
+
* Pure; the editor shows the message (a toast).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* How the host took a request, for a toast. `subject` names what the agent
|
|
8
|
+
* checks next ("this design", "this deck", "this board").
|
|
9
|
+
*/
|
|
10
|
+
export function agentResultMessage(result, subject) {
|
|
11
|
+
switch (result.status) {
|
|
12
|
+
case 'delivered':
|
|
13
|
+
return { title: 'Sent to the agent' };
|
|
14
|
+
case 'queued':
|
|
15
|
+
return { title: 'Queued for the agent', description: `It will see the request the next time it checks ${subject}.` };
|
|
16
|
+
case 'staged':
|
|
17
|
+
return { title: 'Request prepared', description: 'Your agent will ask before acting on it.' };
|
|
18
|
+
default:
|
|
19
|
+
return { title: 'Could not reach the agent', description: result.reason ?? 'Try again, or copy your request into the conversation.' };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** A failed send result for an error thrown while sending. */
|
|
23
|
+
export function sendFailure(error) {
|
|
24
|
+
return { status: 'failed', reason: error instanceof Error ? error.message : String(error) };
|
|
25
|
+
}
|
|
26
|
+
/** Follows the agent's status (none without an agent); returns a function that stops. */
|
|
27
|
+
export function watchAgentStatus(agent, onStatus) {
|
|
28
|
+
if (!agent)
|
|
29
|
+
return () => { };
|
|
30
|
+
let stopped = false;
|
|
31
|
+
agent.status().then((status) => {
|
|
32
|
+
if (!stopped)
|
|
33
|
+
onStatus(status);
|
|
34
|
+
}, () => undefined);
|
|
35
|
+
const off = agent.onStatus(onStatus);
|
|
36
|
+
return () => {
|
|
37
|
+
stopped = true;
|
|
38
|
+
off();
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The screen-reader announcer core, free of any editor store: a polite live
|
|
3
|
+
* region's message and a serial. {@link announce} queues a message; a
|
|
4
|
+
* component renders `useAnnouncer` in a `role="status"` region (see
|
|
5
|
+
* `Announcer.tsx`). Repeating the same message re-announces it.
|
|
6
|
+
*/
|
|
7
|
+
/** Longest message read out (longer ones are cut). */
|
|
8
|
+
export declare const ANNOUNCE_LIMIT = 200;
|
|
9
|
+
export interface AnnouncerState {
|
|
10
|
+
message: string;
|
|
11
|
+
/** Bumped per announcement, so the same text is read again. */
|
|
12
|
+
serial: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const useAnnouncer: import("zustand").UseBoundStore<import("zustand").StoreApi<AnnouncerState>>;
|
|
15
|
+
/** The text read out for a message (whitespace collapsed, cut to {@link ANNOUNCE_LIMIT}); empty: nothing. */
|
|
16
|
+
export declare function announcementText(message: string): string;
|
|
17
|
+
/** Reads a message out to screen readers. */
|
|
18
|
+
export declare function announce(message: string): void;
|
package/src/announce.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The screen-reader announcer core, free of any editor store: a polite live
|
|
3
|
+
* region's message and a serial. {@link announce} queues a message; a
|
|
4
|
+
* component renders `useAnnouncer` in a `role="status"` region (see
|
|
5
|
+
* `Announcer.tsx`). Repeating the same message re-announces it.
|
|
6
|
+
*/
|
|
7
|
+
import { create } from 'zustand';
|
|
8
|
+
/** Longest message read out (longer ones are cut). */
|
|
9
|
+
export const ANNOUNCE_LIMIT = 200;
|
|
10
|
+
export const useAnnouncer = create()(() => ({ message: '', serial: 0 }));
|
|
11
|
+
/** The text read out for a message (whitespace collapsed, cut to {@link ANNOUNCE_LIMIT}); empty: nothing. */
|
|
12
|
+
export function announcementText(message) {
|
|
13
|
+
const text = message.replace(/\s+/g, ' ').trim();
|
|
14
|
+
return text.length > ANNOUNCE_LIMIT ? `${text.slice(0, ANNOUNCE_LIMIT - 1)}…` : text;
|
|
15
|
+
}
|
|
16
|
+
/** Reads a message out to screen readers. */
|
|
17
|
+
export function announce(message) {
|
|
18
|
+
const text = announcementText(message);
|
|
19
|
+
if (text)
|
|
20
|
+
useAnnouncer.setState((s) => ({ message: text, serial: s.serial + 1 }));
|
|
21
|
+
}
|