@ggraphic/editor 0.1.0-alpha.0 → 0.1.0-alpha.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/README.md +16 -3
- package/THIRD_PARTY_NOTICES +25 -1
- package/dist/components/CanvasContextMenu/CanvasActionSheet.js +2 -1
- package/dist/components/CanvasContextMenu/CanvasContextMenu.js +3 -2
- package/dist/components/CanvasEditor/CanvasEditorShell.js +4 -1
- package/dist/components/CanvasTextOverlay.js +10 -3
- package/dist/components/GenericCanvas.js +12 -3
- package/dist/components/RichTextField.js +1 -0
- package/dist/components/SelectionPill.js +2 -1
- package/dist/components/TextFormatButtons.js +7 -2
- package/dist/i18n/de.d.ts +12 -0
- package/dist/i18n/de.js +12 -0
- package/dist/i18n/en.js +11 -0
- package/dist/page/actions.d.ts +66 -0
- package/dist/page/actions.js +353 -0
- package/dist/page/config.d.ts +15 -0
- package/dist/page/config.js +91 -0
- package/dist/page/fitting.d.ts +6 -0
- package/dist/page/fitting.js +26 -0
- package/dist/page/hug.d.ts +10 -0
- package/dist/page/hug.js +18 -0
- package/dist/page/instantiate.d.ts +8 -0
- package/dist/page/instantiate.js +30 -0
- package/dist/page/logoSize.d.ts +8 -0
- package/dist/page/logoSize.js +29 -0
- package/dist/page/pageState.d.ts +41 -0
- package/dist/page/pageState.js +59 -0
- package/dist/page/seeds.d.ts +14 -0
- package/dist/page/seeds.js +40 -0
- package/dist/page/slotBudgets.d.ts +22 -0
- package/dist/page/slotBudgets.js +18 -0
- package/dist/page/templatePack.d.ts +31 -0
- package/dist/page/templatePack.js +55 -0
- package/dist/page/typography.d.ts +11 -0
- package/dist/page/typography.js +13 -0
- package/dist/sidebar/sections/CombinedTextSection.js +1 -1
- package/dist/sidebar/sections/GenericShareSection.js +3 -2
- package/dist/styles/compiled.css +2 -0
- package/dist/ui/alert-dialog.js +3 -2
- package/dist/ui/dialog.js +3 -2
- package/dist/ui/editorScope.d.ts +10 -0
- package/dist/ui/editorScope.js +9 -0
- package/dist/ui/popover.js +2 -1
- package/dist/ui/select.js +2 -1
- package/dist/utils/canvasLayerManager.d.ts +14 -0
- package/dist/utils/canvasLayerManager.js +24 -0
- package/dist/utils/fontMarkSupport.d.ts +10 -0
- package/dist/utils/fontMarkSupport.js +22 -6
- package/dist/utils/layerLabels.js +3 -6
- package/dist/utils/textUtils.js +2 -14
- package/package.json +13 -6
- package/skills/ggraphic-embed/SKILL.md +145 -0
package/README.md
CHANGED
|
@@ -2,8 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
> **Alpha, untested.** Early work in progress: the API and the document format can change without notice. See the [repository README](../../README.md#ggraphic).
|
|
4
4
|
|
|
5
|
-
The brand-neutral canvas editor of ggraphic, built on react-konva
|
|
5
|
+
The brand-neutral canvas editor of ggraphic, built on react-konva: the editor shell with its sidebar, stage, text editing, elements (shapes, icons, illustrations, charts, badges, images), multi-page documents, undo, export (PNG, PDF, PPTX) and the Yjs page document for collaboration. Licensed under the [Mozilla Public License 2.0](./LICENSE).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save-exact @ggraphic/editor@0.1.0-alpha.0 @ggraphic/core@0.1.0-alpha.0 @ggraphic/schema@0.1.0-alpha.0
|
|
11
|
+
npm install react react-dom konva react-konva @tanstack/react-query
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Releases are published under the npm dist-tag `alpha`. The package is ESM-only.
|
|
15
|
+
|
|
16
|
+
## Embedding
|
|
17
|
+
|
|
18
|
+
The editor needs a host: a brand pack, at least one template (page config), host services and styles. The step-by-step guide, with the traps hosts have hit, is the agent skill shipped in this package: [`skills/ggraphic-embed/SKILL.md`](./skills/ggraphic-embed/SKILL.md). It is plain Markdown, so it reads as documentation too.
|
|
19
|
+
|
|
20
|
+
## Entry points
|
|
21
|
+
|
|
22
|
+
Each source file is its own entry point (a host imports `@ggraphic/editor/utils/snapping`, not a barrel), so a module keeps its identity and a test can mock it by that path. The CSS entries are `@ggraphic/editor/styles` (token defaults and editor rules) and `@ggraphic/editor/styles/tailwind` (for Tailwind v4 hosts).
|
package/THIRD_PARTY_NOTICES
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
|
-
This package bundles
|
|
1
|
+
This package bundles one third-party component: dist/styles/compiled.css
|
|
2
|
+
(`@ggraphic/editor/styles/compiled`) contains CSS generated by Tailwind CSS, including its
|
|
3
|
+
preflight reset, under the following license:
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) Tailwind Labs, Inc.
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
2
26
|
|
|
3
27
|
Its npm dependencies keep their own licenses. The icon data comes at runtime from the
|
|
4
28
|
@iconify-json sets: Tabler, Flowbite, Heroicons, Iconoir and Bootstrap Icons (MIT),
|
|
@@ -7,6 +7,7 @@ import { AFTER_CLOSE, } from '@ggraphic/editor/components/CanvasContextMenu/Canv
|
|
|
7
7
|
import { compact, } from '@ggraphic/editor/components/CanvasContextMenu/canvasMenuModel';
|
|
8
8
|
import { useMessages } from '@ggraphic/editor/i18n/messages';
|
|
9
9
|
import { cn } from '@ggraphic/editor/utils/cn';
|
|
10
|
+
import { EDITOR_SCOPE } from '../../ui/editorScope.js';
|
|
10
11
|
/** Die Zwischenablage steht oben als Kacheln, wie bei Canva: das, was man am häufigsten tippt. */
|
|
11
12
|
const QUICK = new Set([
|
|
12
13
|
'copy',
|
|
@@ -133,7 +134,7 @@ export function CanvasActionSheet({ handleRef, }) {
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
};
|
|
136
|
-
return (_jsx(Dialog.Root, { open: open, onOpenChange: setOpen, children: _jsxs(Dialog.Portal, { children: [_jsx(Dialog.Overlay, { className: "fixed inset-0 z-[1010] bg-black/30" }), _jsxs(Dialog.Content, { "aria-describedby": undefined, className: "fixed inset-x-0 bottom-0 z-[1010] flex max-h-[75dvh] flex-col rounded-t-2xl bg-[var(--editor-surface)] pb-[env(safe-area-inset-bottom)] text-[var(--editor-text)] shadow-[0_-8px_24px_rgba(0,0,0,0.16)] outline-none", onCloseAutoFocus: (e) => {
|
|
137
|
+
return (_jsx(Dialog.Root, { open: open, onOpenChange: setOpen, children: _jsxs(Dialog.Portal, { children: [_jsx(Dialog.Overlay, { ...EDITOR_SCOPE, className: "fixed inset-0 z-[1010] bg-black/30" }), _jsxs(Dialog.Content, { ...EDITOR_SCOPE, "aria-describedby": undefined, className: "fixed inset-x-0 bottom-0 z-[1010] flex max-h-[75dvh] flex-col rounded-t-2xl bg-[var(--editor-surface)] pb-[env(safe-area-inset-bottom)] text-[var(--editor-text)] shadow-[0_-8px_24px_rgba(0,0,0,0.16)] outline-none", onCloseAutoFocus: (e) => {
|
|
137
138
|
if (!keepFocusRef.current)
|
|
138
139
|
return;
|
|
139
140
|
keepFocusRef.current = false;
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { ContextMenu } from 'radix-ui';
|
|
4
4
|
import { useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
5
5
|
import { PiCaretRight, PiCheck } from 'react-icons/pi';
|
|
6
|
+
import { EDITOR_SCOPE } from '../../ui/editorScope.js';
|
|
6
7
|
/** Befehle, die selbst den Fokus nehmen (Text-Editor, Bildauswahl): erst nach dem Schließen. */
|
|
7
8
|
export const AFTER_CLOSE = new Set(['editText', 'replaceBackground']);
|
|
8
9
|
const CONTENT = 'z-[10001] min-w-[14rem] max-h-(--radix-context-menu-content-available-height) overflow-y-auto rounded-lg border border-[var(--editor-border)] bg-[var(--editor-surface)] p-1 text-[var(--editor-text)] shadow-[0_8px_24px_rgba(0,0,0,0.16)]';
|
|
@@ -93,12 +94,12 @@ export function CanvasContextMenu({ handleRef, closeKey, }) {
|
|
|
93
94
|
case 'check':
|
|
94
95
|
return (_jsxs(ContextMenu.CheckboxItem, { className: `${ITEM} pl-7`, checked: entry.checked, onSelect: () => select(entry.id), children: [_jsx(ContextMenu.ItemIndicator, { className: "absolute left-2 inline-flex", children: _jsx(PiCheck, { size: 14, "aria-hidden": true }) }), entry.label] }, entry.id));
|
|
95
96
|
case 'sub':
|
|
96
|
-
return (_jsxs(ContextMenu.Sub, { children: [_jsxs(ContextMenu.SubTrigger, { className: ITEM, children: [entry.label, _jsx(PiCaretRight, { size: 14, className: "ml-auto", "aria-hidden": true })] }), _jsx(ContextMenu.Portal, { children: _jsx(ContextMenu.SubContent, { className: CONTENT, sideOffset: 4, children: entry.entries.map(renderEntry) }) })] }, `sub-${entry.label}`));
|
|
97
|
+
return (_jsxs(ContextMenu.Sub, { children: [_jsxs(ContextMenu.SubTrigger, { className: ITEM, children: [entry.label, _jsx(PiCaretRight, { size: 14, className: "ml-auto", "aria-hidden": true })] }), _jsx(ContextMenu.Portal, { children: _jsx(ContextMenu.SubContent, { ...EDITOR_SCOPE, className: CONTENT, sideOffset: 4, children: entry.entries.map(renderEntry) }) })] }, `sub-${entry.label}`));
|
|
97
98
|
case 'item':
|
|
98
99
|
return (_jsxs(ContextMenu.Item, { className: ITEM, disabled: entry.disabled, onSelect: () => select(entry.id), ...(entry.destructive ? { 'data-destructive': '' } : {}), ...(entry.ariaShortcut ? { 'aria-keyshortcuts': entry.ariaShortcut } : {}), children: [entry.label, entry.shortcut && (_jsx("span", { className: "ml-auto pl-6 text-[12px] text-[var(--editor-text-muted)]", children: entry.shortcut }))] }, entry.id));
|
|
99
100
|
}
|
|
100
101
|
};
|
|
101
|
-
return (_jsxs(ContextMenu.Root, { open: open, onOpenChange: changeOpen, modal: false, children: [_jsx(ContextMenu.Trigger, { asChild: true, children: _jsx("span", { ref: anchorRef, "aria-hidden": true, className: "fixed left-0 top-0 size-0" }) }), _jsx(ContextMenu.Portal, { children: request && (_jsx(ContextMenu.Content, { ref: contentRef, className: CONTENT, "aria-label": request.menu.label, onContextMenu: (e) => e.preventDefault(), onCloseAutoFocus: (e) => {
|
|
102
|
+
return (_jsxs(ContextMenu.Root, { open: open, onOpenChange: changeOpen, modal: false, children: [_jsx(ContextMenu.Trigger, { asChild: true, children: _jsx("span", { ref: anchorRef, "aria-hidden": true, className: "fixed left-0 top-0 size-0" }) }), _jsx(ContextMenu.Portal, { children: request && (_jsx(ContextMenu.Content, { ...EDITOR_SCOPE, ref: contentRef, className: CONTENT, "aria-label": request.menu.label, onContextMenu: (e) => e.preventDefault(), onCloseAutoFocus: (e) => {
|
|
102
103
|
if (!keepFocusRef.current)
|
|
103
104
|
return;
|
|
104
105
|
keepFocusRef.current = false;
|
|
@@ -109,8 +109,10 @@ const NO_CALLBACK_KEYS = () => [];
|
|
|
109
109
|
const DEFAULT_DECK_LOCALE = () => 'de-DE';
|
|
110
110
|
/** Folien-PDF: 2× der 1920 × 1080-Folie, scharf auch im Vollbild. */
|
|
111
111
|
const SLIDES_PDF_PIXEL_RATIO = 2;
|
|
112
|
+
/** A box-less root that scopes `@ggraphic/editor/styles/compiled` to the editor (`EDITOR_SCOPE`). */
|
|
113
|
+
const SCOPE_ROOT_STYLE = { display: 'contents' };
|
|
112
114
|
export function CanvasEditorShell(props) {
|
|
113
|
-
return (_jsx(AutoSaveStoreProvider, { initialShareToken: props.initialShareToken ?? null, children: _jsx(CanvasEditorInner, { ...props }) }));
|
|
115
|
+
return (_jsx("div", { ...EDITOR_SCOPE, style: SCOPE_ROOT_STYLE, children: _jsx(AutoSaveStoreProvider, { initialShareToken: props.initialShareToken ?? null, children: _jsx(CanvasEditorInner, { ...props }) }) }));
|
|
114
116
|
}
|
|
115
117
|
function CanvasEditorInner({ initialConfigId, formatId, documentTitle, initialProps, onExport, onCancel, onDownload, callbacks = {}, maxPages = 10, initialPages, collaborative, chromeLeft, chromeCenter, chromeRight, onInvitePeople, onSaveAsTemplate, onCollabSnapshot, onAutoSaveShareToken, initialTab = null, onActiveTabChange, galleryAutoSave = true, showShare = true, exportApiRef, hostChrome, readOnly = false, }) {
|
|
116
118
|
const t = useMessages();
|
|
@@ -1141,4 +1143,5 @@ function CanvasEditorInner({ initialConfigId, formatId, documentTitle, initialPr
|
|
|
1141
1143
|
!readOnly &&
|
|
1142
1144
|
(isMobileWeb ? (_jsx(CanvasActionSheet, { handleRef: contextMenuRef })) : (_jsx(CanvasContextMenu, { handleRef: contextMenuRef, closeKey: zoom })))] }) }) })] }) }));
|
|
1143
1145
|
}
|
|
1146
|
+
import { EDITOR_SCOPE } from '../../ui/editorScope.js';
|
|
1144
1147
|
export default CanvasEditorShell;
|
|
@@ -76,8 +76,15 @@ import { resolveFontFamily } from '../utils/fontAliases.js';
|
|
|
76
76
|
import { fontMarkSupport } from '../utils/fontMarkSupport.js';
|
|
77
77
|
import { defaultTextMarker } from '../utils/markerColors.js';
|
|
78
78
|
import { fontStyleForRun, measureTextWidthWithFont, } from '../utils/textUtils.js';
|
|
79
|
+
import { EDITOR_SCOPE } from '../ui/editorScope.js';
|
|
79
80
|
/** Ohne offene Sitzung trägt niemand einen Schnitt. */
|
|
80
|
-
const NO_MARKS = {
|
|
81
|
+
const NO_MARKS = {
|
|
82
|
+
bold: false,
|
|
83
|
+
italic: false,
|
|
84
|
+
boldItalic: false,
|
|
85
|
+
accent: false,
|
|
86
|
+
marker: false,
|
|
87
|
+
};
|
|
81
88
|
/**
|
|
82
89
|
* Untergrenze für die gespiegelte Deckkraft. Der Regler der Kopfleiste geht
|
|
83
90
|
* bis 0; ein Feld, das dort steht, wäre als Editor nicht mehr zu sehen.
|
|
@@ -514,7 +521,7 @@ function TextEditorRoot({ children }) {
|
|
|
514
521
|
// kein `overflow: hidden` der Leinwandfläche die Werkzeugleiste
|
|
515
522
|
// abschneidet — die sitzt über dem Text und ragt bei einem Feld am
|
|
516
523
|
// oberen Rand aus dem Sujet heraus.
|
|
517
|
-
createPortal(_jsx("div", { style: {
|
|
524
|
+
createPortal(_jsx("div", { ...EDITOR_SCOPE, style: {
|
|
518
525
|
position: 'absolute',
|
|
519
526
|
top: box.top,
|
|
520
527
|
left: box.left,
|
|
@@ -523,5 +530,5 @@ function TextEditorRoot({ children }) {
|
|
|
523
530
|
zIndex: 10000,
|
|
524
531
|
pointerEvents: shrink < 1 ? 'none' : undefined,
|
|
525
532
|
}, children: modules ? (_jsx(modules.RichTextField, { value: draft, onChange: onDraftChange, marks: marks, showToolbar: hosts === 0, onEditorReady: setEditor, autoFocus: true, contentStyle: contentStyle, onBlur: commit, onEscape: commit, onSubmit: commit })) : (_jsx("div", { className: "canvas-rte", children: _jsx("div", { style: contentStyle, children: _jsx("div", { className: "canvas-rte__content", children: stripInlineMarks(draft) }) }) })) }), document.body), loadFailed &&
|
|
526
|
-
createPortal(_jsx("div", { role: "alert", className: "fixed bottom-4 left-1/2 z-[10000] max-w-[min(420px,calc(100vw-32px))] -translate-x-1/2 rounded-md bg-[var(--editor-surface)] px-4 py-3 text-sm text-[var(--editor-text)] shadow-lg", children: messages().errors.textEditorLoad }), document.body)] }));
|
|
533
|
+
createPortal(_jsx("div", { ...EDITOR_SCOPE, role: "alert", className: "fixed bottom-4 left-1/2 z-[10000] max-w-[min(420px,calc(100vw-32px))] -translate-x-1/2 rounded-md bg-[var(--editor-surface)] px-4 py-3 text-sm text-[var(--editor-text)] shadow-lg", children: messages().errors.textEditorLoad }), document.body)] }));
|
|
527
534
|
}
|
|
@@ -49,7 +49,7 @@ import { floatingModuleFor } from '../hooks/useFloatingModuleState.js';
|
|
|
49
49
|
import { CanvasStage, SnapGuidelines } from '../primitives/index.js';
|
|
50
50
|
import { createCanvasCommands, } from '../utils/canvasCommands.js';
|
|
51
51
|
import { canvasFontFamilies } from '../utils/canvasFontFamilies.js';
|
|
52
|
-
import { buildCanvasItems, buildSortedRenderList } from '../utils/canvasLayerManager.js';
|
|
52
|
+
import { buildCanvasItems, buildSortedRenderList, withInsertsOnTop, } from '../utils/canvasLayerManager.js';
|
|
53
53
|
import { addHostElement, fromHostKinds } from '../utils/elementKinds.js';
|
|
54
54
|
import { captureStageImage, captureStageImageAsync, rasterizeStageElement, visibleStageTexts, } from '../utils/captureStage.js';
|
|
55
55
|
import { MAX_ICON_SELECTIONS, selectedCatalogIconIds } from '../utils/iconInstances.js';
|
|
@@ -118,6 +118,15 @@ function GenericCanvasWithRef(props) {
|
|
|
118
118
|
return { ...prev, ...partial };
|
|
119
119
|
});
|
|
120
120
|
}, []);
|
|
121
|
+
// The setter the element actions get: whatever an action inserts is drawn on top of the page,
|
|
122
|
+
// regardless of its kind. The canvas commands (paste, duplicate, reorder) place their own
|
|
123
|
+
// elements and keep the plain setter.
|
|
124
|
+
const setActionState = useCallback((partial) => {
|
|
125
|
+
setStateRaw((prev) => {
|
|
126
|
+
const next = typeof partial === 'function' ? partial(prev) : { ...prev, ...partial };
|
|
127
|
+
return withInsertsOnTop(config, prev, next);
|
|
128
|
+
});
|
|
129
|
+
}, [config]);
|
|
121
130
|
// External edits to this page's `state` Y.Map (chat sharepic editing via
|
|
122
131
|
// the Hocuspocus internal API) merge into the live component state.
|
|
123
132
|
// Rebuilding through createInitialState recomputes the derived fields.
|
|
@@ -201,12 +210,12 @@ function GenericCanvasWithRef(props) {
|
|
|
201
210
|
// `runHistoryBatch` rides on the actions so the AI bridge (built from the
|
|
202
211
|
// page's live actions) coalesces one op batch into one undo step.
|
|
203
212
|
const actions = useMemo(() => ({
|
|
204
|
-
...config.createActions(getState,
|
|
213
|
+
...config.createActions(getState, setActionState, saveToHistory, debouncedSaveToHistory, callbacks),
|
|
205
214
|
runHistoryBatch,
|
|
206
215
|
}), [
|
|
207
216
|
config,
|
|
208
217
|
getState,
|
|
209
|
-
|
|
218
|
+
setActionState,
|
|
210
219
|
saveToHistory,
|
|
211
220
|
debouncedSaveToHistory,
|
|
212
221
|
runHistoryBatch,
|
|
@@ -8,6 +8,7 @@ import { useRovingToolbar } from '@ggraphic/editor/hooks/useRovingToolbar';
|
|
|
8
8
|
import { useMessages } from '@ggraphic/editor/i18n/messages';
|
|
9
9
|
import { CANVAS_COMMANDS, formatShortcut, isMacPlatform, shortcutOf, } from '@ggraphic/editor/utils/canvasCommandRegistry';
|
|
10
10
|
import { cn } from '@ggraphic/editor/utils/cn';
|
|
11
|
+
import { EDITOR_SCOPE } from '../ui/editorScope.js';
|
|
11
12
|
const GAP = 12;
|
|
12
13
|
const EDGE = 8;
|
|
13
14
|
const GEOMETRY = {
|
|
@@ -119,5 +120,5 @@ export function SelectionPill({ variant = 'touch', measureKey, zoom, getBox, sub
|
|
|
119
120
|
? t.topBar.nothingDeletable
|
|
120
121
|
: t.topBar.templateNoDelete;
|
|
121
122
|
const deleteButton = (_jsx("button", { type: "button", className: cn(btn, pointer && DANGER_BTN), onClick: onDelete, disabled: !canDelete, title: pointer ? deleteTitle : undefined, "aria-label": t.commands.delete, children: _jsx(PiTrash, { size: iconSize, "aria-hidden": true }) }));
|
|
122
|
-
return createPortal(_jsxs("div", { ref: pillRef, onKeyDown: onKeyDown, onFocus: onFocus, role: "toolbar", "aria-label": t.common.element, style: { top, left }, className: cn('fixed z-[110] flex items-center gap-0.5 rounded-full border border-[var(--editor-border-soft)] bg-[var(--editor-surface)] shadow-[0_2px_8px_rgba(0,0,0,0.12)]', pointer ? 'p-0.5' : 'px-1'), children: [pointer && onToggleLock && (_jsx("button", { type: "button", className: btn, onClick: onToggleLock, "aria-pressed": isLocked, title: isLocked ? t.topBar.unlockHint : t.topBar.lockHint, "aria-label": lockLabel, children: isLocked ? (_jsx(PiLockSimple, { size: iconSize, "aria-hidden": true })) : (_jsx(PiLockSimpleOpen, { size: iconSize, "aria-hidden": true })) })), _jsx("button", { type: "button", className: btn, onClick: onDuplicate, disabled: !canDuplicate, title: pointer ? (canDuplicate ? t.topBar.duplicate : t.topBar.templateNoDuplicate) : undefined, "aria-label": t.commands.duplicate, children: _jsx(PiCopy, { size: iconSize, "aria-hidden": true }) }), pointer ? (deleteButton) : isLocked && onToggleLock ? (_jsx("button", { type: "button", className: btn, onClick: onToggleLock, "aria-label": t.contextMenu.unlock, children: _jsx(PiLockSimpleOpen, { size: iconSize, "aria-hidden": true }) })) : (deleteButton), onFlip && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: btn, onClick: () => onFlip('x'), "aria-label": CANVAS_COMMANDS.flipHorizontal.label, children: _jsx(PiFlipHorizontal, { size: iconSize, "aria-hidden": true }) }), _jsx("button", { type: "button", className: btn, onClick: () => onFlip('y'), "aria-label": CANVAS_COMMANDS.flipVertical.label, children: _jsx(PiFlipVertical, { size: iconSize, "aria-hidden": true }) })] })), onMore && (_jsx("button", { type: "button", className: btn, onClick: (e) => onMore(e.currentTarget), "aria-haspopup": pointer ? 'menu' : 'dialog', title: pointer ? t.shell.moreOptions : undefined, "aria-label": t.shell.moreOptions, children: _jsx(PiDotsThreeBold, { size: iconSize, "aria-hidden": true }) }))] }), document.body);
|
|
123
|
+
return createPortal(_jsxs("div", { ...EDITOR_SCOPE, ref: pillRef, onKeyDown: onKeyDown, onFocus: onFocus, role: "toolbar", "aria-label": t.common.element, style: { top, left }, className: cn('fixed z-[110] flex items-center gap-0.5 rounded-full border border-[var(--editor-border-soft)] bg-[var(--editor-surface)] shadow-[0_2px_8px_rgba(0,0,0,0.12)]', pointer ? 'p-0.5' : 'px-1'), children: [pointer && onToggleLock && (_jsx("button", { type: "button", className: btn, onClick: onToggleLock, "aria-pressed": isLocked, title: isLocked ? t.topBar.unlockHint : t.topBar.lockHint, "aria-label": lockLabel, children: isLocked ? (_jsx(PiLockSimple, { size: iconSize, "aria-hidden": true })) : (_jsx(PiLockSimpleOpen, { size: iconSize, "aria-hidden": true })) })), _jsx("button", { type: "button", className: btn, onClick: onDuplicate, disabled: !canDuplicate, title: pointer ? (canDuplicate ? t.topBar.duplicate : t.topBar.templateNoDuplicate) : undefined, "aria-label": t.commands.duplicate, children: _jsx(PiCopy, { size: iconSize, "aria-hidden": true }) }), pointer ? (deleteButton) : isLocked && onToggleLock ? (_jsx("button", { type: "button", className: btn, onClick: onToggleLock, "aria-label": t.contextMenu.unlock, children: _jsx(PiLockSimpleOpen, { size: iconSize, "aria-hidden": true }) })) : (deleteButton), onFlip && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: btn, onClick: () => onFlip('x'), "aria-label": CANVAS_COMMANDS.flipHorizontal.label, children: _jsx(PiFlipHorizontal, { size: iconSize, "aria-hidden": true }) }), _jsx("button", { type: "button", className: btn, onClick: () => onFlip('y'), "aria-label": CANVAS_COMMANDS.flipVertical.label, children: _jsx(PiFlipVertical, { size: iconSize, "aria-hidden": true }) })] })), onMore && (_jsx("button", { type: "button", className: btn, onClick: (e) => onMore(e.currentTarget), "aria-haspopup": pointer ? 'menu' : 'dialog', title: pointer ? t.shell.moreOptions : undefined, "aria-label": t.shell.moreOptions, children: _jsx(PiDotsThreeBold, { size: iconSize, "aria-hidden": true }) }))] }), document.body);
|
|
123
124
|
}
|
|
@@ -11,6 +11,7 @@ import { KEEP_EDITING_ATTR } from '@ggraphic/editor/utils/keyboardOwnership';
|
|
|
11
11
|
import { brandColors } from '../utils/colorOptions.js';
|
|
12
12
|
import { defaultTextMarker, markerSwatches } from '../utils/markerColors.js';
|
|
13
13
|
import { CustomColorSwatch } from './CustomColorSwatch.js';
|
|
14
|
+
import { EDITOR_SCOPE } from '../ui/editorScope.js';
|
|
14
15
|
// Die Kontextleiste übernimmt die Maße ihrer Nachbarn (`ICON_BTN` in
|
|
15
16
|
// ContextControls), damit die Gruppe nicht aus der Reihe fällt.
|
|
16
17
|
const BUTTON_CLASS = {
|
|
@@ -34,8 +35,12 @@ export function TextFormatButtons({ state, commands, marks, variant = 'floating'
|
|
|
34
35
|
const m = useMessages().textFormat;
|
|
35
36
|
const brand = useDocumentBrand();
|
|
36
37
|
const { ref: rovingRef, ...rovingHandlers } = roving;
|
|
38
|
+
const boldHidden = marks.bold && state.italic && !marks.boldItalic;
|
|
37
39
|
useImperativeHandle(toolbarRef, () => rovingRef.current, [rovingRef]);
|
|
38
|
-
return (_jsxs("div", { ref: rovingRef, ...rovingHandlers, [KEEP_EDITING_ATTR]: '', role: "toolbar", "aria-label": m.toolbar, className: GROUP_CLASS[variant], children: [marks.bold && (_jsx(ToolbarButton, { onClick: commands.toggleBold,
|
|
40
|
+
return (_jsxs("div", { ref: rovingRef, ...rovingHandlers, [KEEP_EDITING_ATTR]: '', role: "toolbar", "aria-label": m.toolbar, className: GROUP_CLASS[variant], children: [marks.bold && (_jsx(ToolbarButton, { onClick: commands.toggleBold,
|
|
41
|
+
// Kursiv schlägt Fett, wo es keinen fett-kursiven Schnitt gibt: der Knopf
|
|
42
|
+
// zeigte sonst „gedrückt", der Text bliebe aber nur kursiv.
|
|
43
|
+
isActive: state.bold && !boldHidden, disabled: boldHidden, label: boldHidden ? m.boldNeedsItalicCut : m.bold, variant: variant, children: _jsx(FiBold, {}) })), marks.italic && (_jsx(ToolbarButton, { onClick: commands.toggleItalic, isActive: state.italic, label: m.italic, variant: variant, children: _jsx(FiItalic, {}) })), _jsx(ToolbarButton, { onClick: commands.toggleUnderline, isActive: state.underline, label: m.underline, variant: variant, children: _jsx(FiUnderline, {}) }), _jsx(MarkColorButton, { label: m.accent, icon: _jsx(MdHighlight, {}), variant: variant, isActive: state.accent, color: state.accentColor, presets: brandColors(brand), hasTemplate: !!marks.accent, onPick: commands.setAccent, onPreview: commands.previewAccent, onRemove: commands.removeAccent, onColorFieldBlur: onColorFieldBlur }), _jsx(MarkColorButton, { label: m.marker, icon: _jsx(MdBorderColor, {}), variant: variant, isActive: state.marker, color: state.markerColor ?? (marks.marker ? null : defaultTextMarker(brand).fill), presets: markerColorPresets(brand), hasTemplate: !!marks.marker, onPick: commands.setMarker, onPreview: commands.previewMarker, onRemove: commands.removeMarker, onColorFieldBlur: onColorFieldBlur }), _jsx(ToolbarButton, { onClick: commands.toggleBulletList, isActive: state.bulletList, label: m.bulletList, variant: variant, children: _jsx(FiList, {}) }), _jsx(ToolbarButton, { onClick: commands.toggleOrderedList, isActive: state.orderedList, disabled: orderedListDisabled, label: m.orderedList, variant: variant, children: _jsx(MdFormatListNumbered, {}) })] }));
|
|
39
44
|
}
|
|
40
45
|
/** The marker boxes first, then the brand colours that are not among them. */
|
|
41
46
|
const markerColorPresets = (pack) => {
|
|
@@ -93,7 +98,7 @@ function MarkColorButton({ label, icon, variant, isActive, color, presets, hasTe
|
|
|
93
98
|
setPosition(null);
|
|
94
99
|
};
|
|
95
100
|
return (_jsxs("div", { ref: rootRef, className: "relative", children: [_jsx(ToolbarButton, { onClick: toggle, isActive: isActive, label: label, variant: variant, children: _jsxs("span", { className: "flex flex-col items-center", children: [icon, _jsx("span", { className: "mt-px h-[3px] w-3.5 rounded-[1px]", style: { backgroundColor: color ?? 'currentColor' } })] }) }), position &&
|
|
96
|
-
createPortal(_jsxs("div", { ref: popoverRef, [KEEP_EDITING_ATTR]: '', role: "dialog", "aria-label": m.textFormat.colorOf(label), style: { ...position, width: POPOVER_WIDTH }, className: "fixed z-[10001] flex flex-col gap-2 rounded-md border border-[var(--editor-border)] bg-[var(--editor-surface)] p-2 shadow-lg", children: [_jsx("div", { className: "grid grid-cols-6 gap-1.5", children: presets.map((preset) => {
|
|
101
|
+
createPortal(_jsxs("div", { ...EDITOR_SCOPE, ref: popoverRef, [KEEP_EDITING_ATTR]: '', role: "dialog", "aria-label": m.textFormat.colorOf(label), style: { ...position, width: POPOVER_WIDTH }, className: "fixed z-[10001] flex flex-col gap-2 rounded-md border border-[var(--editor-border)] bg-[var(--editor-surface)] p-2 shadow-lg", children: [_jsx("div", { className: "grid grid-cols-6 gap-1.5", children: presets.map((preset) => {
|
|
97
102
|
// Der Text schreibt Farben in Großbuchstaben, die Marke vielleicht nicht.
|
|
98
103
|
const picked = isActive && color?.toLowerCase() === preset.value.toLowerCase();
|
|
99
104
|
return (_jsx("button", { type: "button", onMouseDown: keepSelection, title: preset.name, "aria-label": preset.name, "aria-pressed": picked, className: clsx(SWATCH_CLASS, picked && 'outline-2 outline-offset-1 outline-[var(--editor-active-fg)]'), style: { backgroundColor: preset.value }, onClick: () => pick(preset.value) }, preset.id));
|
package/dist/i18n/de.d.ts
CHANGED
|
@@ -139,6 +139,7 @@ export declare const de: {
|
|
|
139
139
|
textFormat: {
|
|
140
140
|
toolbar: string;
|
|
141
141
|
bold: string;
|
|
142
|
+
boldNeedsItalicCut: string;
|
|
142
143
|
italic: string;
|
|
143
144
|
underline: string;
|
|
144
145
|
accent: string;
|
|
@@ -776,6 +777,17 @@ export declare const de: {
|
|
|
776
777
|
impressumSubmit: string;
|
|
777
778
|
};
|
|
778
779
|
};
|
|
780
|
+
/** The tabs of a free page (`createPageConfig`). */
|
|
781
|
+
pageTabs: {
|
|
782
|
+
text: string;
|
|
783
|
+
textAriaLabel: string;
|
|
784
|
+
elements: string;
|
|
785
|
+
elementsAriaLabel: string;
|
|
786
|
+
uploads: string;
|
|
787
|
+
uploadsAriaLabel: string;
|
|
788
|
+
tools: string;
|
|
789
|
+
toolsAriaLabel: string;
|
|
790
|
+
};
|
|
779
791
|
topBar: {
|
|
780
792
|
cropAction: string;
|
|
781
793
|
aiTemplate: string;
|
package/dist/i18n/de.js
CHANGED
|
@@ -140,6 +140,7 @@ export const de = {
|
|
|
140
140
|
textFormat: {
|
|
141
141
|
toolbar: 'Textformatierung',
|
|
142
142
|
bold: 'Fett (⌘B)',
|
|
143
|
+
boldNeedsItalicCut: 'Fett – diese Schrift hat keinen fett-kursiven Schnitt',
|
|
143
144
|
italic: 'Kursiv (⌘I)',
|
|
144
145
|
underline: 'Unterstrichen (⌘U)',
|
|
145
146
|
accent: 'Akzent',
|
|
@@ -841,6 +842,17 @@ export const de = {
|
|
|
841
842
|
impressumSubmit: 'Übernehmen',
|
|
842
843
|
},
|
|
843
844
|
},
|
|
845
|
+
/** The tabs of a free page (`createPageConfig`). */
|
|
846
|
+
pageTabs: {
|
|
847
|
+
text: 'Text',
|
|
848
|
+
textAriaLabel: 'Text: Text hinzufügen und bearbeiten',
|
|
849
|
+
elements: 'Elemente',
|
|
850
|
+
elementsAriaLabel: 'Elemente: Formen, Icons, Illustrationen und Emoji',
|
|
851
|
+
uploads: 'Uploads',
|
|
852
|
+
uploadsAriaLabel: 'Uploads: deine eigenen Bilder',
|
|
853
|
+
tools: 'Werkzeuge',
|
|
854
|
+
toolsAriaLabel: 'Werkzeuge: QR-Code, Blob, Verlaufstext und Text auf einem Pfad',
|
|
855
|
+
},
|
|
844
856
|
topBar: {
|
|
845
857
|
cropAction: 'Zuschneiden',
|
|
846
858
|
aiTemplate: 'Vorlage',
|
package/dist/i18n/en.js
CHANGED
|
@@ -129,6 +129,7 @@ export const en = {
|
|
|
129
129
|
textFormat: {
|
|
130
130
|
toolbar: 'Text formatting',
|
|
131
131
|
bold: 'Bold (⌘B)',
|
|
132
|
+
boldNeedsItalicCut: 'Bold – this font has no bold italic cut',
|
|
132
133
|
italic: 'Italic (⌘I)',
|
|
133
134
|
underline: 'Underline (⌘U)',
|
|
134
135
|
accent: 'Accent',
|
|
@@ -829,6 +830,16 @@ export const en = {
|
|
|
829
830
|
impressumSubmit: 'Apply',
|
|
830
831
|
},
|
|
831
832
|
},
|
|
833
|
+
pageTabs: {
|
|
834
|
+
text: 'Text',
|
|
835
|
+
textAriaLabel: 'Text: add and edit text',
|
|
836
|
+
elements: 'Elements',
|
|
837
|
+
elementsAriaLabel: 'Elements: shapes, icons, illustrations and emoji',
|
|
838
|
+
uploads: 'Uploads',
|
|
839
|
+
uploadsAriaLabel: 'Uploads: your own images',
|
|
840
|
+
tools: 'Tools',
|
|
841
|
+
toolsAriaLabel: 'Tools: QR code, blob, gradient text and text on a path',
|
|
842
|
+
},
|
|
832
843
|
topBar: {
|
|
833
844
|
cropAction: 'Crop',
|
|
834
845
|
aiTemplate: 'Template',
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a free page can do with its elements: texts, shapes, icons, emoji,
|
|
3
|
+
* illustrations, placed images and the background colour. The editor calls these by name
|
|
4
|
+
* (`OptionalCanvasActions`): the canvas for moves and edits, the sidebar
|
|
5
|
+
* sections for adding, the delete key for removing (`utils/elementKinds.ts`).
|
|
6
|
+
*
|
|
7
|
+
* Every action is one user intent and records one history entry.
|
|
8
|
+
*/
|
|
9
|
+
import { type BindingRef, type FontRole } from '@ggraphic/core';
|
|
10
|
+
import { type LiftedBlock } from '@ggraphic/editor/blocks/liftedBlock';
|
|
11
|
+
import { type IconState } from '@ggraphic/editor/configs/factory/baseTypes';
|
|
12
|
+
import { type AdditionalText } from '@ggraphic/editor/configs/types';
|
|
13
|
+
import { type TextPreview } from '@ggraphic/editor/hooks/useCanvasElementHandlers';
|
|
14
|
+
import { type AssetInstance } from '@ggraphic/editor/utils/canvasAssets';
|
|
15
|
+
import { type ExternalIconPayload } from '@ggraphic/editor/utils/externalIcons';
|
|
16
|
+
import { type IllustrationInstance } from '@ggraphic/editor/utils/illustrations/types';
|
|
17
|
+
import { type ShapeInstance, type ShapeType } from '@ggraphic/editor/utils/shapes';
|
|
18
|
+
import { type ElementPlacement, type UserImageInstance, type UserImagePlacement } from '@ggraphic/editor/utils/userImageUtils';
|
|
19
|
+
import { type PageState } from './pageState.js';
|
|
20
|
+
import { type TemplateLookup } from './slotBudgets.js';
|
|
21
|
+
type SetState = (partial: Partial<PageState> | ((prev: PageState) => PageState)) => void;
|
|
22
|
+
type SaveHistory = (state?: PageState) => void;
|
|
23
|
+
/**
|
|
24
|
+
* The actions of a `width` × `height` page. `templateOf` is the host's catalogue: a text on a page
|
|
25
|
+
* made from one of its templates fits within the line limit of its slot.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createPageActions(getState: () => PageState, setState: SetState, saveToHistory: SaveHistory, debouncedSaveToHistory: SaveHistory, width: number, height: number, templateOf?: TemplateLookup): {
|
|
28
|
+
addHeader: () => void;
|
|
29
|
+
addSubheader: () => void;
|
|
30
|
+
addText: () => void;
|
|
31
|
+
addBodyTextWithContent: (content: string) => void;
|
|
32
|
+
updateAdditionalText: (id: string, partial: Partial<AdditionalText>) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Sets the font of a free text to a brand role (`fontRoleOptions`): the family and the binding
|
|
35
|
+
* to the role are written together, so the text keeps following the role when the brand changes
|
|
36
|
+
* (a family set without the binding would lose it on the next rebind). One history step; the
|
|
37
|
+
* size is refitted to the new font and the plates that hug the text follow.
|
|
38
|
+
*/
|
|
39
|
+
setAdditionalTextFontRole: (id: string, role: FontRole) => void;
|
|
40
|
+
/**
|
|
41
|
+
* How the page will look once a text edit is committed, while it is still being typed: the
|
|
42
|
+
* size the draft fits at and the plates that hug it. A function of the committed page that
|
|
43
|
+
* changes and records nothing; the canvas draws the result over the page until the edit ends,
|
|
44
|
+
* and the commit (`updateAdditionalText`) is what writes. Null for a text that is gone.
|
|
45
|
+
*/
|
|
46
|
+
previewAdditionalText: (id: string, draft: string) => TextPreview | null;
|
|
47
|
+
removeAdditionalText: (id: string) => void;
|
|
48
|
+
addShape: (type: ShapeType, color?: string, options?: ElementPlacement) => void;
|
|
49
|
+
updateShape: (id: string, partial: Partial<ShapeInstance>) => void;
|
|
50
|
+
removeShape: (id: string) => void;
|
|
51
|
+
toggleIcon: (id: string, selected: boolean, options?: ElementPlacement, external?: ExternalIconPayload) => void;
|
|
52
|
+
updateIcon: (id: string, partial: Partial<IconState>) => void;
|
|
53
|
+
addAsset: (assetId: string, options?: ElementPlacement) => void;
|
|
54
|
+
updateAsset: (id: string, partial: Partial<AssetInstance>) => void;
|
|
55
|
+
removeAsset: (id: string) => void;
|
|
56
|
+
addIllustration: (id: string, options?: ElementPlacement) => void;
|
|
57
|
+
updateIllustration: (id: string, partial: Partial<IllustrationInstance>) => void;
|
|
58
|
+
removeIllustration: (id: string) => void;
|
|
59
|
+
addUserImageFromUrl: (url: string, fileName: string, options?: UserImagePlacement) => void;
|
|
60
|
+
updateUserImage: (id: string, partial: Partial<UserImageInstance>) => void;
|
|
61
|
+
removeUserImage: (id: string) => void;
|
|
62
|
+
insertBlock: (block: LiftedBlock) => void;
|
|
63
|
+
setBackgroundColor: (color: string, ref?: BindingRef) => void;
|
|
64
|
+
};
|
|
65
|
+
export type PageActions = ReturnType<typeof createPageActions>;
|
|
66
|
+
export {};
|