@open-artifact/editor-kit 0.11.0 → 0.12.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/package.json +4 -4
- package/src/announce.d.ts +5 -2
- package/src/announce.js +13 -3
- package/src/file-drop.d.ts +33 -0
- package/src/file-drop.js +36 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-artifact/editor-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
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
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@base-ui/react": "^1.8.0",
|
|
25
|
-
"@open-artifact/design-system-core": "0.
|
|
26
|
-
"@open-artifact/runtime": "0.
|
|
27
|
-
"@open-artifact/ui": "0.
|
|
25
|
+
"@open-artifact/design-system-core": "0.12.0",
|
|
26
|
+
"@open-artifact/runtime": "0.12.0",
|
|
27
|
+
"@open-artifact/ui": "0.12.0",
|
|
28
28
|
"clsx": "^2.1.1",
|
|
29
29
|
"lucide-react": "^1.65.0",
|
|
30
30
|
"zustand": "^5.0.10",
|
package/src/announce.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* component renders `useAnnouncer` in a `role="status"` region (see
|
|
5
5
|
* `Announcer.tsx`). Repeating the same message re-announces it.
|
|
6
6
|
*/
|
|
7
|
-
/** Longest message read out (longer ones are cut). */
|
|
7
|
+
/** Longest message read out (longer ones are cut, at a word where they can be). */
|
|
8
8
|
export declare const ANNOUNCE_LIMIT = 200;
|
|
9
9
|
export interface AnnouncerState {
|
|
10
10
|
message: string;
|
|
@@ -12,7 +12,10 @@ export interface AnnouncerState {
|
|
|
12
12
|
serial: number;
|
|
13
13
|
}
|
|
14
14
|
export declare const useAnnouncer: import("zustand").UseBoundStore<import("zustand").StoreApi<AnnouncerState>>;
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The text read out for a message, whitespace collapsed; empty: nothing. Past {@link ANNOUNCE_LIMIT} it is cut at the
|
|
17
|
+
* last word break within that many characters, or mid-word when that break comes early, and ends with an ellipsis.
|
|
18
|
+
*/
|
|
16
19
|
export declare function announcementText(message: string): string;
|
|
17
20
|
/** Reads a message out to screen readers. */
|
|
18
21
|
export declare function announce(message: string): void;
|
package/src/announce.js
CHANGED
|
@@ -5,13 +5,23 @@
|
|
|
5
5
|
* `Announcer.tsx`). Repeating the same message re-announces it.
|
|
6
6
|
*/
|
|
7
7
|
import { create } from 'zustand';
|
|
8
|
-
/** Longest message read out (longer ones are cut). */
|
|
8
|
+
/** Longest message read out (longer ones are cut, at a word where they can be). */
|
|
9
9
|
export const ANNOUNCE_LIMIT = 200;
|
|
10
|
+
/** A cut at a word keeps at least this many characters; one that would keep fewer cuts at the limit instead. */
|
|
11
|
+
const SHORTEST_WORD_CUT = 119;
|
|
10
12
|
export const useAnnouncer = create()(() => ({ message: '', serial: 0 }));
|
|
11
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* The text read out for a message, whitespace collapsed; empty: nothing. Past {@link ANNOUNCE_LIMIT} it is cut at the
|
|
15
|
+
* last word break within that many characters, or mid-word when that break comes early, and ends with an ellipsis.
|
|
16
|
+
*/
|
|
12
17
|
export function announcementText(message) {
|
|
13
18
|
const text = message.replace(/\s+/g, ' ').trim();
|
|
14
|
-
|
|
19
|
+
if (text.length <= ANNOUNCE_LIMIT)
|
|
20
|
+
return text;
|
|
21
|
+
const wordBreak = text.slice(0, ANNOUNCE_LIMIT).search(/\s+\S*$/);
|
|
22
|
+
// A cut mid-word leaves room for the ellipsis and no half of a surrogate pair.
|
|
23
|
+
const kept = wordBreak >= SHORTEST_WORD_CUT ? text.slice(0, wordBreak) : text.slice(0, ANNOUNCE_LIMIT - 1).replace(/[\uD800-\uDBFF]$/, '');
|
|
24
|
+
return `${kept}…`;
|
|
15
25
|
}
|
|
16
26
|
/** Reads a message out to screen readers. */
|
|
17
27
|
export function announce(message) {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file dropped where nothing takes it (a read-only canvas, panels, toolbars)
|
|
3
|
+
* would make the browser open the file in place of the editor. This guard
|
|
4
|
+
* swallows such drops; a handler that takes the drop has already prevented its
|
|
5
|
+
* default, and an enabled file input keeps its own drop.
|
|
6
|
+
*/
|
|
7
|
+
/** Minimal shape of a drag event target, so the guard runs without a DOM. */
|
|
8
|
+
export interface FileDropTarget {
|
|
9
|
+
readonly tagName?: string;
|
|
10
|
+
readonly type?: string;
|
|
11
|
+
readonly disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** The parts of a drag event the guard reads. */
|
|
14
|
+
export interface FileDragEvent {
|
|
15
|
+
readonly type: string;
|
|
16
|
+
readonly defaultPrevented: boolean;
|
|
17
|
+
readonly target?: EventTarget | FileDropTarget | null;
|
|
18
|
+
readonly dataTransfer: {
|
|
19
|
+
types: ArrayLike<string> | Iterable<string>;
|
|
20
|
+
dropEffect: string;
|
|
21
|
+
} | null;
|
|
22
|
+
composedPath?(): readonly unknown[];
|
|
23
|
+
preventDefault(): void;
|
|
24
|
+
}
|
|
25
|
+
/** The parts of a window the guard listens on. */
|
|
26
|
+
export interface FileDropWindow {
|
|
27
|
+
addEventListener(type: 'dragover' | 'drop', listener: (event: FileDragEvent) => void): void;
|
|
28
|
+
removeEventListener(type: 'dragover' | 'drop', listener: (event: FileDragEvent) => void): void;
|
|
29
|
+
}
|
|
30
|
+
/** True when the drag carries files from outside the page. */
|
|
31
|
+
export declare function carriesFiles(event: FileDragEvent): boolean;
|
|
32
|
+
/** Installs the guard; returns a function that removes it. */
|
|
33
|
+
export declare function guardFileDrops(win: FileDropWindow): () => void;
|
package/src/file-drop.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file dropped where nothing takes it (a read-only canvas, panels, toolbars)
|
|
3
|
+
* would make the browser open the file in place of the editor. This guard
|
|
4
|
+
* swallows such drops; a handler that takes the drop has already prevented its
|
|
5
|
+
* default, and an enabled file input keeps its own drop.
|
|
6
|
+
*/
|
|
7
|
+
/** True when the drag carries files from outside the page. */
|
|
8
|
+
export function carriesFiles(event) {
|
|
9
|
+
return Array.from(event.dataTransfer?.types ?? []).includes('Files');
|
|
10
|
+
}
|
|
11
|
+
function isEnabledFileInput(node) {
|
|
12
|
+
if (typeof node !== 'object' || node === null)
|
|
13
|
+
return false;
|
|
14
|
+
const target = node;
|
|
15
|
+
return typeof target.tagName === 'string' && target.tagName.toLowerCase() === 'input' && target.type === 'file' && target.disabled !== true;
|
|
16
|
+
}
|
|
17
|
+
function landsOnFileInput(event) {
|
|
18
|
+
const first = event.composedPath?.()[0] ?? event.target ?? null;
|
|
19
|
+
return isEnabledFileInput(first);
|
|
20
|
+
}
|
|
21
|
+
/** Installs the guard; returns a function that removes it. */
|
|
22
|
+
export function guardFileDrops(win) {
|
|
23
|
+
const guard = (event) => {
|
|
24
|
+
if (event.defaultPrevented || !carriesFiles(event) || landsOnFileInput(event))
|
|
25
|
+
return;
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
if (event.type === 'dragover' && event.dataTransfer)
|
|
28
|
+
event.dataTransfer.dropEffect = 'none';
|
|
29
|
+
};
|
|
30
|
+
win.addEventListener('dragover', guard);
|
|
31
|
+
win.addEventListener('drop', guard);
|
|
32
|
+
return () => {
|
|
33
|
+
win.removeEventListener('dragover', guard);
|
|
34
|
+
win.removeEventListener('drop', guard);
|
|
35
|
+
};
|
|
36
|
+
}
|
package/src/index.d.ts
CHANGED