@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/src/stash.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unsaved-work recovery, the shared part: while edits wait to be saved, an
|
|
3
|
+
* editor copies what differs from the saved files to `localStorage` (a
|
|
4
|
+
* "stash"); if the tab closes before the save lands, the next visit offers
|
|
5
|
+
* it back. What a stash holds and how it is restored is the editor's; this
|
|
6
|
+
* module keeps the storage guarded, the age limit and the debounce.
|
|
7
|
+
*/
|
|
8
|
+
/** How long a stash is kept, ms (three days). */
|
|
9
|
+
export const STASH_KEEP_MS = 3 * 24 * 60 * 60 * 1000;
|
|
10
|
+
/** True while a stash written at `at` may still be offered (not too old, not from the future). */
|
|
11
|
+
export function stashFresh(at, now) {
|
|
12
|
+
return now - at <= STASH_KEEP_MS && at <= now + 60_000;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A JSON value stored under `key` (e.g. `open-artifact-design:recovery:<path>`).
|
|
16
|
+
* `parse` validates what is read back (`null`: unusable). Storage that is
|
|
17
|
+
* missing, full or blocked reads as empty and ignores writes.
|
|
18
|
+
*/
|
|
19
|
+
export function storedJson(key, parse, storage = () => globalThis.localStorage) {
|
|
20
|
+
const clear = () => {
|
|
21
|
+
try {
|
|
22
|
+
storage()?.removeItem(key);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Unavailable: nothing to clear.
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
read() {
|
|
30
|
+
try {
|
|
31
|
+
const raw = storage()?.getItem(key);
|
|
32
|
+
return raw ? parse(JSON.parse(raw)) : null;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
write(value) {
|
|
39
|
+
if (value === null)
|
|
40
|
+
return clear();
|
|
41
|
+
try {
|
|
42
|
+
storage()?.setItem(key, JSON.stringify(value));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Full or unavailable: recovery is best effort.
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
clear,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** JSON compared by value (key order and spacing aside), text otherwise. */
|
|
52
|
+
export function normalizeJson(text) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.stringify(sortKeys(JSON.parse(text)));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return text;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function sortKeys(value) {
|
|
61
|
+
if (Array.isArray(value))
|
|
62
|
+
return value.map(sortKeys);
|
|
63
|
+
if (value && typeof value === 'object')
|
|
64
|
+
return Object.fromEntries(Object.keys(value).sort().map((k) => [k, sortKeys(value[k])]));
|
|
65
|
+
return value;
|
|
66
|
+
}
|
package/src/styles.css
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* The comments layer's font: Inter (SIL Open Font License 1.1). Declared on the page, since a shadow root ignores @font-face. */
|
|
2
|
+
@import "@fontsource-variable/inter/wght.css";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Editors import this after the UI kit's sheet, so Tailwind scans the
|
|
6
|
+
* kit's components for class names:
|
|
7
|
+
*
|
|
8
|
+
* @import "@open-artifact/ui/styles.css";
|
|
9
|
+
* @import "@open-artifact/editor-kit/styles.css";
|
|
10
|
+
*
|
|
11
|
+
* The chrome components use the editor's chrome tokens (`bg-chrome`,
|
|
12
|
+
* `text-chrome-fg`, `shadow-chrome`, `outline-chrome-focus`…), which each
|
|
13
|
+
* editor defines in its own `@theme`.
|
|
14
|
+
*/
|
|
15
|
+
@source "./";
|
|
16
|
+
/* The comment components draw in a shadow root with their own stylesheet (collab/cds/comments.css). */
|
|
17
|
+
@source not "./collab/cds";
|