@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,51 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
/** Reveal selection inside the canvas scroller without moving focus or the document. */
|
|
3
|
+
export function useCanvasSelectionScroll(canvas, selectedId) {
|
|
4
|
+
const frame = useRef();
|
|
5
|
+
const reveal = useCallback((id) => {
|
|
6
|
+
if (frame.current !== undefined)
|
|
7
|
+
cancelAnimationFrame(frame.current);
|
|
8
|
+
frame.current = requestAnimationFrame(() => {
|
|
9
|
+
frame.current = undefined;
|
|
10
|
+
const root = canvas.current;
|
|
11
|
+
const target = Array.from(root?.querySelectorAll('[data-block-id]') ?? [])
|
|
12
|
+
.find(element => element.dataset.blockId === id);
|
|
13
|
+
const scroller = root?.closest('.editor-canvas-scroll, .preview-scroll, .lesson-canvas-scroll');
|
|
14
|
+
if (target && scroller)
|
|
15
|
+
revealInViewport(target, scroller);
|
|
16
|
+
const row = Array.from(root?.closest('.content-editor-shell')?.querySelectorAll('[data-outline-block]') ?? [])
|
|
17
|
+
.find(element => element.dataset.outlineBlock === id);
|
|
18
|
+
const panel = row?.closest('.editor-tree-list, .slide-tree-list');
|
|
19
|
+
if (row && panel)
|
|
20
|
+
revealInViewport(row, panel);
|
|
21
|
+
});
|
|
22
|
+
}, [canvas]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
reveal(selectedId);
|
|
25
|
+
return () => { if (frame.current !== undefined)
|
|
26
|
+
cancelAnimationFrame(frame.current); };
|
|
27
|
+
}, [selectedId, reveal]);
|
|
28
|
+
return reveal;
|
|
29
|
+
}
|
|
30
|
+
function revealInViewport(target, scroller) {
|
|
31
|
+
const bounds = target.getBoundingClientRect(), viewport = scroller.getBoundingClientRect();
|
|
32
|
+
const top = viewport.top + scroller.clientTop;
|
|
33
|
+
const left = viewport.left + scroller.clientLeft;
|
|
34
|
+
const bottom = top + (scroller.clientHeight || viewport.height);
|
|
35
|
+
const right = left + (scroller.clientWidth || viewport.width);
|
|
36
|
+
if (!(bounds.top < top && bounds.bottom > bottom)) {
|
|
37
|
+
if (bounds.top < top)
|
|
38
|
+
scroller.scrollTop += bounds.top - top;
|
|
39
|
+
else if (bounds.bottom > bottom)
|
|
40
|
+
scroller.scrollTop += bounds.bottom - bottom;
|
|
41
|
+
}
|
|
42
|
+
// A wide selected container must not move its already-visible leading edge offscreen.
|
|
43
|
+
const leadingEdgeVisible = bounds.left >= left && bounds.left < right;
|
|
44
|
+
const spansViewport = bounds.left < left && bounds.right > right;
|
|
45
|
+
if (spansViewport || (bounds.width >= right - left && leadingEdgeVisible))
|
|
46
|
+
return;
|
|
47
|
+
if (bounds.left < left)
|
|
48
|
+
scroller.scrollLeft += bounds.left - left;
|
|
49
|
+
else if (bounds.right > right)
|
|
50
|
+
scroller.scrollLeft += bounds.right - right;
|
|
51
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type Entry<Value> = Readonly<{
|
|
2
|
+
value: Value;
|
|
3
|
+
label: string;
|
|
4
|
+
group: string;
|
|
5
|
+
}>;
|
|
6
|
+
export type ContentHistoryState<Value> = Readonly<{
|
|
7
|
+
past: readonly Entry<Value>[];
|
|
8
|
+
present: Entry<Value>;
|
|
9
|
+
future: readonly Entry<Value>[];
|
|
10
|
+
}>;
|
|
11
|
+
/** Host snapshots stay authoritative; adjacent typing groups never cross component/field boundaries. */
|
|
12
|
+
export declare function useContentHistory<Value>(initial: Value, equals?: (left: Value, right: Value) => boolean, saved?: ContentHistoryState<Value>): {
|
|
13
|
+
state: Readonly<{
|
|
14
|
+
past: readonly Readonly<{
|
|
15
|
+
value: Value;
|
|
16
|
+
label: string;
|
|
17
|
+
group: string;
|
|
18
|
+
}>[];
|
|
19
|
+
present: Readonly<{
|
|
20
|
+
value: Value;
|
|
21
|
+
label: string;
|
|
22
|
+
group: string;
|
|
23
|
+
}>;
|
|
24
|
+
future: readonly Readonly<{
|
|
25
|
+
value: Value;
|
|
26
|
+
label: string;
|
|
27
|
+
group: string;
|
|
28
|
+
}>[];
|
|
29
|
+
}>;
|
|
30
|
+
value: Value;
|
|
31
|
+
label: string;
|
|
32
|
+
change: (value: Value, label?: string, group?: string) => void;
|
|
33
|
+
replace: (value: Value) => void;
|
|
34
|
+
reset: (value: Value) => void;
|
|
35
|
+
undo: () => void;
|
|
36
|
+
redo: () => void;
|
|
37
|
+
canUndo: boolean;
|
|
38
|
+
canRedo: boolean;
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from 'react';
|
|
2
|
+
const HISTORY_LIMIT = 100;
|
|
3
|
+
const TEXT_GROUP_MS = 600;
|
|
4
|
+
/** Host snapshots stay authoritative; adjacent typing groups never cross component/field boundaries. */
|
|
5
|
+
export function useContentHistory(initial, equals = Object.is, saved) {
|
|
6
|
+
const [history, setHistory] = useState(saved ?? {
|
|
7
|
+
past: [], present: { value: initial, label: '', group: '' }, future: [],
|
|
8
|
+
});
|
|
9
|
+
const lastEdit = useRef(0);
|
|
10
|
+
const change = useCallback((value, label = 'Text edited', group = label) => {
|
|
11
|
+
const now = Date.now();
|
|
12
|
+
const merge = label.endsWith('edited') && now - lastEdit.current < TEXT_GROUP_MS;
|
|
13
|
+
lastEdit.current = label.endsWith('edited') ? now : 0;
|
|
14
|
+
setHistory(current => equals(value, current.present.value) ? current : {
|
|
15
|
+
past: merge && current.present.label === label && current.present.group === group ? current.past : [...current.past, current.present].slice(-HISTORY_LIMIT),
|
|
16
|
+
present: { value, label, group }, future: [],
|
|
17
|
+
});
|
|
18
|
+
}, [equals]);
|
|
19
|
+
const replace = useCallback((value) => {
|
|
20
|
+
lastEdit.current = 0;
|
|
21
|
+
setHistory(current => ({ ...current, present: { ...current.present, value } }));
|
|
22
|
+
}, []);
|
|
23
|
+
const reset = useCallback((value) => {
|
|
24
|
+
lastEdit.current = 0;
|
|
25
|
+
setHistory({ past: [], present: { value, label: '', group: '' }, future: [] });
|
|
26
|
+
}, []);
|
|
27
|
+
const undo = useCallback(() => {
|
|
28
|
+
lastEdit.current = 0;
|
|
29
|
+
setHistory(current => {
|
|
30
|
+
const previous = current.past.at(-1);
|
|
31
|
+
return previous ? { past: current.past.slice(0, -1), present: previous, future: [current.present, ...current.future] } : current;
|
|
32
|
+
});
|
|
33
|
+
}, []);
|
|
34
|
+
const redo = useCallback(() => {
|
|
35
|
+
lastEdit.current = 0;
|
|
36
|
+
setHistory(current => {
|
|
37
|
+
const next = current.future[0];
|
|
38
|
+
return next ? { past: [...current.past, current.present], present: next, future: current.future.slice(1) } : current;
|
|
39
|
+
});
|
|
40
|
+
}, []);
|
|
41
|
+
return { state: history, value: history.present.value, label: history.present.label, change, replace, reset, undo, redo, canUndo: history.past.length > 0, canRedo: history.future.length > 0 };
|
|
42
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type HTMLAttributes } from 'react';
|
|
2
|
+
/** The same validated insertion edge for an outline row or a native canvas surface. */
|
|
3
|
+
export declare function useContentReorderTarget(type: string, scope: string, onMove: (source: string, after: boolean) => void): {
|
|
4
|
+
edge: "after" | "before" | undefined;
|
|
5
|
+
handlers: Pick<HTMLAttributes<HTMLElement>, "onDragOver" | "onDragLeave" | "onDrop">;
|
|
6
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { acceptsReorder, dropAfter, reorderScope } from './ReorderHandle.js';
|
|
3
|
+
/** The same validated insertion edge for an outline row or a native canvas surface. */
|
|
4
|
+
export function useContentReorderTarget(type, scope, onMove) {
|
|
5
|
+
const [edge, setEdge] = useState();
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!edge)
|
|
8
|
+
return;
|
|
9
|
+
const clear = () => setEdge(undefined);
|
|
10
|
+
document.addEventListener('dragend', clear);
|
|
11
|
+
return () => document.removeEventListener('dragend', clear);
|
|
12
|
+
}, [edge]);
|
|
13
|
+
const handlers = {
|
|
14
|
+
onDragOver: event => {
|
|
15
|
+
if (!acceptsReorder(event, type))
|
|
16
|
+
return;
|
|
17
|
+
const scopes = Array.from(event.dataTransfer.types).filter(value => value.startsWith(`${type}-scope-`));
|
|
18
|
+
if (scopes.length && !scopes.includes(reorderScope(type, scope))) {
|
|
19
|
+
event.dataTransfer.dropEffect = 'none';
|
|
20
|
+
setEdge(undefined);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
event.stopPropagation();
|
|
25
|
+
event.dataTransfer.dropEffect = 'move';
|
|
26
|
+
setEdge(dropAfter(event) ? 'after' : 'before');
|
|
27
|
+
},
|
|
28
|
+
onDragLeave: event => {
|
|
29
|
+
if (!(event.relatedTarget instanceof Node) || !event.currentTarget.contains(event.relatedTarget))
|
|
30
|
+
setEdge(undefined);
|
|
31
|
+
},
|
|
32
|
+
onDrop: event => {
|
|
33
|
+
if (!acceptsReorder(event, type))
|
|
34
|
+
return;
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
event.stopPropagation();
|
|
37
|
+
const scopes = Array.from(event.dataTransfer.types).filter(value => value.startsWith(`${type}-scope-`));
|
|
38
|
+
if (!scopes.length || scopes.includes(reorderScope(type, scope)))
|
|
39
|
+
onMove(event.dataTransfer.getData(type), dropAfter(event));
|
|
40
|
+
setEdge(undefined);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
return { edge, handlers };
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Selection and branch expansion belong to content composition; hosts choose when to reset. */
|
|
2
|
+
export declare function useContentSelection(resetKey: string | number): {
|
|
3
|
+
revealAncestors: (ids: readonly string[]) => void;
|
|
4
|
+
selectedId: string;
|
|
5
|
+
setSelectedId: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
6
|
+
inlineId: string;
|
|
7
|
+
setInlineId: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
8
|
+
collapsedBlocks: ReadonlySet<string>;
|
|
9
|
+
toggleBranch: (id: string) => void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
/** Selection and branch expansion belong to content composition; hosts choose when to reset. */
|
|
3
|
+
export function useContentSelection(resetKey) {
|
|
4
|
+
const [selectedId, setSelectedId] = useState('');
|
|
5
|
+
const [inlineId, setInlineId] = useState('');
|
|
6
|
+
const [collapsedBlocks, setCollapsedBlocks] = useState(new Set());
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
setSelectedId('');
|
|
9
|
+
setInlineId('');
|
|
10
|
+
}, [resetKey]);
|
|
11
|
+
const toggleBranch = (id) => {
|
|
12
|
+
setCollapsedBlocks((previous) => {
|
|
13
|
+
const next = new Set(previous);
|
|
14
|
+
if (next.has(id))
|
|
15
|
+
next.delete(id);
|
|
16
|
+
else
|
|
17
|
+
next.add(id);
|
|
18
|
+
return next;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const revealAncestors = (ids) => setCollapsedBlocks(previous => new Set([...previous].filter(id => !ids.includes(id))));
|
|
22
|
+
return { revealAncestors, selectedId, setSelectedId, inlineId, setInlineId, collapsedBlocks, toggleBranch };
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ForwardedRef, type RefObject } from 'react';
|
|
2
|
+
export declare function useDropdownElementRef<T extends HTMLElement>(forwardedRef: ForwardedRef<T>): {
|
|
3
|
+
element: import("react").MutableRefObject<T | null>;
|
|
4
|
+
ref: (node: T | null) => void;
|
|
5
|
+
};
|
|
6
|
+
export type ControlContrastStates = readonly [
|
|
7
|
+
readonly [string, string, number?],
|
|
8
|
+
...(readonly [string, string, number?])[]
|
|
9
|
+
];
|
|
10
|
+
/** One contrast observer is shared by React controls and existing property-field DOM. */
|
|
11
|
+
export declare function observeControlContrast(menu: HTMLElement, states: ControlContrastStates): {
|
|
12
|
+
refresh: () => void;
|
|
13
|
+
dispose: () => void;
|
|
14
|
+
} | undefined;
|
|
15
|
+
/** Adjust insufficient ink contrast without replacing Bootstrap's surfaces or focus treatment. */
|
|
16
|
+
export declare function useDropdownContrast(element: RefObject<HTMLElement>, active: boolean, states: ControlContrastStates): void;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { correctControlBackgroundIcon } from './controlBackgroundIconContrast.js';
|
|
2
|
+
import { useCallback, useLayoutEffect, useRef, } from 'react';
|
|
3
|
+
import { mixDropdownColor, readableDropdownColor, } from './dropdownContrast.js';
|
|
4
|
+
export function useDropdownElementRef(forwardedRef) {
|
|
5
|
+
const element = useRef(null);
|
|
6
|
+
const ref = useCallback((node) => {
|
|
7
|
+
element.current = node;
|
|
8
|
+
if (typeof forwardedRef === 'function')
|
|
9
|
+
forwardedRef(node);
|
|
10
|
+
else if (forwardedRef)
|
|
11
|
+
forwardedRef.current = node;
|
|
12
|
+
}, [forwardedRef]);
|
|
13
|
+
return { element, ref };
|
|
14
|
+
}
|
|
15
|
+
/** One contrast observer is shared by React controls and existing property-field DOM. */
|
|
16
|
+
export function observeControlContrast(menu, states) {
|
|
17
|
+
if (typeof CanvasRenderingContext2D === 'undefined')
|
|
18
|
+
return;
|
|
19
|
+
const context = document.createElement('canvas').getContext('2d');
|
|
20
|
+
if (!context)
|
|
21
|
+
return;
|
|
22
|
+
const properties = [
|
|
23
|
+
...states.map(([property]) => property),
|
|
24
|
+
'--editor-placeholder-color',
|
|
25
|
+
'--editor-file-button-color',
|
|
26
|
+
'background-image',
|
|
27
|
+
'opacity',
|
|
28
|
+
];
|
|
29
|
+
const originals = properties.map((property) => ({
|
|
30
|
+
property,
|
|
31
|
+
value: menu.style.getPropertyValue(property),
|
|
32
|
+
priority: menu.style.getPropertyPriority(property),
|
|
33
|
+
}));
|
|
34
|
+
const restore = () => {
|
|
35
|
+
menu.removeAttribute('data-editor-placeholder-adjusted');
|
|
36
|
+
menu.removeAttribute('data-editor-file-button-adjusted');
|
|
37
|
+
originals.forEach(({ property, value, priority }) => {
|
|
38
|
+
if (value)
|
|
39
|
+
menu.style.setProperty(property, value, priority);
|
|
40
|
+
else
|
|
41
|
+
menu.style.removeProperty(property);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const color = (css, background) => {
|
|
45
|
+
context.clearRect(0, 0, 1, 1);
|
|
46
|
+
context.fillStyle = css;
|
|
47
|
+
context.fillRect(0, 0, 1, 1);
|
|
48
|
+
const pixel = context.getImageData(0, 0, 1, 1).data;
|
|
49
|
+
return mixDropdownColor([pixel[0], pixel[1], pixel[2]], background, pixel[3] / 255);
|
|
50
|
+
};
|
|
51
|
+
const measure = () => {
|
|
52
|
+
restore();
|
|
53
|
+
let surface = [255, 255, 255];
|
|
54
|
+
const ancestors = [];
|
|
55
|
+
for (let node = menu.parentElement; node; node = node.parentElement)
|
|
56
|
+
ancestors.unshift(node);
|
|
57
|
+
for (const node of ancestors)
|
|
58
|
+
surface = color(getComputedStyle(node).backgroundColor, surface);
|
|
59
|
+
const sample = (property) => {
|
|
60
|
+
const style = getComputedStyle(menu);
|
|
61
|
+
const value = style.getPropertyValue(property).trim();
|
|
62
|
+
return !value || value.toLowerCase() === 'currentcolor'
|
|
63
|
+
? style.color
|
|
64
|
+
: value;
|
|
65
|
+
};
|
|
66
|
+
surface = color(sample(states[0][1]), surface);
|
|
67
|
+
for (const [ink, fill, minimumContrast] of states) {
|
|
68
|
+
const background = color(sample(fill), surface);
|
|
69
|
+
const foreground = color(sample(ink), background);
|
|
70
|
+
const corrected = readableDropdownColor(foreground, background, minimumContrast);
|
|
71
|
+
if (corrected)
|
|
72
|
+
menu.style.setProperty(ink, `rgb(${corrected.join(', ')})`);
|
|
73
|
+
}
|
|
74
|
+
const pseudoInk = (pseudo, property, attribute) => {
|
|
75
|
+
const style = getComputedStyle(menu, pseudo);
|
|
76
|
+
const background = color(style.backgroundColor, surface);
|
|
77
|
+
const foreground = mixDropdownColor(color(style.color, background), background, Number(style.opacity));
|
|
78
|
+
const corrected = readableDropdownColor(foreground, background);
|
|
79
|
+
if (corrected) {
|
|
80
|
+
menu.style.setProperty(property, `rgb(${corrected.join(', ')})`);
|
|
81
|
+
menu.setAttribute(attribute, 'true');
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
if (menu.matches('input[placeholder], textarea[placeholder]'))
|
|
85
|
+
pseudoInk('::placeholder', '--editor-placeholder-color', 'data-editor-placeholder-adjusted');
|
|
86
|
+
if (menu.matches('input[type="file"]'))
|
|
87
|
+
pseudoInk('::file-selector-button', '--editor-file-button-color', 'data-editor-file-button-adjusted');
|
|
88
|
+
correctControlBackgroundIcon(menu, surface, context);
|
|
89
|
+
};
|
|
90
|
+
measure();
|
|
91
|
+
let frame = 0;
|
|
92
|
+
const observer = new MutationObserver(() => {
|
|
93
|
+
cancelAnimationFrame(frame);
|
|
94
|
+
frame = requestAnimationFrame(measure);
|
|
95
|
+
});
|
|
96
|
+
observer.observe(menu, {
|
|
97
|
+
attributes: true,
|
|
98
|
+
attributeFilter: [
|
|
99
|
+
'class',
|
|
100
|
+
'disabled',
|
|
101
|
+
'aria-disabled',
|
|
102
|
+
'readonly',
|
|
103
|
+
'aria-invalid',
|
|
104
|
+
'placeholder',
|
|
105
|
+
'checked',
|
|
106
|
+
],
|
|
107
|
+
});
|
|
108
|
+
for (let parent = menu.parentElement; parent; parent = parent.parentElement) {
|
|
109
|
+
if (parent instanceof HTMLFieldSetElement)
|
|
110
|
+
observer.observe(parent, {
|
|
111
|
+
attributes: true,
|
|
112
|
+
attributeFilter: ['disabled'],
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
observer.observe(document.head, {
|
|
116
|
+
subtree: true,
|
|
117
|
+
childList: true,
|
|
118
|
+
characterData: true,
|
|
119
|
+
});
|
|
120
|
+
observer.observe(document.documentElement, {
|
|
121
|
+
subtree: true,
|
|
122
|
+
attributes: true,
|
|
123
|
+
attributeFilter: [
|
|
124
|
+
'data-bs-theme',
|
|
125
|
+
'data-canvas-theme',
|
|
126
|
+
'data-editor-color-scheme',
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
refresh: measure,
|
|
131
|
+
dispose: () => {
|
|
132
|
+
observer.disconnect();
|
|
133
|
+
cancelAnimationFrame(frame);
|
|
134
|
+
restore();
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** Adjust insufficient ink contrast without replacing Bootstrap's surfaces or focus treatment. */
|
|
139
|
+
export function useDropdownContrast(element, active, states) {
|
|
140
|
+
useLayoutEffect(() => {
|
|
141
|
+
if (!element.current || !active)
|
|
142
|
+
return;
|
|
143
|
+
return observeControlContrast(element.current, states)?.dispose;
|
|
144
|
+
}, [active, element, states]);
|
|
145
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { useId, useLayoutEffect } from 'react';
|
|
2
|
+
import { observeControlContrast, } from './useDropdownContrast.js';
|
|
3
|
+
import { BUTTON_OUTLINE_STATES, BUTTON_TEXT_STATES } from './ReadableButton.js';
|
|
4
|
+
const TARGETS = 'input:not([type=hidden], [type=range], [type=color]), textarea, select, button, [role=option], [role=menuitem], [role=menuitemradio], [role=menuitemcheckbox], summary.editor-panel-header, label, legend, .editor-panel-title, .form-text, h3, h4';
|
|
5
|
+
const TEXT_STATES = [['color', 'background-color']];
|
|
6
|
+
const ICON_STATES = [['color', 'background-color', 3]];
|
|
7
|
+
const SUMMARY_STATES = [
|
|
8
|
+
...TEXT_STATES,
|
|
9
|
+
['outline-color', 'background-color', 3],
|
|
10
|
+
];
|
|
11
|
+
function excluded(node, portalClassName) {
|
|
12
|
+
if (node.closest('[data-editor-contrast-owned], .content-text-content, [contenteditable=true], .simulator-app-page'))
|
|
13
|
+
return true;
|
|
14
|
+
if (node.closest('.content-authoring-canvas') &&
|
|
15
|
+
!node.closest('.content-text-toolbar'))
|
|
16
|
+
return true;
|
|
17
|
+
const popup = node.closest('.mdxeditor-popup-container');
|
|
18
|
+
return Boolean(popup &&
|
|
19
|
+
(!portalClassName || !popup.classList.contains(portalClassName)));
|
|
20
|
+
}
|
|
21
|
+
/** Cover host-supplied property fields without replacing native controls or their event handlers. */
|
|
22
|
+
export function useEditorControlContrast(root, portalClassName) {
|
|
23
|
+
const owner = useId();
|
|
24
|
+
useLayoutEffect(() => {
|
|
25
|
+
const surface = root.current;
|
|
26
|
+
if (!surface)
|
|
27
|
+
return;
|
|
28
|
+
const scope = surface.closest('.modal-content') ?? surface;
|
|
29
|
+
const registrations = new Map();
|
|
30
|
+
let frame = 0;
|
|
31
|
+
const scan = () => {
|
|
32
|
+
const scopes = [
|
|
33
|
+
scope,
|
|
34
|
+
...(portalClassName
|
|
35
|
+
? Array.from(document.querySelectorAll(`.mdxeditor-popup-container.${CSS.escape(portalClassName)}`))
|
|
36
|
+
: []),
|
|
37
|
+
];
|
|
38
|
+
const visible = new Set(scopes.flatMap((region) => {
|
|
39
|
+
const bounds = region === scope
|
|
40
|
+
? region.getBoundingClientRect()
|
|
41
|
+
: { top: 0, bottom: innerHeight };
|
|
42
|
+
return Array.from(region.querySelectorAll(TARGETS)).filter((node) => {
|
|
43
|
+
if (excluded(node, portalClassName) ||
|
|
44
|
+
(node.dataset.editorContrastOwner &&
|
|
45
|
+
node.dataset.editorContrastOwner !== owner) ||
|
|
46
|
+
!node.getClientRects().length)
|
|
47
|
+
return false;
|
|
48
|
+
const box = node.getBoundingClientRect();
|
|
49
|
+
return (box.bottom >= Math.max(0, bounds.top) &&
|
|
50
|
+
box.top <= Math.min(innerHeight, bounds.bottom) &&
|
|
51
|
+
box.right >= 0 &&
|
|
52
|
+
box.left <= innerWidth);
|
|
53
|
+
});
|
|
54
|
+
}));
|
|
55
|
+
for (const [node, registration] of registrations)
|
|
56
|
+
if (!visible.has(node)) {
|
|
57
|
+
registration.stop();
|
|
58
|
+
registrations.delete(node);
|
|
59
|
+
}
|
|
60
|
+
for (const node of visible) {
|
|
61
|
+
const existing = registrations.get(node);
|
|
62
|
+
if (existing) {
|
|
63
|
+
if (existing.removeClass &&
|
|
64
|
+
!node.classList.contains(existing.removeClass))
|
|
65
|
+
node.classList.add(existing.removeClass);
|
|
66
|
+
existing.refresh();
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
let states = TEXT_STATES;
|
|
70
|
+
let removeClass;
|
|
71
|
+
if (node.matches('.btn')) {
|
|
72
|
+
states = node.className
|
|
73
|
+
.split(/\s+/)
|
|
74
|
+
.some((name) => name.startsWith('btn-outline-'))
|
|
75
|
+
? BUTTON_OUTLINE_STATES
|
|
76
|
+
: BUTTON_TEXT_STATES;
|
|
77
|
+
if (!node.classList.contains('editor-readable-button')) {
|
|
78
|
+
node.classList.add('editor-readable-button');
|
|
79
|
+
removeClass = 'editor-readable-button';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (node.matches('button') && !node.textContent?.trim())
|
|
83
|
+
states = ICON_STATES;
|
|
84
|
+
else if (node.matches('summary'))
|
|
85
|
+
states = SUMMARY_STATES;
|
|
86
|
+
node.dataset.editorContrastOwner = owner;
|
|
87
|
+
const observer = observeControlContrast(node, states);
|
|
88
|
+
if (!observer) {
|
|
89
|
+
delete node.dataset.editorContrastOwner;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
registrations.set(node, {
|
|
93
|
+
refresh: observer.refresh,
|
|
94
|
+
removeClass,
|
|
95
|
+
stop: () => {
|
|
96
|
+
observer.dispose();
|
|
97
|
+
delete node.dataset.editorContrastOwner;
|
|
98
|
+
if (removeClass)
|
|
99
|
+
node.classList.remove(removeClass);
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const schedule = () => {
|
|
105
|
+
cancelAnimationFrame(frame);
|
|
106
|
+
frame = requestAnimationFrame(scan);
|
|
107
|
+
};
|
|
108
|
+
const mutation = new MutationObserver(() => {
|
|
109
|
+
schedule();
|
|
110
|
+
});
|
|
111
|
+
scan();
|
|
112
|
+
mutation.observe(scope, {
|
|
113
|
+
subtree: true,
|
|
114
|
+
childList: true,
|
|
115
|
+
attributes: true,
|
|
116
|
+
attributeFilter: [
|
|
117
|
+
'class',
|
|
118
|
+
'disabled',
|
|
119
|
+
'readonly',
|
|
120
|
+
'aria-invalid',
|
|
121
|
+
'aria-selected',
|
|
122
|
+
'aria-pressed',
|
|
123
|
+
'data-state',
|
|
124
|
+
'data-highlighted',
|
|
125
|
+
'open',
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
const resize = new ResizeObserver(schedule);
|
|
129
|
+
resize.observe(scope);
|
|
130
|
+
for (const event of [
|
|
131
|
+
'scroll',
|
|
132
|
+
'focusin',
|
|
133
|
+
'focusout',
|
|
134
|
+
'pointerover',
|
|
135
|
+
'pointerout',
|
|
136
|
+
'pointerdown',
|
|
137
|
+
'pointerup',
|
|
138
|
+
'change',
|
|
139
|
+
'input',
|
|
140
|
+
])
|
|
141
|
+
scope.addEventListener(event, schedule, true);
|
|
142
|
+
const portals = portalClassName
|
|
143
|
+
? new MutationObserver((records) => {
|
|
144
|
+
if (records.some((record) => (record.target instanceof Element &&
|
|
145
|
+
record.target.closest(`.mdxeditor-popup-container.${CSS.escape(portalClassName)}`)) ||
|
|
146
|
+
[
|
|
147
|
+
...record.addedNodes,
|
|
148
|
+
...record.removedNodes,
|
|
149
|
+
].some((node) => node instanceof Element &&
|
|
150
|
+
node.matches(`.mdxeditor-popup-container.${CSS.escape(portalClassName)}`))))
|
|
151
|
+
schedule();
|
|
152
|
+
})
|
|
153
|
+
: null;
|
|
154
|
+
portals?.observe(document.body, {
|
|
155
|
+
subtree: true,
|
|
156
|
+
childList: true,
|
|
157
|
+
attributes: true,
|
|
158
|
+
attributeFilter: [
|
|
159
|
+
'class',
|
|
160
|
+
'data-state',
|
|
161
|
+
'data-highlighted',
|
|
162
|
+
'aria-selected',
|
|
163
|
+
],
|
|
164
|
+
});
|
|
165
|
+
window.addEventListener('resize', schedule);
|
|
166
|
+
return () => {
|
|
167
|
+
mutation.disconnect();
|
|
168
|
+
portals?.disconnect();
|
|
169
|
+
resize.disconnect();
|
|
170
|
+
cancelAnimationFrame(frame);
|
|
171
|
+
window.removeEventListener('resize', schedule);
|
|
172
|
+
for (const event of [
|
|
173
|
+
'scroll',
|
|
174
|
+
'focusin',
|
|
175
|
+
'focusout',
|
|
176
|
+
'pointerover',
|
|
177
|
+
'pointerout',
|
|
178
|
+
'pointerdown',
|
|
179
|
+
'pointerup',
|
|
180
|
+
'change',
|
|
181
|
+
'input',
|
|
182
|
+
])
|
|
183
|
+
scope.removeEventListener(event, schedule, true);
|
|
184
|
+
for (const registration of registrations.values())
|
|
185
|
+
registration.stop();
|
|
186
|
+
};
|
|
187
|
+
}, [root, owner, portalClassName]);
|
|
188
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Site styles stop at independently themed canvases and their text-editor portals. */
|
|
2
|
+
export declare function scopeSiteThemeCss(css: string): string;
|
|
3
|
+
export declare function useSiteThemeStyles(theme: string, load: (theme: string) => Promise<string>, colorScheme: 'light' | 'dark', colorMode?: 'light' | 'dark'): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef } from 'react';
|
|
2
|
+
/** Site styles stop at independently themed canvases and their text-editor portals. */
|
|
3
|
+
export function scopeSiteThemeCss(css) {
|
|
4
|
+
const imports = [];
|
|
5
|
+
const rules = css.replace(/@charset\s+"[^"]*"\s*;/g, '').replace(/@import\s+(?:url\([^)]*\)|"[^"]*"|'[^']*')[^;]*;/g, statement => { imports.push(statement); return ''; });
|
|
6
|
+
return `${imports.join('\n')}\n@scope (:root) to (.content-authoring-canvas[data-canvas-theme], .mdxeditor-popup-container[class*="canvas-palette-"]) {${rules.replace(/:root\b/g, ':scope').replace(/\[data-bs-theme=(["']?)(light|dark)\1\]/g, ':is(:where(:scope)[data-bs-theme=$2], [data-bs-theme=$2])')}}`;
|
|
7
|
+
}
|
|
8
|
+
export function useSiteThemeStyles(theme, load, colorScheme, colorMode = 'light') {
|
|
9
|
+
const stylesheet = useRef(null);
|
|
10
|
+
useLayoutEffect(() => {
|
|
11
|
+
const style = document.createElement('style');
|
|
12
|
+
document.head.prepend(style);
|
|
13
|
+
stylesheet.current = style;
|
|
14
|
+
return () => { style.remove(); stylesheet.current = null; };
|
|
15
|
+
}, []);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
let cancelled = false;
|
|
18
|
+
void load(theme).then(css => {
|
|
19
|
+
if (cancelled || !stylesheet.current)
|
|
20
|
+
return;
|
|
21
|
+
stylesheet.current.textContent = scopeSiteThemeCss(css);
|
|
22
|
+
stylesheet.current.dataset.siteTheme = theme;
|
|
23
|
+
document.documentElement.dataset.bsTheme = colorMode;
|
|
24
|
+
document.documentElement.dataset.editorColorScheme = colorMode === 'dark' ? 'dark' : colorScheme;
|
|
25
|
+
}).catch(() => {
|
|
26
|
+
// Retain the last successfully loaded site palette if a chunk cannot load.
|
|
27
|
+
});
|
|
28
|
+
return () => { cancelled = true; };
|
|
29
|
+
}, [theme, load, colorScheme, colorMode]);
|
|
30
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Explicit host validation failures move focus after their message has rendered. */
|
|
2
|
+
export declare function useValidationFocus<T extends HTMLElement = HTMLParagraphElement>(): {
|
|
3
|
+
validationRef: import("react").RefObject<T>;
|
|
4
|
+
requestValidationFocus: import("react").DispatchWithoutAction;
|
|
5
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useReducer, useRef } from 'react';
|
|
2
|
+
/** Explicit host validation failures move focus after their message has rendered. */
|
|
3
|
+
export function useValidationFocus() {
|
|
4
|
+
const validationRef = useRef(null);
|
|
5
|
+
const [attempt, requestValidationFocus] = useReducer((value) => value + 1, 0);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (attempt === 0)
|
|
8
|
+
return;
|
|
9
|
+
const target = validationRef.current;
|
|
10
|
+
if (!target || target.closest('[hidden],[inert],[aria-hidden="true"]'))
|
|
11
|
+
return;
|
|
12
|
+
const dialog = Array.from(document.querySelectorAll('[role="dialog"]')).at(-1);
|
|
13
|
+
if (!dialog || dialog.contains(target))
|
|
14
|
+
target.focus();
|
|
15
|
+
}, [attempt]);
|
|
16
|
+
return { validationRef, requestValidationFocus };
|
|
17
|
+
}
|