@signalsafe/content-editor-react 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/README.md +105 -2
- package/dist/BootstrapBlockRenderer.d.ts +10 -0
- package/dist/BootstrapBlockRenderer.js +256 -0
- package/dist/BootstrapInlineCanvasEditor.d.ts +11 -0
- package/dist/BootstrapInlineCanvasEditor.js +38 -0
- package/dist/BootstrapInlineText.d.ts +9 -0
- package/dist/BootstrapInlineText.js +121 -0
- package/dist/BootstrapNavigationBlocks.d.ts +13 -0
- package/dist/BootstrapNavigationBlocks.js +33 -0
- package/dist/BootstrapProgressGroup.d.ts +11 -0
- package/dist/BootstrapProgressGroup.js +13 -0
- package/dist/BootstrapProperties.d.ts +15 -0
- package/dist/BootstrapProperties.js +217 -0
- package/dist/CanvasTheme.d.ts +25 -0
- package/dist/CanvasTheme.js +34 -0
- package/dist/CollectionRowActions.d.ts +19 -0
- package/dist/CollectionRowActions.js +9 -0
- package/dist/ColorModeSelect.d.ts +9 -0
- package/dist/ColorModeSelect.js +28 -0
- package/dist/ColumnContent.d.ts +6 -0
- package/dist/ColumnContent.js +6 -0
- package/dist/ComponentPicker.d.ts +10 -0
- package/dist/ComponentPicker.js +22 -0
- package/dist/ComponentPickerIcon.d.ts +3 -0
- package/dist/ComponentPickerIcon.js +52 -0
- package/dist/ContentEditor.d.ts +16 -0
- package/dist/ContentEditor.js +73 -0
- package/dist/ContentImage.d.ts +16 -0
- package/dist/ContentImage.js +45 -0
- package/dist/ContentInteractionProvider.d.ts +21 -0
- package/dist/ContentInteractionProvider.js +102 -0
- package/dist/ContentKeyboardHelp.d.ts +4 -0
- package/dist/ContentKeyboardHelp.js +8 -0
- package/dist/ContentOutline.d.ts +20 -0
- package/dist/ContentOutline.js +71 -0
- package/dist/ContentRuntime.d.ts +28 -0
- package/dist/ContentRuntime.js +13 -0
- package/dist/EditorActionIcon.d.ts +18 -0
- package/dist/EditorActionIcon.js +32 -0
- package/dist/EditorCanvasScroll.d.ts +6 -0
- package/dist/EditorCanvasScroll.js +82 -0
- package/dist/EditorCanvasSettings.d.ts +5 -0
- package/dist/EditorCanvasSettings.js +21 -0
- package/dist/EditorCanvasToolbar.d.ts +16 -0
- package/dist/EditorCanvasToolbar.js +22 -0
- package/dist/EditorCollectionAdd.d.ts +6 -0
- package/dist/EditorCollectionAdd.js +6 -0
- package/dist/EditorCollectionRow.d.ts +18 -0
- package/dist/EditorCollectionRow.js +6 -0
- package/dist/EditorCommandBar.d.ts +7 -0
- package/dist/EditorCommandBar.js +9 -0
- package/dist/EditorContainerFields.d.ts +17 -0
- package/dist/EditorContainerFields.js +27 -0
- package/dist/EditorHistoryControls.d.ts +8 -0
- package/dist/EditorHistoryControls.js +6 -0
- package/dist/EditorIssuesPanel.d.ts +5 -0
- package/dist/EditorIssuesPanel.js +6 -0
- package/dist/EditorLayoutMenu.d.ts +23 -0
- package/dist/EditorLayoutMenu.js +13 -0
- package/dist/EditorMenuChoice.d.ts +8 -0
- package/dist/EditorMenuChoice.js +6 -0
- package/dist/EditorPanel.d.ts +10 -0
- package/dist/EditorPanel.js +12 -0
- package/dist/EditorPreviewToggle.d.ts +6 -0
- package/dist/EditorPreviewToggle.js +6 -0
- package/dist/EditorSidebarLayout.d.ts +8 -0
- package/dist/EditorSidebarLayout.js +29 -0
- package/dist/EditorStatusBar.d.ts +5 -0
- package/dist/EditorStatusBar.js +8 -0
- package/dist/EditorStatusBarContext.d.ts +2 -0
- package/dist/EditorStatusBarContext.js +3 -0
- package/dist/EditorSubmenu.d.ts +18 -0
- package/dist/EditorSubmenu.js +74 -0
- package/dist/EditorTabs.d.ts +9 -0
- package/dist/EditorTabs.js +28 -0
- package/dist/EditorTemplateMenu.d.ts +12 -0
- package/dist/EditorTemplateMenu.js +7 -0
- package/dist/EditorViewportSelect.d.ts +30 -0
- package/dist/EditorViewportSelect.js +17 -0
- package/dist/EditorWorkflowActions.d.ts +12 -0
- package/dist/EditorWorkflowActions.js +6 -0
- package/dist/EmptyContent.d.ts +6 -0
- package/dist/EmptyContent.js +18 -0
- package/dist/InlineCanvasEditor.d.ts +7 -0
- package/dist/InlineCanvasEditor.js +12 -0
- package/dist/InteractiveBootstrapBlocks.d.ts +17 -0
- package/dist/InteractiveBootstrapBlocks.js +434 -0
- package/dist/JsonEditor.css +163 -0
- package/dist/JsonTextEditor.d.ts +11 -0
- package/dist/JsonTextEditor.js +70 -0
- package/dist/JsonViewer.d.ts +15 -0
- package/dist/JsonViewer.js +109 -0
- package/dist/LayoutPresets.d.ts +8 -0
- package/dist/LayoutPresets.js +66 -0
- package/dist/LayoutPropertyFields.d.ts +8 -0
- package/dist/LayoutPropertyFields.js +43 -0
- package/dist/MarkdownEditor.d.ts +13 -0
- package/dist/MarkdownEditor.js +82 -0
- package/dist/PracticeInputBlock.d.ts +12 -0
- package/dist/PracticeInputBlock.js +21 -0
- package/dist/ReadableButton.d.ts +5 -0
- package/dist/ReadableButton.js +20 -0
- package/dist/ReadableDropdownSurface.d.ts +6 -0
- package/dist/ReadableDropdownSurface.js +16 -0
- package/dist/ReadableDropdownToggle.d.ts +2 -0
- package/dist/ReadableDropdownToggle.js +14 -0
- package/dist/ReadableFormSelect.d.ts +3 -0
- package/dist/ReadableFormSelect.js +10 -0
- package/dist/ReorderHandle.d.ts +15 -0
- package/dist/ReorderHandle.js +31 -0
- package/dist/ReorderTarget.d.ts +10 -0
- package/dist/ReorderTarget.js +7 -0
- package/dist/SpacingEditor.d.ts +9 -0
- package/dist/SpacingEditor.js +53 -0
- package/dist/authoringActions.d.ts +18 -0
- package/dist/authoringActions.js +172 -0
- package/dist/authoringText.d.ts +4 -0
- package/dist/authoringText.js +45 -0
- package/dist/authoringUuid.d.ts +2 -0
- package/dist/authoringUuid.js +11 -0
- package/dist/bootstrapFamilies.d.ts +10 -0
- package/dist/bootstrapFamilies.js +151 -0
- package/dist/bootstrapGridImport.d.ts +8 -0
- package/dist/bootstrapGridImport.js +122 -0
- package/dist/bootstrapGridMigration.d.ts +3 -0
- package/dist/bootstrapGridMigration.js +27 -0
- package/dist/bootstrapRegistry.d.ts +69 -0
- package/dist/bootstrapRegistry.js +966 -0
- package/dist/canvasPreferences.d.ts +27 -0
- package/dist/canvasPreferences.js +28 -0
- package/dist/collectionNavigation.d.ts +20 -0
- package/dist/collectionNavigation.js +38 -0
- package/dist/componentPickerFamilies.d.ts +5 -0
- package/dist/componentPickerFamilies.js +40 -0
- package/dist/componentPolicy.d.ts +31 -0
- package/dist/componentPolicy.js +25 -0
- package/dist/componentValidation.d.ts +23707 -0
- package/dist/componentValidation.js +7 -0
- package/dist/content-editor.css +584 -0
- package/dist/content-layout.css +597 -0
- package/dist/contentContainment.d.ts +4 -0
- package/dist/contentContainment.js +117 -0
- package/dist/contentCssPath.d.ts +5 -0
- package/dist/contentCssPath.js +63 -0
- package/dist/contentEditingCommands.d.ts +35 -0
- package/dist/contentEditingCommands.js +69 -0
- package/dist/contentInsertion.d.ts +3 -0
- package/dist/contentInsertion.js +16 -0
- package/dist/contentModel.d.ts +3 -0
- package/dist/contentModel.js +1 -0
- package/dist/contentTreeValidation.d.ts +8 -0
- package/dist/contentTreeValidation.js +211 -0
- package/dist/contracts/semantics.gen.d.ts +2 -0
- package/dist/contracts/semantics.gen.js +3 -0
- package/dist/contracts/types.gen.d.ts +3741 -0
- package/dist/contracts/types.gen.js +1 -0
- package/dist/contracts/zod.gen.d.ts +62365 -0
- package/dist/contracts/zod.gen.js +3036 -0
- package/dist/controlBackgroundIconContrast.d.ts +3 -0
- package/dist/controlBackgroundIconContrast.js +60 -0
- package/dist/dropdownContrast.d.ts +5 -0
- package/dist/dropdownContrast.js +34 -0
- package/dist/editor-ui-colors.css +40 -0
- package/dist/editorThemes.d.ts +10 -0
- package/dist/editorThemes.js +12 -0
- package/dist/inlineMarkup.d.ts +6 -0
- package/dist/inlineMarkup.js +171 -0
- package/dist/layout.d.ts +17 -0
- package/dist/layout.js +37 -0
- package/dist/nestedComponentLabel.d.ts +2 -0
- package/dist/nestedComponentLabel.js +17 -0
- package/dist/responsiveLayout.d.ts +51 -0
- package/dist/responsiveLayout.js +97 -0
- package/dist/slideAppearance.d.ts +25 -0
- package/dist/slideAppearance.js +283 -0
- package/dist/source-manifest.json +105 -0
- package/dist/spacingShorthand.d.ts +12 -0
- package/dist/spacingShorthand.js +47 -0
- package/dist/themes/canvas-themes.css +131 -0
- package/dist/useCanvasSelectionScroll.d.ts +3 -0
- package/dist/useCanvasSelectionScroll.js +51 -0
- package/dist/useContentHistory.d.ts +40 -0
- package/dist/useContentHistory.js +42 -0
- package/dist/useContentReorderTarget.d.ts +6 -0
- package/dist/useContentReorderTarget.js +44 -0
- package/dist/useContentSelection.d.ts +10 -0
- package/dist/useContentSelection.js +23 -0
- package/dist/useDropdownContrast.d.ts +16 -0
- package/dist/useDropdownContrast.js +145 -0
- package/dist/useEditorControlContrast.d.ts +3 -0
- package/dist/useEditorControlContrast.js +188 -0
- package/dist/useSiteThemeStyles.d.ts +3 -0
- package/dist/useSiteThemeStyles.js +30 -0
- package/dist/useValidationFocus.d.ts +5 -0
- package/dist/useValidationFocus.js +17 -0
- package/package.json +74 -5
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { slideAppearance, spacingStyles } from './slideAppearance.js';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { Image } from 'react-bootstrap';
|
|
5
|
+
export const IMAGE_DEFAULT_PROPS = {
|
|
6
|
+
src: '',
|
|
7
|
+
alt: '',
|
|
8
|
+
caption: '',
|
|
9
|
+
size: 'full',
|
|
10
|
+
alignment: 'center',
|
|
11
|
+
};
|
|
12
|
+
const IMAGE_WIDTHS = { small: '25%', medium: '50%', large: '75%', full: '100%' };
|
|
13
|
+
const IMAGE_ALIGNMENT = { start: 'me-auto', center: 'mx-auto', end: 'ms-auto' };
|
|
14
|
+
/** Sources remain editable text in draft JSON; only supported URLs reach an img. */
|
|
15
|
+
export function imageSource(value) {
|
|
16
|
+
if (!value || /[\\\s]/.test(value))
|
|
17
|
+
return null;
|
|
18
|
+
if (!/^https?:\/\//i.test(value) && !/^\/[^/]/.test(value))
|
|
19
|
+
return null;
|
|
20
|
+
try {
|
|
21
|
+
const url = new URL(value, 'https://lesson.invalid');
|
|
22
|
+
return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password
|
|
23
|
+
? value
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function imageFitClass(objectFit) {
|
|
31
|
+
return objectFit ? `object-fit-${objectFit}` : '';
|
|
32
|
+
}
|
|
33
|
+
function imagePlaceholder(src, source) {
|
|
34
|
+
if (!src)
|
|
35
|
+
return 'Choose an image';
|
|
36
|
+
if (source)
|
|
37
|
+
return 'Image could not be loaded';
|
|
38
|
+
return 'Enter an HTTP(S) URL or site-relative path';
|
|
39
|
+
}
|
|
40
|
+
/** Canvas and learner playback deliberately share this exact presentation. */
|
|
41
|
+
export function ContentImage({ src, alt, caption, size, alignment, objectFit, aspectRatio, thumbnail, rounded, roundedCircle, surfaceProps, elementRef, objectPosition, ...appearance }) {
|
|
42
|
+
const [failedSource, setFailedSource] = useState(null);
|
|
43
|
+
const source = imageSource(src);
|
|
44
|
+
return (_jsxs("figure", { ...surfaceProps, ref: elementRef, "aria-label": appearance.ariaLabel ?? surfaceProps?.["aria-label"], className: `lesson-image figure d-block ${IMAGE_ALIGNMENT[alignment]} ${slideAppearance(appearance)} ${surfaceProps?.className ?? ""}`, style: { ...surfaceProps?.style, width: IMAGE_WIDTHS[size], ...spacingStyles(appearance) }, children: [source && failedSource !== src ? (_jsx(Image, { rounded: Boolean(rounded && rounded !== "0"), roundedCircle: roundedCircle === true || rounded === "circle", className: `figure-img img-fluid w-100 ${thumbnail ? 'img-thumbnail' : ''} ${imageFitClass(objectFit)} ${rounded ? `rounded-${rounded}` : ""}`, style: { objectPosition: objectPosition ?? undefined, ...(aspectRatio ? { aspectRatio: aspectRatio.replace('x', ' / '), objectFit: objectFit ?? 'cover' } : {}) }, src: source, alt: alt, referrerPolicy: "no-referrer", decoding: "async", onError: () => setFailedSource(src) }, src)) : (_jsxs("div", { className: "lesson-image-placeholder bg-body-tertiary border rounded text-body-secondary p-3 text-center", role: "img", "aria-label": alt || 'Image placeholder', children: [_jsx("i", { className: "bi bi-image d-block fs-2 mb-2", "aria-hidden": "true" }), _jsx("span", { children: imagePlaceholder(src, source) })] })), caption && _jsx("figcaption", { className: "figure-caption", children: caption })] }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ContentAction } from './ContentRuntime.js';
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
type InteractionBlock = Readonly<{
|
|
4
|
+
type?: string;
|
|
5
|
+
props: Readonly<{
|
|
6
|
+
id: string;
|
|
7
|
+
parentId?: string | null;
|
|
8
|
+
eventKey?: string | null;
|
|
9
|
+
}>;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function ContentInteractionProvider({ children, authoring, resetKey, playbackActive, onAction, canExecute, blocks, selectedId, }: Readonly<{
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
authoring?: boolean;
|
|
14
|
+
resetKey?: string | number;
|
|
15
|
+
playbackActive?: boolean;
|
|
16
|
+
onAction?: (action: ContentAction) => void;
|
|
17
|
+
canExecute?: (action: ContentAction) => boolean;
|
|
18
|
+
blocks?: readonly InteractionBlock[];
|
|
19
|
+
selectedId?: string;
|
|
20
|
+
}>): import("react").JSX.Element;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ContentRuntimeProvider } from './ContentRuntime.js';
|
|
3
|
+
import { useState, useEffect, useRef, useId, useMemo, useCallback, } from "react";
|
|
4
|
+
export function ContentInteractionProvider({ children, authoring = false, resetKey, playbackActive = false, onAction, canExecute, blocks, selectedId, }) {
|
|
5
|
+
return (_jsx(InteractionSession, { resetKey: resetKey, authoring: authoring, playbackActive: playbackActive, onAction: onAction, canExecute: canExecute, blocks: blocks, selectedId: selectedId, children: children }));
|
|
6
|
+
}
|
|
7
|
+
function InteractionSession({ children, authoring, playbackActive, resetKey, onAction, canExecute, blocks, selectedId, }) {
|
|
8
|
+
const [state, setState] = useState(() => Object.fromEntries((blocks ?? []).flatMap((block) => "defaultOpen" in block.props &&
|
|
9
|
+
typeof block.props.defaultOpen === "boolean"
|
|
10
|
+
? [[block.props.id, { open: block.props.defaultOpen }]]
|
|
11
|
+
: [])));
|
|
12
|
+
const previousReveal = useRef();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!authoring || !selectedId) {
|
|
15
|
+
previousReveal.current = undefined;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const ancestors = [];
|
|
19
|
+
const visited = new Set();
|
|
20
|
+
let item = blocks?.find(block => block.props.id === selectedId);
|
|
21
|
+
while (item && !visited.has(item.props.id)) {
|
|
22
|
+
ancestors.push(item);
|
|
23
|
+
visited.add(item.props.id);
|
|
24
|
+
item = blocks?.find(block => block.props.id === item?.props.parentId);
|
|
25
|
+
}
|
|
26
|
+
const patches = {};
|
|
27
|
+
const revealedDropdowns = new Set(ancestors.filter(block => block.type === 'Dropdown').map(block => block.props.id));
|
|
28
|
+
for (const block of blocks ?? []) {
|
|
29
|
+
if (block.type === 'Dropdown')
|
|
30
|
+
patches[block.props.id] = { open: revealedDropdowns.has(block.props.id) };
|
|
31
|
+
}
|
|
32
|
+
for (const [index, block] of ancestors.entries()) {
|
|
33
|
+
if (!block.props.eventKey)
|
|
34
|
+
continue;
|
|
35
|
+
const ownerType = block.type === 'TabPane' ? 'TabContainer' : block.type === 'Tab' ? 'Tabs' : block.type === 'AccordionItem' ? 'Accordion' : undefined;
|
|
36
|
+
if (!ownerType)
|
|
37
|
+
continue;
|
|
38
|
+
const owner = ancestors.slice(index + 1).find(ancestor => ancestor.type === ownerType);
|
|
39
|
+
if (owner)
|
|
40
|
+
patches[owner.props.id] = { selected: block.props.eventKey };
|
|
41
|
+
}
|
|
42
|
+
// Hosts may recreate their block array when native controls select a canvas node.
|
|
43
|
+
// Reveal a selection once; rerenders must not reopen a menu the user just closed.
|
|
44
|
+
const revealKey = JSON.stringify([resetKey, selectedId, patches]);
|
|
45
|
+
if (previousReveal.current === revealKey)
|
|
46
|
+
return;
|
|
47
|
+
previousReveal.current = revealKey;
|
|
48
|
+
if (Object.keys(patches).length)
|
|
49
|
+
setState(current => ({ ...current, ...patches }));
|
|
50
|
+
}, [authoring, selectedId, blocks, resetKey]);
|
|
51
|
+
const scopeId = useId();
|
|
52
|
+
const previousReset = useRef(resetKey);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (previousReset.current === resetKey)
|
|
55
|
+
return;
|
|
56
|
+
previousReset.current = resetKey;
|
|
57
|
+
setState(Object.fromEntries((blocks ?? []).flatMap((block) => "defaultOpen" in block.props &&
|
|
58
|
+
typeof block.props.defaultOpen === "boolean"
|
|
59
|
+
? [[block.props.id, { open: block.props.defaultOpen }]]
|
|
60
|
+
: [])));
|
|
61
|
+
}, [resetKey, blocks]);
|
|
62
|
+
const update = useCallback((id, patch) => setState((current) => ({
|
|
63
|
+
...current,
|
|
64
|
+
[id]: { ...current[id], ...patch },
|
|
65
|
+
})), []);
|
|
66
|
+
const execute = useCallback((action) => {
|
|
67
|
+
if (authoring)
|
|
68
|
+
return;
|
|
69
|
+
onAction?.(action);
|
|
70
|
+
if (!action.targetId)
|
|
71
|
+
return;
|
|
72
|
+
if (action.action === "select-tab" && action.targetKey)
|
|
73
|
+
update(action.targetId, { selected: action.targetKey });
|
|
74
|
+
if (action.action === "show" ||
|
|
75
|
+
action.action === "hide" ||
|
|
76
|
+
action.action === "toggle") {
|
|
77
|
+
const id = action.targetId;
|
|
78
|
+
setState((current) => ({
|
|
79
|
+
...current,
|
|
80
|
+
[id]: {
|
|
81
|
+
...current[id],
|
|
82
|
+
open: action.action === "toggle"
|
|
83
|
+
? !(current[id]?.open ?? false)
|
|
84
|
+
: action.action === "show",
|
|
85
|
+
},
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
}, [authoring, onAction, update]);
|
|
89
|
+
const blockOrder = useMemo(() => (blocks ?? []).map((block) => block.props.id), [blocks]);
|
|
90
|
+
const value = useMemo(() => ({
|
|
91
|
+
authoring,
|
|
92
|
+
playbackActive,
|
|
93
|
+
canExecute,
|
|
94
|
+
scopeId,
|
|
95
|
+
revision: resetKey,
|
|
96
|
+
blockOrder,
|
|
97
|
+
state,
|
|
98
|
+
update,
|
|
99
|
+
execute,
|
|
100
|
+
}), [authoring, playbackActive, canExecute, scopeId, resetKey, blockOrder, state, update, execute]);
|
|
101
|
+
return (_jsx(ContentRuntimeProvider, { value: value, children: children }));
|
|
102
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { EditorActionIcon } from './EditorActionIcon.js';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { Button, Modal } from 'react-bootstrap';
|
|
5
|
+
export function ContentKeyboardHelp({ children }) {
|
|
6
|
+
const [open, setOpen] = useState(false);
|
|
7
|
+
return _jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", variant: "outline-secondary", onClick: () => setOpen(true), "aria-label": "Keyboard shortcuts", title: "Keyboard shortcuts", children: _jsx(EditorActionIcon, { action: "keyboard" }) }), _jsxs(Modal, { show: open, onHide: () => setOpen(false), "aria-labelledby": "content-keyboard-title", centered: true, scrollable: true, children: [_jsx(Modal.Header, { closeButton: true, children: _jsx(Modal.Title, { id: "content-keyboard-title", children: "Keyboard shortcuts" }) }), _jsxs(Modal.Body, { children: [_jsx("p", { children: "When a component is focused in the outline or canvas:" }), _jsxs("dl", { children: [_jsx("dt", { children: "\u2191 / \u2193 \u00B7 Home / End" }), _jsx("dd", { children: "Select the previous, next, first or last visible component." }), _jsx("dt", { children: "\u2190 / \u2192" }), _jsx("dd", { children: "Collapse or expand a container; select its parent or first child." }), _jsx("dt", { children: "Escape" }), _jsx("dd", { children: "Select its parent, or return to content properties." }), _jsx("dt", { children: "Enter / F2" }), _jsx("dd", { children: "Edit text or focus the component properties." }), _jsx("dt", { children: "Delete / Backspace" }), _jsx("dd", { children: "Remove the selected component and its children. Undo restores it." }), _jsx("dt", { children: "Ctrl / \u2318 + D" }), _jsx("dd", { children: "Duplicate the focused component and its children." }), _jsx("dt", { children: "Alt + \u2191 / \u2193" }), _jsx("dd", { children: "Reorder within the same container." })] }), children, _jsx("p", { children: "Text and form fields keep their normal editing keys. Escape exits inline editing and returns focus to the component." })] }), _jsx(Modal.Footer, { children: _jsx(Button, { onClick: () => setOpen(false), children: "Close" }) })] })] });
|
|
8
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type KeyboardEvent, type ReactNode } from 'react';
|
|
2
|
+
import type { ContentBlock } from './contentModel.js';
|
|
3
|
+
export declare function ContentOutline({ visibleBlocks, orderedBlocks, blocks, selected, selectionPath, collapsedBlocks, componentLabel, toggleBranch, selectionKey, selectBlock, moveBlock, duplicateBlock, deleteBlock, children, readOnly, componentLimit, }: Readonly<{
|
|
4
|
+
visibleBlocks: readonly ContentBlock[];
|
|
5
|
+
orderedBlocks: readonly ContentBlock[];
|
|
6
|
+
blocks: readonly ContentBlock[];
|
|
7
|
+
selected: ContentBlock | undefined;
|
|
8
|
+
selectionPath: readonly ContentBlock[];
|
|
9
|
+
collapsedBlocks: ReadonlySet<string>;
|
|
10
|
+
componentLabel: (block: ContentBlock) => string;
|
|
11
|
+
toggleBranch: (id: string) => void;
|
|
12
|
+
selectionKey: (event: KeyboardEvent<HTMLElement>, id: string) => void;
|
|
13
|
+
selectBlock: (id: string) => void;
|
|
14
|
+
moveBlock: (source: string, target: string, after?: boolean) => void;
|
|
15
|
+
duplicateBlock: (id: string) => void;
|
|
16
|
+
deleteBlock: (id: string) => void;
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
componentLimit?: number;
|
|
20
|
+
}>): import("react").JSX.Element;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { nestedComponentLabel } from './nestedComponentLabel.js';
|
|
3
|
+
import { ComponentPickerIcon } from './ComponentPickerIcon.js';
|
|
4
|
+
import { useEffect, useRef } from 'react';
|
|
5
|
+
import { ReorderTarget } from './ReorderTarget.js';
|
|
6
|
+
import { startReorder, BLOCK_DRAG_TYPE } from './ReorderHandle.js';
|
|
7
|
+
import { layoutParent as parentId, layoutAncestorIds } from './layout.js';
|
|
8
|
+
import { blockFamily } from './authoringActions.js';
|
|
9
|
+
import { EditorActionIcon } from './EditorActionIcon.js';
|
|
10
|
+
export function ContentOutline({ visibleBlocks, orderedBlocks, blocks, selected, selectionPath, collapsedBlocks, componentLabel, toggleBranch, selectionKey, selectBlock, moveBlock, duplicateBlock, deleteBlock, children, readOnly = false, componentLimit = 100, }) {
|
|
11
|
+
const outline = useRef(null);
|
|
12
|
+
const revealedId = useRef('');
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!selected) {
|
|
15
|
+
revealedId.current = '';
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (revealedId.current === selected.props.id)
|
|
19
|
+
return;
|
|
20
|
+
for (const ancestor of selectionPath) {
|
|
21
|
+
if (ancestor !== selected && collapsedBlocks.has(ancestor.props.id))
|
|
22
|
+
toggleBranch(ancestor.props.id);
|
|
23
|
+
}
|
|
24
|
+
const row = Array.from(outline.current?.querySelectorAll('[data-outline-block]') ?? [])
|
|
25
|
+
.find(element => element.dataset.outlineBlock === selected.props.id);
|
|
26
|
+
const scroller = outline.current?.closest('.editor-tree-list, .slide-tree-list');
|
|
27
|
+
if (!row)
|
|
28
|
+
return;
|
|
29
|
+
revealedId.current = selected.props.id;
|
|
30
|
+
if (!scroller)
|
|
31
|
+
return;
|
|
32
|
+
const bounds = row.getBoundingClientRect(), viewport = scroller.getBoundingClientRect();
|
|
33
|
+
if (bounds.top < viewport.top)
|
|
34
|
+
scroller.scrollTop += bounds.top - viewport.top;
|
|
35
|
+
else if (bounds.bottom > viewport.bottom)
|
|
36
|
+
scroller.scrollTop += bounds.bottom - viewport.bottom;
|
|
37
|
+
}, [selected, selectionPath, collapsedBlocks, toggleBranch, visibleBlocks]);
|
|
38
|
+
const byId = new Map(blocks.map(block => [block.props.id, block]));
|
|
39
|
+
return _jsx("div", { ref: outline, className: "content-outline editor-panel", children: _jsxs("div", { className: "editor-list-group", children: [visibleBlocks.map((block) => {
|
|
40
|
+
const index = orderedBlocks.indexOf(block);
|
|
41
|
+
const label = componentLabel(block);
|
|
42
|
+
const ancestors = layoutAncestorIds(block, blocks);
|
|
43
|
+
const ancestorLabels = ancestors.flatMap(id => {
|
|
44
|
+
const owner = byId.get(id);
|
|
45
|
+
return owner ? [componentLabel(owner)] : [];
|
|
46
|
+
});
|
|
47
|
+
const shortLabel = nestedComponentLabel(label, ancestorLabels);
|
|
48
|
+
const hasChildren = blocks.some((child) => parentId(child) === block.props.id);
|
|
49
|
+
return (_jsxs(ReorderTarget, { className: outlineRowClass(block, selected, selectionPath), type: BLOCK_DRAG_TYPE, scope: parentId(block) ?? 'root', label: `${index + 1}. ${componentLabel(block)}`, onMove: (source, after) => { if (!readOnly)
|
|
50
|
+
moveBlock(source, block.props.id, after); }, children: [hasChildren ? (_jsx("button", { type: "button", className: "editor-icon-action", style: {
|
|
51
|
+
marginLeft: `${ancestors.length * 0.75}rem`,
|
|
52
|
+
}, "aria-label": `${collapsedBlocks.has(block.props.id) ? 'Expand' : 'Collapse'} ${componentLabel(block)} ${index + 1}`, "aria-expanded": !collapsedBlocks.has(block.props.id), onClick: () => toggleBranch(block.props.id), children: _jsx(EditorActionIcon, { action: collapsedBlocks.has(block.props.id) ? 'collapse' : 'expand' }) })) : null, _jsxs("button", { type: "button", className: "block-row editor-list-item", style: {
|
|
53
|
+
paddingLeft: hasChildren
|
|
54
|
+
? '0.25rem'
|
|
55
|
+
: `${2 + ancestors.length * 0.75}rem`,
|
|
56
|
+
}, draggable: !readOnly, onDragStart: (event) => {
|
|
57
|
+
if (readOnly)
|
|
58
|
+
return;
|
|
59
|
+
startReorder(event, BLOCK_DRAG_TYPE, block.props.id, parentId(block) ?? 'root');
|
|
60
|
+
}, title: label, "aria-label": `${index + 1}. ${componentLabel(block)}`, onKeyDown: (event) => selectionKey(event, block.props.id), "data-outline-block": block.props.id, "aria-pressed": block === selected, onClick: () => selectBlock(block.props.id), children: [_jsx("span", { className: "content-outline-icon", children: _jsx(ComponentPickerIcon, { type: block.type }) }), _jsx("span", { className: "content-outline-selector text-truncate", children: shortLabel })] }), block === selected && (_jsxs("div", { className: "list-row-actions", children: [_jsx("button", { type: "button", className: "editor-icon-action", "aria-label": "Duplicate component", title: "Duplicate component", disabled: readOnly || blocks.length +
|
|
61
|
+
blockFamily(blocks, block.props.id).length >
|
|
62
|
+
componentLimit, onClick: () => duplicateBlock(block.props.id), children: _jsx(EditorActionIcon, { action: "duplicate" }) }), _jsx("button", { type: "button", className: "editor-icon-action", disabled: readOnly, "aria-label": "Delete block", title: "Delete block", onClick: () => deleteBlock(block.props.id), children: _jsx(EditorActionIcon, { action: "delete" }) })] }))] }, block.props.id));
|
|
63
|
+
}), children] }) });
|
|
64
|
+
}
|
|
65
|
+
function outlineRowClass(block, selected, path) {
|
|
66
|
+
if (block === selected)
|
|
67
|
+
return 'editor-list-row selected';
|
|
68
|
+
if (path.includes(block))
|
|
69
|
+
return 'editor-list-row selection-ancestor';
|
|
70
|
+
return 'editor-list-row';
|
|
71
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { ContentBlock } from './contentModel.js';
|
|
3
|
+
export type ContentAction = Pick<Extract<ContentBlock, {
|
|
4
|
+
type: 'Button';
|
|
5
|
+
}>['props'], 'action' | 'targetId' | 'targetKey'>;
|
|
6
|
+
export type ContentRuntime = Readonly<{
|
|
7
|
+
authoring: boolean;
|
|
8
|
+
playbackActive: boolean;
|
|
9
|
+
scopeId: string;
|
|
10
|
+
revision?: string | number;
|
|
11
|
+
blockOrder: readonly string[];
|
|
12
|
+
state: Readonly<Record<string, Readonly<{
|
|
13
|
+
open?: boolean;
|
|
14
|
+
selected?: string;
|
|
15
|
+
}>>>;
|
|
16
|
+
update: (id: string, patch: Readonly<{
|
|
17
|
+
open?: boolean;
|
|
18
|
+
selected?: string;
|
|
19
|
+
}>) => void;
|
|
20
|
+
execute: (action: ContentAction) => void;
|
|
21
|
+
canExecute?: (action: ContentAction) => boolean;
|
|
22
|
+
}>;
|
|
23
|
+
/** Hosts implement navigation and session state; Bootstrap rendering stays portable. */
|
|
24
|
+
export declare function ContentRuntimeProvider({ value, children }: Readonly<{
|
|
25
|
+
value: ContentRuntime;
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
}>): import("react").JSX.Element;
|
|
28
|
+
export declare function useContentRuntime(): ContentRuntime;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
const Runtime = createContext({
|
|
4
|
+
authoring: false, playbackActive: false, scopeId: 'content', blockOrder: [], state: {},
|
|
5
|
+
update: () => undefined, execute: () => undefined,
|
|
6
|
+
});
|
|
7
|
+
/** Hosts implement navigation and session state; Bootstrap rendering stays portable. */
|
|
8
|
+
export function ContentRuntimeProvider({ value, children }) {
|
|
9
|
+
return _jsx(Runtime.Provider, { value: value, children: children });
|
|
10
|
+
}
|
|
11
|
+
export function useContentRuntime() {
|
|
12
|
+
return useContext(Runtime);
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const paths: {
|
|
2
|
+
readonly undo: readonly ["M8 3a5 5 0 1 1-4.546 2.914.5.5 0 0 0-.908-.417A6 6 0 1 0 8 2z", "M8 4.466V.534a.25.25 0 0 0-.41-.192L5.23 2.308a.25.25 0 0 0 0 .384l2.36 1.966A.25.25 0 0 0 8 4.466"];
|
|
3
|
+
readonly redo: readonly ["M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2z", "M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466"];
|
|
4
|
+
readonly expand: readonly ["M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708"];
|
|
5
|
+
readonly collapse: readonly ["M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708"];
|
|
6
|
+
readonly grip: readonly ["M6 2a1 1 0 1 1-2 0 1 1 0 0 1 2 0m0 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0m0 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0m6-12a1 1 0 1 1-2 0 1 1 0 0 1 2 0m0 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0m0 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0"];
|
|
7
|
+
readonly keyboard: readonly ["M2 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zm0 1h12a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1m0 1h2v2H2zm3 0h2v2H5zm3 0h2v2H8zm3 0h3v2h-3zM2 8h2v2H2zm3 0h6v2H5zm7 0h2v2h-2z"];
|
|
8
|
+
readonly done: readonly ["M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-4-4a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0"];
|
|
9
|
+
readonly duplicate: readonly ["M4 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1zM2 5a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-1h1v1a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h1v1z"];
|
|
10
|
+
readonly up: readonly ["M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5"];
|
|
11
|
+
readonly down: readonly ["M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1"];
|
|
12
|
+
readonly delete: readonly ["M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0z", "M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4zM2.5 3h11V2h-11z"];
|
|
13
|
+
readonly add: readonly ["M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4"];
|
|
14
|
+
};
|
|
15
|
+
export declare function EditorActionIcon({ action }: Readonly<{
|
|
16
|
+
action: keyof typeof paths;
|
|
17
|
+
}>): import("react").JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Bootstrap Icons, matching DeliveryPlus editor controls (MIT license).
|
|
3
|
+
const paths = {
|
|
4
|
+
undo: ['M8 3a5 5 0 1 1-4.546 2.914.5.5 0 0 0-.908-.417A6 6 0 1 0 8 2z', 'M8 4.466V.534a.25.25 0 0 0-.41-.192L5.23 2.308a.25.25 0 0 0 0 .384l2.36 1.966A.25.25 0 0 0 8 4.466'],
|
|
5
|
+
redo: ['M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2z', 'M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466'],
|
|
6
|
+
expand: ['M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708'],
|
|
7
|
+
collapse: ['M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708'],
|
|
8
|
+
grip: ['M6 2a1 1 0 1 1-2 0 1 1 0 0 1 2 0m0 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0m0 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0m6-12a1 1 0 1 1-2 0 1 1 0 0 1 2 0m0 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0m0 6a1 1 0 1 1-2 0 1 1 0 0 1 2 0'],
|
|
9
|
+
keyboard: ['M2 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zm0 1h12a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1m0 1h2v2H2zm3 0h2v2H5zm3 0h2v2H8zm3 0h3v2h-3zM2 8h2v2H2zm3 0h6v2H5zm7 0h2v2h-2z'],
|
|
10
|
+
done: [
|
|
11
|
+
'M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-4-4a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0',
|
|
12
|
+
],
|
|
13
|
+
duplicate: [
|
|
14
|
+
'M4 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1zM2 5a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-1h1v1a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h1v1z',
|
|
15
|
+
],
|
|
16
|
+
up: [
|
|
17
|
+
'M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5',
|
|
18
|
+
],
|
|
19
|
+
down: [
|
|
20
|
+
'M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1',
|
|
21
|
+
],
|
|
22
|
+
delete: [
|
|
23
|
+
'M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0z',
|
|
24
|
+
'M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4zM2.5 3h11V2h-11z',
|
|
25
|
+
],
|
|
26
|
+
add: [
|
|
27
|
+
'M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4',
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
export function EditorActionIcon({ action }) {
|
|
31
|
+
return (_jsx("svg", { "aria-hidden": "true", width: "16", height: "16", viewBox: "0 0 16 16", fill: "currentColor", children: paths[action].map((path) => (_jsx("path", { d: path, fillRule: "evenodd" }, path))) }));
|
|
32
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ReactNode, type HTMLAttributes } from 'react';
|
|
2
|
+
/** Keep canvas origins stable and expose a persistent bar on overlay-scrollbar systems. */
|
|
3
|
+
export declare function EditorCanvasScroll({ viewport, status, children, className, onScroll, id, ...props }: HTMLAttributes<HTMLDivElement> & {
|
|
4
|
+
viewport: string;
|
|
5
|
+
status?: ReactNode;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { EditorStatusBar } from './EditorStatusBar.js';
|
|
3
|
+
import { useId, useLayoutEffect, useRef, useState } from 'react';
|
|
4
|
+
const SCROLL_STEP = 40;
|
|
5
|
+
/** Keep canvas origins stable and expose a persistent bar on overlay-scrollbar systems. */
|
|
6
|
+
export function EditorCanvasScroll({ viewport, status, children, className = '', onScroll, id, ...props }) {
|
|
7
|
+
const generatedId = useId();
|
|
8
|
+
const controls = id ?? generatedId;
|
|
9
|
+
const scroll = useRef(null);
|
|
10
|
+
const [geometry, setGeometry] = useState({ viewport: 0, maximum: 0, nativeScrollbar: false });
|
|
11
|
+
const [position, setPosition] = useState(0);
|
|
12
|
+
const customScrollbar = geometry.maximum > 0 && !geometry.nativeScrollbar;
|
|
13
|
+
useLayoutEffect(() => {
|
|
14
|
+
const node = scroll.current;
|
|
15
|
+
if (node)
|
|
16
|
+
node.scrollLeft = 0;
|
|
17
|
+
setPosition(0);
|
|
18
|
+
}, [viewport]);
|
|
19
|
+
useLayoutEffect(() => {
|
|
20
|
+
const node = scroll.current;
|
|
21
|
+
if (!node)
|
|
22
|
+
return;
|
|
23
|
+
let width = node.clientWidth;
|
|
24
|
+
const measure = () => {
|
|
25
|
+
if (node.clientWidth !== width) {
|
|
26
|
+
width = node.clientWidth;
|
|
27
|
+
node.scrollLeft = 0;
|
|
28
|
+
setPosition(0);
|
|
29
|
+
}
|
|
30
|
+
const next = { viewport: node.clientWidth, maximum: Math.max(0, node.scrollWidth - node.clientWidth), nativeScrollbar: node.offsetHeight - node.clientHeight > 0 };
|
|
31
|
+
setGeometry(previous => previous.viewport === next.viewport && previous.maximum === next.maximum && previous.nativeScrollbar === next.nativeScrollbar ? previous : next);
|
|
32
|
+
};
|
|
33
|
+
measure();
|
|
34
|
+
const observer = new ResizeObserver(measure);
|
|
35
|
+
observer.observe(node);
|
|
36
|
+
if (node.firstElementChild)
|
|
37
|
+
observer.observe(node.firstElementChild);
|
|
38
|
+
// Authored tables, code and disclosures can change overflow without resizing the canvas box.
|
|
39
|
+
const mutations = new MutationObserver(measure);
|
|
40
|
+
mutations.observe(node, { subtree: true, childList: true, characterData: true, attributes: true, attributeFilter: ['class', 'style'] });
|
|
41
|
+
return () => { observer.disconnect(); mutations.disconnect(); };
|
|
42
|
+
}, []);
|
|
43
|
+
const changePosition = (next) => {
|
|
44
|
+
const node = scroll.current;
|
|
45
|
+
if (!node)
|
|
46
|
+
return;
|
|
47
|
+
node.scrollLeft = Math.max(0, Math.min(geometry.maximum, next));
|
|
48
|
+
setPosition(node.scrollLeft);
|
|
49
|
+
};
|
|
50
|
+
return _jsxs("div", { className: "editor-canvas-viewport", children: [_jsx("div", { ...props, id: controls, ref: scroll, tabIndex: props.tabIndex ?? 0, onScroll: event => { setPosition(event.currentTarget.scrollLeft); onScroll?.(event); }, className: `editor-canvas-scroll ${className}`, "data-horizontal-overflow": geometry.maximum > 0, "data-custom-scrollbar": customScrollbar, children: children }), customScrollbar && _jsx(HorizontalScrollbar, { controls: controls, geometry: geometry, position: position, onChange: changePosition }), _jsx(EditorStatusBar, { children: status })] });
|
|
51
|
+
}
|
|
52
|
+
function HorizontalScrollbar({ controls, geometry, position, onChange }) {
|
|
53
|
+
const thumb = useRef(null);
|
|
54
|
+
const drag = useRef(null);
|
|
55
|
+
const fraction = Math.max(0.05, geometry.viewport / (geometry.maximum + geometry.viewport));
|
|
56
|
+
return _jsx("div", { role: "scrollbar", "aria-label": "Canvas horizontal scroll", "aria-controls": controls, "aria-orientation": "horizontal", "aria-valuemin": 0, "aria-valuemax": Math.round(geometry.maximum), "aria-valuenow": Math.round(position), tabIndex: 0, className: "editor-canvas-horizontal-scrollbar", onKeyDown: event => {
|
|
57
|
+
const next = event.key === 'Home' ? 0 : event.key === 'End' ? geometry.maximum
|
|
58
|
+
: event.key === 'ArrowLeft' ? position - SCROLL_STEP : event.key === 'ArrowRight' ? position + SCROLL_STEP
|
|
59
|
+
: event.key === 'PageUp' ? position - geometry.viewport : event.key === 'PageDown' ? position + geometry.viewport : undefined;
|
|
60
|
+
if (next !== undefined) {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
onChange(next);
|
|
63
|
+
}
|
|
64
|
+
}, onPointerDown: event => {
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
67
|
+
const track = event.currentTarget.getBoundingClientRect();
|
|
68
|
+
const handle = thumb.current?.getBoundingClientRect();
|
|
69
|
+
if (!handle)
|
|
70
|
+
return;
|
|
71
|
+
if (event.target !== thumb.current) {
|
|
72
|
+
onChange(position + (event.clientX < handle.left ? -geometry.viewport : geometry.viewport));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
drag.current = { start: event.clientX, position, travel: track.width - handle.width };
|
|
76
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
77
|
+
}, onPointerMove: event => {
|
|
78
|
+
const initial = drag.current;
|
|
79
|
+
if (initial && initial.travel > 0)
|
|
80
|
+
onChange(initial.position + (event.clientX - initial.start) * geometry.maximum / initial.travel);
|
|
81
|
+
}, onPointerUp: () => { drag.current = null; }, onPointerCancel: () => { drag.current = null; }, children: _jsx("div", { ref: thumb, className: "editor-canvas-horizontal-thumb", style: { width: `${fraction * 100}%`, left: `${geometry.maximum ? position / geometry.maximum * (1 - fraction) * 100 : 0}%` } }) });
|
|
82
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { useEditorControlContrast } from './useEditorControlContrast.js';
|
|
4
|
+
import { ReadableFormSelect } from './ReadableFormSelect.js';
|
|
5
|
+
import { useId } from 'react';
|
|
6
|
+
import { useCanvasTheme } from './CanvasTheme.js';
|
|
7
|
+
import { EDITOR_THEMES, isEditorTheme } from './editorThemes.js';
|
|
8
|
+
import { EDITOR_VIEWPORT_PRESETS } from './EditorViewportSelect.js';
|
|
9
|
+
/** Canvas preferences share persistence and fields across both editing hosts. */
|
|
10
|
+
export function EditorCanvasSettings({ fallbackWidth }) {
|
|
11
|
+
const contrast = useRef(null);
|
|
12
|
+
useEditorControlContrast(contrast);
|
|
13
|
+
const state = useCanvasTheme();
|
|
14
|
+
const id = useId();
|
|
15
|
+
if (!state)
|
|
16
|
+
return _jsxs("fieldset", { ref: contrast, className: "editor-panel-fields border-0 m-0", "aria-label": "Canvas settings", children: [_jsx("legend", { className: "h6", children: "Canvas" }), fallbackWidth] });
|
|
17
|
+
const custom = state.width !== null && !EDITOR_VIEWPORT_PRESETS.some(item => item.width === state.width);
|
|
18
|
+
return _jsxs("fieldset", { ref: contrast, className: "editor-panel-fields border-0 m-0", "aria-label": "Canvas settings", children: [_jsx("legend", { className: "h6", children: "Canvas" }), _jsxs("label", { htmlFor: `${id}-theme`, children: ["Theme", _jsx(ReadableFormSelect, { id: `${id}-theme`, "aria-label": "Canvas theme", className: "form-select", value: state.theme, onChange: event => { if (isEditorTheme(event.currentTarget.value))
|
|
19
|
+
state.setTheme(event.currentTarget.value); }, children: EDITOR_THEMES.map(theme => _jsx("option", { children: theme }, theme)) })] }), _jsxs("label", { htmlFor: `${id}-variant`, children: ["Variant", _jsxs(ReadableFormSelect, { id: `${id}-variant`, "aria-label": "Canvas variant", className: "form-select", value: state.colorMode, onChange: event => { const value = event.currentTarget.value; if (value === 'light' || value === 'dark')
|
|
20
|
+
state.setColorMode(value); }, children: [_jsx("option", { value: "light", children: "Light" }), _jsx("option", { value: "dark", children: "Dark" })] })] }), _jsxs("label", { htmlFor: `${id}-width`, children: ["Width", _jsxs(ReadableFormSelect, { id: `${id}-width`, "aria-label": "Canvas width", className: "form-select", value: state.width ?? 'fluid', onChange: event => state.setWidth(event.currentTarget.value === 'fluid' ? null : Number(event.currentTarget.value)), children: [_jsx("option", { value: "fluid", children: "Available" }), EDITOR_VIEWPORT_PRESETS.map(item => _jsx("option", { value: item.width, children: item.label }, item.width)), custom && _jsxs("option", { value: state.width ?? '', children: ["Custom (", state.width, "px)"] })] })] })] });
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ReactNode, type Ref } from 'react';
|
|
2
|
+
export declare function EditorCanvasToolbar({ title, selectedId, path, onSelect, viewport, actions, rootButtonRef, readOnly, label }: Readonly<{
|
|
3
|
+
rootButtonRef?: Ref<HTMLButtonElement>;
|
|
4
|
+
readOnly?: boolean;
|
|
5
|
+
title: string;
|
|
6
|
+
selectedId: string;
|
|
7
|
+
path: readonly Readonly<{
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
type?: string;
|
|
11
|
+
}>[];
|
|
12
|
+
onSelect: (id: string) => void;
|
|
13
|
+
viewport: ReactNode;
|
|
14
|
+
actions: ReactNode;
|
|
15
|
+
label?: string;
|
|
16
|
+
}>): import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { nestedComponentLabel } from './nestedComponentLabel.js';
|
|
3
|
+
import { ComponentPickerIcon } from './ComponentPickerIcon.js';
|
|
4
|
+
import { useCanvasTheme } from './CanvasTheme.js';
|
|
5
|
+
import { useLayoutEffect, useRef } from 'react';
|
|
6
|
+
export function EditorCanvasToolbar({ title, selectedId, path, onSelect, viewport, actions, rootButtonRef, readOnly = false, label = 'Component selection' }) {
|
|
7
|
+
const nav = useRef(null);
|
|
8
|
+
const keyboardSelection = useRef(undefined);
|
|
9
|
+
useLayoutEffect(() => {
|
|
10
|
+
const target = keyboardSelection.current;
|
|
11
|
+
keyboardSelection.current = undefined;
|
|
12
|
+
if (target === selectedId)
|
|
13
|
+
nav.current?.querySelector('button[aria-current]')?.focus({ preventScroll: true });
|
|
14
|
+
}, [selectedId]);
|
|
15
|
+
const canvasPreferences = useCanvasTheme();
|
|
16
|
+
const namedPath = path.map((item, index) => ({ ...item, shortLabel: nestedComponentLabel(item.label, path.slice(0, index).map(ancestor => ancestor.label)) }));
|
|
17
|
+
const hiddenPath = namedPath.length > 3 ? namedPath.slice(0, -2) : [];
|
|
18
|
+
const visiblePath = hiddenPath.length ? namedPath.slice(-2) : namedPath;
|
|
19
|
+
const pathButton = (item) => _jsxs("button", { ref: item.id === '' ? rootButtonRef : undefined, type: "button", className: "editor-path-link", disabled: readOnly, title: item.label, "aria-label": item.label, "aria-current": item.id === selectedId ? 'location' : undefined, onClick: event => { if (event.detail === 0)
|
|
20
|
+
keyboardSelection.current = item.id; onSelect(item.id); }, children: [item.type && _jsx("span", { className: "content-outline-icon", children: _jsx(ComponentPickerIcon, { type: item.type }) }), _jsx("span", { className: "editor-path-label", children: item.shortLabel ?? item.label })] });
|
|
21
|
+
return _jsxs("nav", { ref: nav, "aria-label": label, className: "editor-selection-toolbar editor-canvas-statusbar", children: [_jsxs("div", { className: "editor-selection-path", children: [pathButton({ id: '', label: title }), hiddenPath.length > 0 && _jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", children: "/" }), _jsxs("details", { className: "editor-path-ancestors", children: [_jsx("summary", { "aria-label": "Show ancestor components", children: "\u2026" }), _jsx("div", { className: "editor-path-menu", children: hiddenPath.map(item => _jsx("span", { children: pathButton(item) }, item.id)) })] })] }), visiblePath.map(item => _jsxs("span", { className: "editor-path-item", children: [_jsx("span", { "aria-hidden": "true", children: "/" }), pathButton(item)] }, item.id))] }), !canvasPreferences && _jsx("div", { className: "editor-viewport", children: viewport }), actions] });
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { EditorActionIcon } from './EditorActionIcon.js';
|
|
3
|
+
/** The page/slide panel owns the command; the shared button owns its presentation. */
|
|
4
|
+
export function EditorCollectionAdd({ label, disabled, onAdd }) {
|
|
5
|
+
return _jsx("button", { type: "button", className: "editor-icon-action editor-collection-add", "aria-label": label, title: label, disabled: disabled, onClick: event => { event.preventDefault(); onAdd(); }, children: _jsx(EditorActionIcon, { action: "add" }) });
|
|
6
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AriaAttributes, KeyboardEventHandler, ReactNode, Ref } from 'react';
|
|
2
|
+
/** Collection policy and drag behavior remain owned by the document editor. */
|
|
3
|
+
export declare function EditorCollectionRow({ id, index, title, label, selected, current, expanded, toggleLabel, onToggle, onSelect, onKeyDown, selectRef, handle, actions, }: Readonly<{
|
|
4
|
+
id: string;
|
|
5
|
+
index: number;
|
|
6
|
+
title: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
selected: boolean;
|
|
9
|
+
current?: AriaAttributes['aria-current'];
|
|
10
|
+
expanded?: boolean;
|
|
11
|
+
toggleLabel: string;
|
|
12
|
+
onToggle: () => void;
|
|
13
|
+
onSelect: () => void;
|
|
14
|
+
onKeyDown?: KeyboardEventHandler<HTMLButtonElement>;
|
|
15
|
+
selectRef?: Ref<HTMLButtonElement>;
|
|
16
|
+
handle?: ReactNode;
|
|
17
|
+
actions?: ReactNode;
|
|
18
|
+
}>): import("react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { EditorActionIcon } from './EditorActionIcon.js';
|
|
3
|
+
/** Collection policy and drag behavior remain owned by the document editor. */
|
|
4
|
+
export function EditorCollectionRow({ id, index, title, label, selected, current, expanded, toggleLabel, onToggle, onSelect, onKeyDown, selectRef, handle, actions, }) {
|
|
5
|
+
return _jsxs("div", { className: `editor-collection-row${selected ? ' selected' : ''}`, children: [handle, expanded !== undefined && _jsx("button", { type: "button", className: "editor-icon-action", "aria-label": toggleLabel, "aria-expanded": expanded, onClick: onToggle, children: _jsx(EditorActionIcon, { action: expanded ? 'expand' : 'collapse' }) }), _jsxs("button", { ref: selectRef, type: "button", className: "editor-collection-select text-truncate", "data-outline-collection": id, "aria-label": label, "aria-pressed": selected, "aria-current": current, title: title, onKeyDown: onKeyDown, onClick: onSelect, children: [String(index + 1).padStart(2, '0'), " ", title] }), actions] });
|
|
6
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/** Both authoring hosts use one command layout and native theme styling. */
|
|
3
|
+
export declare function EditorCommandBar({ title, label, children }: Readonly<{
|
|
4
|
+
title: string;
|
|
5
|
+
label: string;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}>): import("react").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { useEditorControlContrast } from './useEditorControlContrast.js';
|
|
4
|
+
/** Both authoring hosts use one command layout and native theme styling. */
|
|
5
|
+
export function EditorCommandBar({ title, label, children }) {
|
|
6
|
+
const contrast = useRef(null);
|
|
7
|
+
useEditorControlContrast(contrast);
|
|
8
|
+
return _jsxs("div", { ref: contrast, className: "content-editor-toolbar", role: "toolbar", "aria-label": label, children: [_jsx("h2", { className: "content-editor-title", children: title }), _jsx("div", { className: "content-editor-actions", children: children })] });
|
|
9
|
+
}
|