@zsherman/canvas 0.0.0-stage → 0.1.1
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/CHANGELOG.md +24 -0
- package/LICENSE +373 -0
- package/README.md +15 -2
- package/THIRD_PARTY_NOTICES.md +117 -0
- package/dist/dom/canvas/assets.js +89 -0
- package/dist/dom/canvas/board-store.js +56 -0
- package/dist/dom/canvas/canvas-actions.js +78 -0
- package/dist/dom/canvas/canvas-board.js +557 -0
- package/dist/dom/canvas/canvas-board.styles.js +110 -0
- package/dist/dom/canvas/canvas-chrome.js +1167 -0
- package/dist/dom/canvas/canvas-chrome.styles.js +220 -0
- package/dist/dom/canvas/canvas-comments.js +950 -0
- package/dist/dom/canvas/canvas-comments.styles.js +231 -0
- package/dist/dom/canvas/canvas-context.js +196 -0
- package/dist/dom/canvas/canvas-controller.js +697 -0
- package/dist/dom/canvas/canvas-cursor-chat.js +120 -0
- package/dist/dom/canvas/canvas-cursor-chat.styles.js +55 -0
- package/dist/dom/canvas/canvas-menus.js +276 -0
- package/dist/dom/canvas/canvas-menus.styles.js +7 -0
- package/dist/dom/canvas/canvas-style-bar.js +930 -0
- package/dist/dom/canvas/canvas-style-bar.styles.js +52 -0
- package/dist/dom/canvas/canvas-surface.js +1354 -0
- package/dist/dom/canvas/canvas-surface.styles.js +345 -0
- package/dist/dom/canvas/canvas-tool-rail.js +406 -0
- package/dist/dom/canvas/canvas-tool-rail.styles.js +20 -0
- package/dist/dom/canvas/comments.js +58 -0
- package/dist/dom/canvas/equality.js +13 -0
- package/dist/dom/canvas/export-png.js +496 -0
- package/dist/dom/canvas/gesture-machine.js +91 -0
- package/dist/dom/canvas/handlers.js +18 -0
- package/dist/dom/canvas/index.js +9 -0
- package/dist/dom/canvas/input.js +85 -0
- package/dist/dom/canvas/instant.js +28 -0
- package/dist/dom/canvas/kernel.js +39 -0
- package/dist/dom/canvas/motion.js +686 -0
- package/dist/dom/canvas/palette.js +165 -0
- package/dist/dom/canvas/random-id.js +15 -0
- package/dist/dom/canvas/scene-renderer.js +559 -0
- package/dist/dom/canvas/scene.styles.js +7 -0
- package/dist/dom/canvas/surface-model.js +324 -0
- package/dist/dom/canvas/uploads.js +294 -0
- package/dist/dom/index.js +9 -0
- package/dist/dom/kernel/actions.js +455 -0
- package/dist/dom/kernel/board.js +856 -0
- package/dist/dom/kernel/claims.js +40 -0
- package/dist/dom/kernel/clipboard.js +30 -0
- package/dist/dom/kernel/constants.js +210 -0
- package/dist/dom/kernel/contract.js +0 -0
- package/dist/dom/kernel/decode.js +85 -0
- package/dist/dom/kernel/editor.js +2077 -0
- package/dist/dom/kernel/errors.js +82 -0
- package/dist/dom/kernel/fonts/inter.js +7924 -0
- package/dist/dom/kernel/fractional-index.js +54 -0
- package/dist/dom/kernel/geometry.js +123 -0
- package/dist/dom/kernel/hit-test.js +156 -0
- package/dist/dom/kernel/index.js +22 -0
- package/dist/dom/kernel/inspect.js +116 -0
- package/dist/dom/kernel/kernel.js +251 -0
- package/dist/dom/kernel/outline.js +64 -0
- package/dist/dom/kernel/plan.js +1370 -0
- package/dist/dom/kernel/rev.js +173 -0
- package/dist/dom/kernel/scene.js +580 -0
- package/dist/dom/kernel/schema.js +1109 -0
- package/dist/dom/kernel/snap.js +258 -0
- package/dist/dom/kernel/svg.js +148 -0
- package/dist/dom/kernel/text.js +142 -0
- package/dist/solid/canvas/assets.jsx +89 -0
- package/dist/solid/canvas/board-store.jsx +56 -0
- package/dist/solid/canvas/canvas-actions.jsx +78 -0
- package/dist/solid/canvas/canvas-board.jsx +326 -0
- package/dist/solid/canvas/canvas-board.styles.jsx +110 -0
- package/dist/solid/canvas/canvas-chrome.jsx +612 -0
- package/dist/solid/canvas/canvas-chrome.styles.jsx +220 -0
- package/dist/solid/canvas/canvas-comments.jsx +435 -0
- package/dist/solid/canvas/canvas-comments.styles.jsx +231 -0
- package/dist/solid/canvas/canvas-context.jsx +174 -0
- package/dist/solid/canvas/canvas-controller.jsx +697 -0
- package/dist/solid/canvas/canvas-cursor-chat.jsx +87 -0
- package/dist/solid/canvas/canvas-cursor-chat.styles.jsx +55 -0
- package/dist/solid/canvas/canvas-menus.jsx +223 -0
- package/dist/solid/canvas/canvas-menus.styles.jsx +7 -0
- package/dist/solid/canvas/canvas-style-bar.jsx +486 -0
- package/dist/solid/canvas/canvas-style-bar.styles.jsx +52 -0
- package/dist/solid/canvas/canvas-surface.jsx +681 -0
- package/dist/solid/canvas/canvas-surface.styles.jsx +345 -0
- package/dist/solid/canvas/canvas-tool-rail.jsx +195 -0
- package/dist/solid/canvas/canvas-tool-rail.styles.jsx +20 -0
- package/dist/solid/canvas/comments.jsx +58 -0
- package/dist/solid/canvas/equality.jsx +13 -0
- package/dist/solid/canvas/export-png.jsx +496 -0
- package/dist/solid/canvas/gesture-machine.jsx +91 -0
- package/dist/solid/canvas/handlers.jsx +18 -0
- package/dist/solid/canvas/index.jsx +9 -0
- package/dist/solid/canvas/input.jsx +85 -0
- package/dist/solid/canvas/instant.jsx +28 -0
- package/dist/solid/canvas/kernel.jsx +39 -0
- package/dist/solid/canvas/motion.jsx +686 -0
- package/dist/solid/canvas/palette.jsx +165 -0
- package/dist/solid/canvas/random-id.jsx +15 -0
- package/dist/solid/canvas/scene-renderer.jsx +559 -0
- package/dist/solid/canvas/scene.styles.jsx +7 -0
- package/dist/solid/canvas/surface-model.jsx +324 -0
- package/dist/solid/canvas/uploads.jsx +294 -0
- package/dist/solid/index.jsx +9 -0
- package/dist/solid/kernel/actions.jsx +455 -0
- package/dist/solid/kernel/board.jsx +856 -0
- package/dist/solid/kernel/claims.jsx +40 -0
- package/dist/solid/kernel/clipboard.jsx +30 -0
- package/dist/solid/kernel/constants.jsx +210 -0
- package/dist/solid/kernel/contract.jsx +0 -0
- package/dist/solid/kernel/decode.jsx +85 -0
- package/dist/solid/kernel/editor.jsx +2077 -0
- package/dist/solid/kernel/errors.jsx +82 -0
- package/dist/solid/kernel/fonts/inter.jsx +7924 -0
- package/dist/solid/kernel/fractional-index.jsx +54 -0
- package/dist/solid/kernel/geometry.jsx +123 -0
- package/dist/solid/kernel/hit-test.jsx +156 -0
- package/dist/solid/kernel/index.jsx +22 -0
- package/dist/solid/kernel/inspect.jsx +116 -0
- package/dist/solid/kernel/kernel.jsx +251 -0
- package/dist/solid/kernel/outline.jsx +64 -0
- package/dist/solid/kernel/plan.jsx +1370 -0
- package/dist/solid/kernel/rev.jsx +173 -0
- package/dist/solid/kernel/scene.jsx +580 -0
- package/dist/solid/kernel/schema.jsx +1109 -0
- package/dist/solid/kernel/snap.jsx +258 -0
- package/dist/solid/kernel/svg.jsx +148 -0
- package/dist/solid/kernel/text.jsx +142 -0
- package/dist/styles.css +1 -0
- package/dist/types/canvas/assets.d.ts +111 -0
- package/dist/types/canvas/board-store.d.ts +86 -0
- package/dist/types/canvas/canvas-actions.d.ts +21 -0
- package/dist/types/canvas/canvas-board.d.ts +53 -0
- package/dist/types/canvas/canvas-board.styles.d.ts +94 -0
- package/dist/types/canvas/canvas-chrome.d.ts +109 -0
- package/dist/types/canvas/canvas-chrome.styles.d.ts +193 -0
- package/dist/types/canvas/canvas-comments.d.ts +20 -0
- package/dist/types/canvas/canvas-comments.styles.d.ts +208 -0
- package/dist/types/canvas/canvas-context.d.ts +104 -0
- package/dist/types/canvas/canvas-controller.d.ts +159 -0
- package/dist/types/canvas/canvas-cursor-chat.d.ts +13 -0
- package/dist/types/canvas/canvas-cursor-chat.styles.d.ts +54 -0
- package/dist/types/canvas/canvas-menus.d.ts +21 -0
- package/dist/types/canvas/canvas-menus.styles.d.ts +6 -0
- package/dist/types/canvas/canvas-style-bar.d.ts +19 -0
- package/dist/types/canvas/canvas-style-bar.styles.d.ts +43 -0
- package/dist/types/canvas/canvas-surface.d.ts +15 -0
- package/dist/types/canvas/canvas-surface.styles.d.ts +313 -0
- package/dist/types/canvas/canvas-tool-rail.d.ts +41 -0
- package/dist/types/canvas/canvas-tool-rail.styles.d.ts +15 -0
- package/dist/types/canvas/comments.d.ts +106 -0
- package/dist/types/canvas/equality.d.ts +4 -0
- package/dist/types/canvas/export-png.d.ts +77 -0
- package/dist/types/canvas/gesture-machine.d.ts +46 -0
- package/dist/types/canvas/handlers.d.ts +7 -0
- package/dist/types/canvas/index.d.ts +18 -0
- package/dist/types/canvas/input.d.ts +63 -0
- package/dist/types/canvas/instant.d.ts +13 -0
- package/dist/types/canvas/kernel.d.ts +27 -0
- package/dist/types/canvas/motion.d.ts +72 -0
- package/dist/types/canvas/palette.d.ts +46 -0
- package/dist/types/canvas/random-id.d.ts +6 -0
- package/dist/types/canvas/scene-renderer.d.ts +27 -0
- package/dist/types/canvas/scene.styles.d.ts +4 -0
- package/dist/types/canvas/surface-model.d.ts +113 -0
- package/dist/types/canvas/uploads.d.ts +58 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/kernel/actions.d.ts +19 -0
- package/dist/types/kernel/board.d.ts +137 -0
- package/dist/types/kernel/claims.d.ts +29 -0
- package/dist/types/kernel/clipboard.d.ts +10 -0
- package/dist/types/kernel/constants.d.ts +195 -0
- package/dist/types/kernel/contract.d.ts +1533 -0
- package/dist/types/kernel/decode.d.ts +60 -0
- package/dist/types/kernel/editor.d.ts +12 -0
- package/dist/types/kernel/errors.d.ts +11 -0
- package/dist/types/kernel/fractional-index.d.ts +7 -0
- package/dist/types/kernel/geometry.d.ts +42 -0
- package/dist/types/kernel/hit-test.d.ts +16 -0
- package/dist/types/kernel/index.d.ts +8 -0
- package/dist/types/kernel/inspect.d.ts +6 -0
- package/dist/types/kernel/kernel.d.ts +6 -0
- package/dist/types/kernel/outline.d.ts +4 -0
- package/dist/types/kernel/plan.d.ts +20 -0
- package/dist/types/kernel/rev.d.ts +21 -0
- package/dist/types/kernel/scene.d.ts +16 -0
- package/dist/types/kernel/schema.d.ts +3436 -0
- package/dist/types/kernel/snap.d.ts +41 -0
- package/dist/types/kernel/svg.d.ts +3 -0
- package/dist/types/kernel/text.d.ts +21 -0
- package/docs/api.json +207 -0
- package/docs/canvas.md +444 -0
- package/docs/kernel.md +108 -0
- package/docs/llms.txt +41 -0
- package/docs/search-index.json +52 -0
- package/package.json +60 -4
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { TOOL_ACTIONS, shortcutKeys, shortcutLabel, useCanvasActions } from "./canvas-actions.js";
|
|
2
|
+
import { useCanvasCommands, useCanvasController, useCanvasMedia, useCanvasSelector } from "./canvas-context.js";
|
|
3
|
+
import { rail } from "./canvas-tool-rail.styles.js";
|
|
4
|
+
import { shallowEqual } from "./equality.js";
|
|
5
|
+
import { createComponent, getNextElement, insert, memo, mergeProps, ref, runHydrationEvents, spread, template } from "@solidjs/web";
|
|
6
|
+
import * as stylex from "@stylexjs/stylex";
|
|
7
|
+
import { For, Show, createMemo, omit } from "solid-js";
|
|
8
|
+
import { Icon } from "@zsherman/kit/icon";
|
|
9
|
+
import { ArrowUpRight, Circle, Clock, Ellipsis, Eraser, Hand, Image, MessageCircle, MousePointer2, Pen, Redo2, Square, StickyNote, Type, Undo2 } from "@zsherman/kit/icons";
|
|
10
|
+
import { Kbd } from "@zsherman/kit/kbd";
|
|
11
|
+
import { Menu, MenuContent, MenuItemIcon, MenuItemIndicator, MenuRadioGroup, MenuRadioItem, MenuShortcut, MenuTrigger } from "@zsherman/kit/menu";
|
|
12
|
+
import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "@zsherman/kit/toolbar";
|
|
13
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@zsherman/kit/tooltip";
|
|
14
|
+
import { Toggle, ToggleIcon } from "@zsherman/kit/toggle";
|
|
15
|
+
// src/canvas/canvas-tool-rail.tsx
|
|
16
|
+
var _tmpl$ = /* @__PURE__ */ template(`<span>`);
|
|
17
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<input>`);
|
|
18
|
+
const TOOL_ICONS = {
|
|
19
|
+
arrow: ArrowUpRight,
|
|
20
|
+
comment: MessageCircle,
|
|
21
|
+
ellipse: Circle,
|
|
22
|
+
eraser: Eraser,
|
|
23
|
+
hand: Hand,
|
|
24
|
+
pen: Pen,
|
|
25
|
+
rectangle: Square,
|
|
26
|
+
select: MousePointer2,
|
|
27
|
+
sticky: StickyNote,
|
|
28
|
+
text: Type,
|
|
29
|
+
timestamp: Clock
|
|
30
|
+
};
|
|
31
|
+
/** Rail order: pointing, then shapes, then drawing, then comments. */
|
|
32
|
+
const TOOLS = [
|
|
33
|
+
"select",
|
|
34
|
+
"hand",
|
|
35
|
+
"sticky",
|
|
36
|
+
"rectangle",
|
|
37
|
+
"ellipse",
|
|
38
|
+
"text",
|
|
39
|
+
"timestamp",
|
|
40
|
+
"arrow",
|
|
41
|
+
"pen",
|
|
42
|
+
"eraser",
|
|
43
|
+
"comment"
|
|
44
|
+
];
|
|
45
|
+
/** The tools a narrow rail keeps in view; the rest go in its overflow menu. */
|
|
46
|
+
const COMPACT_TOOLS = [
|
|
47
|
+
"select",
|
|
48
|
+
"hand",
|
|
49
|
+
"sticky",
|
|
50
|
+
"rectangle",
|
|
51
|
+
"pen",
|
|
52
|
+
"comment"
|
|
53
|
+
];
|
|
54
|
+
const READ_ONLY_TOOLS = ["select", "hand"];
|
|
55
|
+
function isTool(value) {
|
|
56
|
+
return TOOLS.some((tool) => tool === value);
|
|
57
|
+
}
|
|
58
|
+
const floatingClass = stylex.props(rail.floating).className;
|
|
59
|
+
/** An action's first shortcut as keys, named for assistive technology. */
|
|
60
|
+
function CanvasShortcut(props) {
|
|
61
|
+
const actions = useCanvasActions();
|
|
62
|
+
const keys = createMemo(() => {
|
|
63
|
+
const shortcut = actions().get(props.action)?.shortcuts[0];
|
|
64
|
+
return shortcut === void 0 ? null : shortcutKeys(shortcut);
|
|
65
|
+
});
|
|
66
|
+
return memo(() => {
|
|
67
|
+
return memo(() => {
|
|
68
|
+
return !!keys();
|
|
69
|
+
})() ? (() => {
|
|
70
|
+
var _el$ = getNextElement(_tmpl$);
|
|
71
|
+
spread(_el$, [{
|
|
72
|
+
role: "img",
|
|
73
|
+
get "aria-label"() {
|
|
74
|
+
return keys().spoken;
|
|
75
|
+
}
|
|
76
|
+
}, () => {
|
|
77
|
+
return stylex.attrs(rail.shortcut);
|
|
78
|
+
}], true);
|
|
79
|
+
insert(_el$, createComponent(For, {
|
|
80
|
+
get each() {
|
|
81
|
+
return keys().keys;
|
|
82
|
+
},
|
|
83
|
+
children: (key) => createComponent(Kbd, { children: key })
|
|
84
|
+
}));
|
|
85
|
+
runHydrationEvents();
|
|
86
|
+
return _el$;
|
|
87
|
+
})() : void 0;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A control named by its action, with the action's shortcut on hover, and the kernel's reason when it can't
|
|
92
|
+
* run, such as "Lee Park is editing this".
|
|
93
|
+
*/
|
|
94
|
+
function ActionHint(props) {
|
|
95
|
+
const rest = omit(props, "action", "side", "render");
|
|
96
|
+
const actions = useCanvasActions();
|
|
97
|
+
const found = () => actions().get(props.action);
|
|
98
|
+
const reason = () => {
|
|
99
|
+
const action = found();
|
|
100
|
+
return action?.enabled === false ? action.reason : null;
|
|
101
|
+
};
|
|
102
|
+
return createComponent(Tooltip, { get children() {
|
|
103
|
+
return [createComponent(TooltipTrigger, mergeProps({ unstyled: true }, rest, { render: (trigger) => props.render(trigger) })), createComponent(TooltipContent, {
|
|
104
|
+
get side() {
|
|
105
|
+
return props.side;
|
|
106
|
+
},
|
|
107
|
+
get children() {
|
|
108
|
+
return createComponent(Show, {
|
|
109
|
+
get when() {
|
|
110
|
+
return reason();
|
|
111
|
+
},
|
|
112
|
+
get fallback() {
|
|
113
|
+
return [memo(() => {
|
|
114
|
+
return found()?.label;
|
|
115
|
+
}), createComponent(CanvasShortcut, { get action() {
|
|
116
|
+
return props.action;
|
|
117
|
+
} })];
|
|
118
|
+
},
|
|
119
|
+
children: (why) => `${found()?.label ?? ""}: ${why()}`
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
})];
|
|
123
|
+
} });
|
|
124
|
+
}
|
|
125
|
+
/** Adds images from the viewer's files, placed in the middle of the view. Shown only when the host gives the board `assets`. */
|
|
126
|
+
function ImageButton(props) {
|
|
127
|
+
const controller = useCanvasController();
|
|
128
|
+
const media = useCanvasMedia();
|
|
129
|
+
let input;
|
|
130
|
+
return createComponent(Show, {
|
|
131
|
+
get when() {
|
|
132
|
+
return media();
|
|
133
|
+
},
|
|
134
|
+
children: (current) => [createComponent(Tooltip, { get children() {
|
|
135
|
+
return [createComponent(TooltipTrigger, {
|
|
136
|
+
unstyled: true,
|
|
137
|
+
"aria-label": "Add images",
|
|
138
|
+
"data-part": "canvas-image-button",
|
|
139
|
+
onClick: () => input?.click(),
|
|
140
|
+
render: (trigger) => createComponent(ToolbarButton, mergeProps(trigger, {
|
|
141
|
+
iconOnly: true,
|
|
142
|
+
size: "sm"
|
|
143
|
+
})),
|
|
144
|
+
get children() {
|
|
145
|
+
return createComponent(Icon, {
|
|
146
|
+
icon: Image,
|
|
147
|
+
"aria-hidden": "true"
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}), createComponent(TooltipContent, {
|
|
151
|
+
get side() {
|
|
152
|
+
return props.side;
|
|
153
|
+
},
|
|
154
|
+
children: "Add images, or drop or paste them on the board"
|
|
155
|
+
})];
|
|
156
|
+
} }), (() => {
|
|
157
|
+
var _el$2 = getNextElement(_tmpl$2);
|
|
158
|
+
spread(_el$2, [
|
|
159
|
+
{
|
|
160
|
+
type: "file",
|
|
161
|
+
get accept() {
|
|
162
|
+
return current().assets.accept.join(",");
|
|
163
|
+
},
|
|
164
|
+
"aria-hidden": "true"
|
|
165
|
+
},
|
|
166
|
+
() => {
|
|
167
|
+
return stylex.attrs(rail.fileInput);
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"data-slot": "canvas-image-input",
|
|
171
|
+
multiple: true,
|
|
172
|
+
tabindex: -1,
|
|
173
|
+
onChange: (event) => {
|
|
174
|
+
const files = [...event.currentTarget.files ?? []];
|
|
175
|
+
event.currentTarget.value = "";
|
|
176
|
+
if (files.length > 0) current().uploads.addFiles(files, controller.centre());
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
], false);
|
|
180
|
+
ref(() => {
|
|
181
|
+
return (element) => input = element;
|
|
182
|
+
}, _el$2);
|
|
183
|
+
runHydrationEvents();
|
|
184
|
+
return _el$2;
|
|
185
|
+
})()]
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The tools, and undo and redo. A column at the board's side, or a row along its bottom when the board is
|
|
190
|
+
* narrow, with the less used tools in a menu.
|
|
191
|
+
*/
|
|
192
|
+
function CanvasToolRail(props) {
|
|
193
|
+
const state = useCanvasSelector((snapshot) => ({
|
|
194
|
+
comments: snapshot.comments,
|
|
195
|
+
readOnly: snapshot.state.readOnly,
|
|
196
|
+
tool: snapshot.state.tool
|
|
197
|
+
}), shallowEqual);
|
|
198
|
+
const actions = useCanvasActions();
|
|
199
|
+
const commands = useCanvasCommands();
|
|
200
|
+
const compact = () => props.compact ?? false;
|
|
201
|
+
const orientation = () => compact() ? "horizontal" : "vertical";
|
|
202
|
+
const side = () => compact() ? "top" : "right";
|
|
203
|
+
const available = createMemo(() => (state().readOnly ? READ_ONLY_TOOLS : TOOLS).filter((tool) => tool !== "comment" || state().comments));
|
|
204
|
+
const shown = createMemo(() => compact() ? available().filter((tool) => COMPACT_TOOLS.includes(tool)) : available());
|
|
205
|
+
const overflow = createMemo(() => available().filter((tool) => !shown().includes(tool)));
|
|
206
|
+
/** The tool in use, when it is one of the overflow menu's. */
|
|
207
|
+
const overflowTool = () => overflow().find((tool) => tool === state().tool);
|
|
208
|
+
const overflowIcon = () => {
|
|
209
|
+
const tool = overflowTool();
|
|
210
|
+
return tool === void 0 ? Ellipsis : TOOL_ICONS[tool];
|
|
211
|
+
};
|
|
212
|
+
const overflowLabel = () => {
|
|
213
|
+
const tool = overflowTool();
|
|
214
|
+
return tool === void 0 ? "More tools" : `More tools, ${labelOf(tool)} in use`;
|
|
215
|
+
};
|
|
216
|
+
const labelOf = (tool) => actions().get(TOOL_ACTIONS[tool])?.label ?? tool;
|
|
217
|
+
const choose = (tool) => {
|
|
218
|
+
if (isTool(tool)) commands.action(TOOL_ACTIONS[tool]);
|
|
219
|
+
};
|
|
220
|
+
return createComponent(Toolbar, {
|
|
221
|
+
"aria-label": "Board tools",
|
|
222
|
+
class: floatingClass,
|
|
223
|
+
"data-canvas-tool-rail": "",
|
|
224
|
+
get orientation() {
|
|
225
|
+
return orientation();
|
|
226
|
+
},
|
|
227
|
+
get children() {
|
|
228
|
+
return [
|
|
229
|
+
createComponent(ToolbarGroup, {
|
|
230
|
+
"aria-label": "Tool",
|
|
231
|
+
get children() {
|
|
232
|
+
return createComponent(For, {
|
|
233
|
+
get each() {
|
|
234
|
+
return shown();
|
|
235
|
+
},
|
|
236
|
+
children: (tool) => createComponent(ActionHint, {
|
|
237
|
+
get action() {
|
|
238
|
+
return TOOL_ACTIONS[tool];
|
|
239
|
+
},
|
|
240
|
+
get side() {
|
|
241
|
+
return side();
|
|
242
|
+
},
|
|
243
|
+
get "aria-label"() {
|
|
244
|
+
return labelOf(tool);
|
|
245
|
+
},
|
|
246
|
+
"data-tool": tool,
|
|
247
|
+
render: (trigger) => createComponent(Toggle, mergeProps(trigger, {
|
|
248
|
+
size: "sm",
|
|
249
|
+
get pressed() {
|
|
250
|
+
return state().tool === tool;
|
|
251
|
+
},
|
|
252
|
+
onPressedChange: () => choose(tool)
|
|
253
|
+
})),
|
|
254
|
+
get children() {
|
|
255
|
+
return createComponent(ToggleIcon, { get icon() {
|
|
256
|
+
return TOOL_ICONS[tool];
|
|
257
|
+
} });
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}),
|
|
263
|
+
createComponent(Show, {
|
|
264
|
+
get when() {
|
|
265
|
+
return overflow().length > 0;
|
|
266
|
+
},
|
|
267
|
+
get children() {
|
|
268
|
+
return createComponent(Menu, { get children() {
|
|
269
|
+
return [createComponent(ToolbarButton, {
|
|
270
|
+
get "aria-label"() {
|
|
271
|
+
return overflowLabel();
|
|
272
|
+
},
|
|
273
|
+
render: (trigger) => createComponent(MenuTrigger, mergeProps(trigger, {
|
|
274
|
+
iconOnly: true,
|
|
275
|
+
size: "sm"
|
|
276
|
+
})),
|
|
277
|
+
get children() {
|
|
278
|
+
return createComponent(Icon, {
|
|
279
|
+
get icon() {
|
|
280
|
+
return overflowIcon();
|
|
281
|
+
},
|
|
282
|
+
"aria-hidden": "true"
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}), createComponent(MenuContent, {
|
|
286
|
+
get side() {
|
|
287
|
+
return side();
|
|
288
|
+
},
|
|
289
|
+
get children() {
|
|
290
|
+
return createComponent(MenuRadioGroup, {
|
|
291
|
+
get value() {
|
|
292
|
+
return state().tool;
|
|
293
|
+
},
|
|
294
|
+
onValueChange: (value) => choose(value),
|
|
295
|
+
get children() {
|
|
296
|
+
return createComponent(For, {
|
|
297
|
+
get each() {
|
|
298
|
+
return overflow();
|
|
299
|
+
},
|
|
300
|
+
children: (tool) => {
|
|
301
|
+
const shortcut = () => actions().get(TOOL_ACTIONS[tool])?.shortcuts[0];
|
|
302
|
+
return createComponent(MenuRadioItem, {
|
|
303
|
+
value: tool,
|
|
304
|
+
closeOnSelect: true,
|
|
305
|
+
get children() {
|
|
306
|
+
return [
|
|
307
|
+
createComponent(MenuItemIcon, { get icon() {
|
|
308
|
+
return TOOL_ICONS[tool];
|
|
309
|
+
} }),
|
|
310
|
+
memo(() => {
|
|
311
|
+
return labelOf(tool);
|
|
312
|
+
}),
|
|
313
|
+
createComponent(Show, {
|
|
314
|
+
get when() {
|
|
315
|
+
return shortcut();
|
|
316
|
+
},
|
|
317
|
+
children: (keys) => createComponent(MenuShortcut, { get children() {
|
|
318
|
+
return shortcutLabel(keys());
|
|
319
|
+
} })
|
|
320
|
+
}),
|
|
321
|
+
createComponent(MenuItemIndicator, {})
|
|
322
|
+
];
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
})];
|
|
331
|
+
} });
|
|
332
|
+
}
|
|
333
|
+
}),
|
|
334
|
+
createComponent(Show, {
|
|
335
|
+
get when() {
|
|
336
|
+
return !state().readOnly;
|
|
337
|
+
},
|
|
338
|
+
get children() {
|
|
339
|
+
return [
|
|
340
|
+
createComponent(ImageButton, { get side() {
|
|
341
|
+
return side();
|
|
342
|
+
} }),
|
|
343
|
+
createComponent(ToolbarSeparator, {}),
|
|
344
|
+
createComponent(ToolbarGroup, {
|
|
345
|
+
"aria-label": "History",
|
|
346
|
+
get children() {
|
|
347
|
+
return [createComponent(ActionHint, {
|
|
348
|
+
action: "undo",
|
|
349
|
+
get side() {
|
|
350
|
+
return side();
|
|
351
|
+
},
|
|
352
|
+
"aria-label": "Undo",
|
|
353
|
+
onClick: () => commands.action("undo"),
|
|
354
|
+
render: (trigger) => createComponent(ToolbarButton, mergeProps(trigger, {
|
|
355
|
+
iconOnly: true,
|
|
356
|
+
size: "sm",
|
|
357
|
+
get disabled() {
|
|
358
|
+
return actions().get("undo")?.enabled !== true;
|
|
359
|
+
}
|
|
360
|
+
})),
|
|
361
|
+
get children() {
|
|
362
|
+
return createComponent(Icon, {
|
|
363
|
+
icon: Undo2,
|
|
364
|
+
flipInRtl: true,
|
|
365
|
+
"aria-hidden": "true"
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}), createComponent(Show, {
|
|
369
|
+
get when() {
|
|
370
|
+
return !compact();
|
|
371
|
+
},
|
|
372
|
+
get children() {
|
|
373
|
+
return createComponent(ActionHint, {
|
|
374
|
+
action: "redo",
|
|
375
|
+
get side() {
|
|
376
|
+
return side();
|
|
377
|
+
},
|
|
378
|
+
"aria-label": "Redo",
|
|
379
|
+
onClick: () => commands.action("redo"),
|
|
380
|
+
render: (trigger) => createComponent(ToolbarButton, mergeProps(trigger, {
|
|
381
|
+
iconOnly: true,
|
|
382
|
+
size: "sm",
|
|
383
|
+
get disabled() {
|
|
384
|
+
return actions().get("redo")?.enabled !== true;
|
|
385
|
+
}
|
|
386
|
+
})),
|
|
387
|
+
get children() {
|
|
388
|
+
return createComponent(Icon, {
|
|
389
|
+
icon: Redo2,
|
|
390
|
+
flipInRtl: true,
|
|
391
|
+
"aria-hidden": "true"
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
})];
|
|
397
|
+
}
|
|
398
|
+
})
|
|
399
|
+
];
|
|
400
|
+
}
|
|
401
|
+
})
|
|
402
|
+
];
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
export { ActionHint, CanvasShortcut, CanvasToolRail, TOOL_ICONS };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "@stylexjs/stylex";
|
|
2
|
+
// src/canvas/canvas-tool-rail.styles.ts
|
|
3
|
+
const rail = {
|
|
4
|
+
floating: {
|
|
5
|
+
kGVxlE: "x1vt0vig",
|
|
6
|
+
$$css: true
|
|
7
|
+
},
|
|
8
|
+
shortcut: {
|
|
9
|
+
k1xSpc: "x3nfvp2",
|
|
10
|
+
kGNEyG: "x6s0dn4",
|
|
11
|
+
kOIVth: "xpowot6",
|
|
12
|
+
kmuXW: "x2lah0s",
|
|
13
|
+
$$css: true
|
|
14
|
+
},
|
|
15
|
+
fileInput: {
|
|
16
|
+
k1xSpc: "x1s85apg",
|
|
17
|
+
$$css: true
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export { rail };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { randomId } from "./random-id.js";
|
|
2
|
+
// src/canvas/comments.ts
|
|
3
|
+
/** The longest comment body, in UTF-16 code units. */
|
|
4
|
+
const COMMENT_MAX = 2e3;
|
|
5
|
+
/** A new thread or comment id, in the server's id alphabet. */
|
|
6
|
+
function commentId() {
|
|
7
|
+
return randomId();
|
|
8
|
+
}
|
|
9
|
+
/** The body to send for typed text, or null when it can't be sent. */
|
|
10
|
+
function commentBody(text) {
|
|
11
|
+
const body = text.trim();
|
|
12
|
+
return body.length === 0 || body.length > 2e3 ? null : body;
|
|
13
|
+
}
|
|
14
|
+
/** The top-left corner of a shape's bounds; null when it is not on the board. */
|
|
15
|
+
function shapeCorner(board, id) {
|
|
16
|
+
const shape = board.shapes.find((item) => item.id === id);
|
|
17
|
+
if (shape === void 0) return null;
|
|
18
|
+
return {
|
|
19
|
+
x: Math.min(shape.x, shape.x + shape.w),
|
|
20
|
+
y: Math.min(shape.y, shape.y + shape.h)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Where a thread's pin sits on the board now. */
|
|
24
|
+
function pinPoint(board, anchor) {
|
|
25
|
+
if (anchor._tag === "Point") return anchor.at;
|
|
26
|
+
const corner = shapeCorner(board, anchor.shape);
|
|
27
|
+
if (corner === null) return anchor.at;
|
|
28
|
+
return {
|
|
29
|
+
x: corner.x + anchor.offset.x,
|
|
30
|
+
y: corner.y + anchor.offset.y
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** The anchor for a pin dropped at `at`, on `shape` when one is under it. */
|
|
34
|
+
function anchorAt(board, at, shape) {
|
|
35
|
+
const corner = shape === null ? null : shapeCorner(board, shape);
|
|
36
|
+
if (shape === null || corner === null) return {
|
|
37
|
+
_tag: "Point",
|
|
38
|
+
at
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
_tag: "Shape",
|
|
42
|
+
at,
|
|
43
|
+
offset: {
|
|
44
|
+
x: at.x - corner.x,
|
|
45
|
+
y: at.y - corner.y
|
|
46
|
+
},
|
|
47
|
+
shape
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** What the viewer may do with one comment. */
|
|
51
|
+
function commentPermissions(comments, comment) {
|
|
52
|
+
const mine = comment.author.principal === comments.viewer;
|
|
53
|
+
return {
|
|
54
|
+
edit: mine && comments.canComment,
|
|
55
|
+
delete: mine && comments.canComment || comments.canManage
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export { COMMENT_MAX, anchorAt, commentBody, commentId, commentPermissions, pinPoint };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/canvas/equality.ts
|
|
2
|
+
/** True when two plain objects hold the same values, key by key. */
|
|
3
|
+
function shallowEqual(a, b) {
|
|
4
|
+
if (Object.is(a, b)) return true;
|
|
5
|
+
const keys = Object.keys(a);
|
|
6
|
+
if (keys.length !== Object.keys(b).length) return false;
|
|
7
|
+
return keys.every((key) => key in b && Object.is(a[key], b[key]));
|
|
8
|
+
}
|
|
9
|
+
/** True when two lists hold the same items in the same order. */
|
|
10
|
+
function sameList(a, b) {
|
|
11
|
+
return a === b || a.length === b.length && a.every((x, i) => Object.is(x, b[i]));
|
|
12
|
+
}
|
|
13
|
+
export { sameList, shallowEqual };
|