@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
package/README.md
CHANGED
|
@@ -1,3 +1,106 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @signalsafe/content-editor-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reusable React Bootstrap content composition, extracted from lesson authoring. It owns
|
|
4
|
+
component definitions, Bootstrap rendering, the controlled Puck canvas, the component
|
|
5
|
+
outline and picker, property and responsive-layout controls, compound starter content,
|
|
6
|
+
selection/expansion state, subtree insertion/copy/removal/reordering helpers, and rich text.
|
|
7
|
+
It has no dependency on the lesson editor, simulator packages, application APIs or an
|
|
8
|
+
editor-shell package.
|
|
9
|
+
|
|
10
|
+
## Embed and configure
|
|
11
|
+
|
|
12
|
+
Use `createComponentPolicy` from `componentPolicy` to select the supported component types
|
|
13
|
+
and optionally replace the editable property definitions for a type. Its palette groups,
|
|
14
|
+
containment checks and definitions reflect that selection. Use `ComponentPicker`,
|
|
15
|
+
`ContentOutline`, `BootstrapProperties`, `LayoutPropertyFields`, `useContentSelection`,
|
|
16
|
+
`bootstrapFamilies`, and `authoringActions` within the host's existing authoring layout.
|
|
17
|
+
All imports use their direct owning module; there are no forwarding exports.
|
|
18
|
+
|
|
19
|
+
`ContentEditor` accepts a typed Puck configuration and document, selected ID, callbacks,
|
|
20
|
+
and a rejection revision. The host owns document projection, validation, history and
|
|
21
|
+
persistence. Empty selection chooses the root; null represents a selection outside the
|
|
22
|
+
content canvas. External changes synchronize without another history entry. Increment
|
|
23
|
+
`rejectionRevision` when rejecting a canvas edit to restore the authoritative projection.
|
|
24
|
+
|
|
25
|
+
`BootstrapProperties` uses the canonical generated component validators by default.
|
|
26
|
+
Hosts can supply `acceptsValue` to enforce their domain's property rules, a narrowed
|
|
27
|
+
`properties` list, and their permitted `actions`. Its default actions manipulate content;
|
|
28
|
+
slide navigation is enabled explicitly by the lesson host. `ContentInteractionProvider`
|
|
29
|
+
owns local component state and delegates host actions to `onAction`; `canExecute` controls
|
|
30
|
+
availability. `ContentRuntimeProvider` supports hosts with their own interaction session.
|
|
31
|
+
|
|
32
|
+
The current component data shapes are generated from the canonical Pydantic contract
|
|
33
|
+
closure. Generated names preserve existing saved-format compatibility, including legacy
|
|
34
|
+
`Slide*` names. Do not edit `src/contracts` by hand. DeliveryPlus's
|
|
35
|
+
`yarn lesson-editor:contracts` regenerates both package closures and
|
|
36
|
+
`yarn lesson-editor:check` detects drift. These are component schemas, not lesson workflow
|
|
37
|
+
or simulator schemas. Embedding domains remain responsible for full-document semantics.
|
|
38
|
+
|
|
39
|
+
## Rich text and styles
|
|
40
|
+
|
|
41
|
+
`MarkdownEditor`, `InlineCanvasEditor` and `BootstrapInlineCanvasEditor` provide rich text.
|
|
42
|
+
`BootstrapInlineText` owns safe rendering/sanitization and `inlineMarkup` owns authored
|
|
43
|
+
markup/URL checks. Plain text stays literal, executable content is rejected and initial
|
|
44
|
+
normalization does not emit an authored edit. Import `styles.css` for the shared text
|
|
45
|
+
styles; the embedding application supplies Bootstrap CSS and its surrounding layout.
|
|
46
|
+
|
|
47
|
+
## Lesson integration
|
|
48
|
+
|
|
49
|
+
DeliveryPlus uses the lesson editor for slide authoring. The lesson editor selects its
|
|
50
|
+
palette through `slideContentPolicy`, adds its core slide components, adapts navigation
|
|
51
|
+
and playback to content interactions, and retains slide validation, narration, timing,
|
|
52
|
+
transitions, simulator integration, publication and recovery. The saved slide format is
|
|
53
|
+
unchanged. Other existing generic text fields may use their owning text primitives;
|
|
54
|
+
there is no parallel slide editor in DeliveryPlus.
|
|
55
|
+
|
|
56
|
+
Run `yarn install --frozen-lockfile`, `yarn typecheck`, `yarn lint`, `yarn test:coverage`
|
|
57
|
+
and `yarn build`. `npm pack --ignore-scripts` produces portable ESM, declarations, CSS
|
|
58
|
+
and a source fingerprint manifest. Local candidate archives are not published releases.
|
|
59
|
+
|
|
60
|
+
## Sandstone showcase
|
|
61
|
+
|
|
62
|
+
The editable [component showcase](showcase/README.md) uses the official Bootswatch
|
|
63
|
+
Sandstone theme and the built package. Explore nested components, edit properties,
|
|
64
|
+
try interactions, change canvas width, and inspect/import/export JSON. Save draft
|
|
65
|
+
captures an explicit checkpoint; confirmed Cancel restores it separately from
|
|
66
|
+
automatic recovery drafts.
|
|
67
|
+
The Pages workflow is ready for a manual deployment after GitHub Pages is enabled;
|
|
68
|
+
adding the showcase does not publish it automatically.
|
|
69
|
+
|
|
70
|
+
## Shared editing contract
|
|
71
|
+
|
|
72
|
+
`contentEditingCommands` owns component navigation and safe history shortcut
|
|
73
|
+
routing. `useContentHistory` owns bounded snapshots and typing groups; hosts can
|
|
74
|
+
retain a captured history state across navigation. `contentInsertion` orders
|
|
75
|
+
structural families. `contentTreeValidation` owns common relationships, action
|
|
76
|
+
references, bounds, media and rich-text safety. `useContentReorderTarget` supplies
|
|
77
|
+
the same insertion feedback to native canvas surfaces and the shared outline.
|
|
78
|
+
Both the gallery and lesson editor use these owners. The lesson stylesheet imports
|
|
79
|
+
the shared editing guides. See [the parity matrix](showcase/EDITING_PARITY.md).
|
|
80
|
+
|
|
81
|
+
JsonTextEditor and JsonEditor.css own the shared raw JSON surface used by lesson authoring and the standalone content editor. Hosts supply the JSONEditor global; the standalone showcase bundles the pinned runtime locally. Incomplete drafts and the fallback textarea retain exact source text.
|
|
82
|
+
|
|
83
|
+
Shared editor chrome is rendered by `EditorPanel`, `EditorTabs`, `EditorCollectionRow` and `EditorCanvasToolbar`. Both page and lesson editors consume these components; document policy, workflow actions, content and persistence remain host-owned. Visual regression scenarios in DeliveryPlus exercise both real showcases. Successful local draft saves are silent; recovery failures retain their actions.
|
|
84
|
+
|
|
85
|
+
## Shared editor layout
|
|
86
|
+
|
|
87
|
+
Both editors use a compact command bar, Layout → Theme/Variant and Panels menus,
|
|
88
|
+
Canvas/Settings/Source tabs, and a page-level status bar containing selection
|
|
89
|
+
breadcrumbs and keyboard help. Canvas theme, light/dark variant and Bootstrap
|
|
90
|
+
width are Settings fields, independent of site appearance. The content Elements
|
|
91
|
+
panel lists root children; page properties live in Settings without a page list row.
|
|
92
|
+
|
|
93
|
+
The picker groups icon tiles under family headings in Layout, Content, Forms and
|
|
94
|
+
Components tabs; lessons add their own Lesson tab. Outline and breadcrumb labels
|
|
95
|
+
share picker icons and omit redundant parent-family prefixes. Grid import and
|
|
96
|
+
saved-document migration recognize Row/Column classes while preserving responsive
|
|
97
|
+
values and ordinary Group wrappers. Inline formatting, including code, remains
|
|
98
|
+
editable in the surrounding text. Disclosure selection, authoring guides, overlays,
|
|
99
|
+
focus, internal scrollbars and theme-aware controls are shared with lessons.
|
|
100
|
+
|
|
101
|
+
See [the shared behavior contract](showcase/EDITING_PARITY.md) for ownership and
|
|
102
|
+
intentional host differences.
|
|
103
|
+
|
|
104
|
+
## Registry release
|
|
105
|
+
|
|
106
|
+
Version 0.1.1 owns the reusable read-only `JsonViewer` (including expand/collapse controls) and `useValidationFocus`, alongside the existing content editing modules.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
import type { BootstrapBlock } from "./bootstrapRegistry.js";
|
|
3
|
+
export type BootstrapBlockRendererProps = Readonly<{
|
|
4
|
+
block: BootstrapBlock;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
surfaceProps?: HTMLAttributes<HTMLElement>;
|
|
7
|
+
elementRef?: (node: HTMLElement | null) => void;
|
|
8
|
+
}>;
|
|
9
|
+
/** Bootstrap owns presentation; the host supplies editable child slots and root interaction props. */
|
|
10
|
+
export declare function BootstrapBlockRenderer({ block, children, surfaceProps, elementRef, }: BootstrapBlockRendererProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ContentImage } from "./ContentImage.js";
|
|
3
|
+
import { BootstrapNavigationBlock, isNavigationBlock } from "./BootstrapNavigationBlocks.js";
|
|
4
|
+
import { responsiveContainerClassName, stackLayoutStyle, rowLayoutClassName, rowLayoutStyle, columnLayoutStyle, } from "./responsiveLayout.js";
|
|
5
|
+
import { useContentRuntime } from "./ContentRuntime.js";
|
|
6
|
+
import { InteractiveBootstrapBlock, isInteractiveBlock, } from "./InteractiveBootstrapBlocks.js";
|
|
7
|
+
import { slideAppearance, spacingStyles } from "./slideAppearance.js";
|
|
8
|
+
import { createElement } from "react";
|
|
9
|
+
import { Alert, Row, Col, Spinner, CloseButton, Placeholder, Stack, Badge, Card, CardGroup, Container, Figure, ListGroup, Table, } from "react-bootstrap";
|
|
10
|
+
import { BootstrapInlineText, safeBootstrapUrl } from "./BootstrapInlineText.js";
|
|
11
|
+
/** Bootstrap owns presentation; the host supplies editable child slots and root interaction props. */
|
|
12
|
+
export function BootstrapBlockRenderer({ block, children, surfaceProps, elementRef, }) {
|
|
13
|
+
const runtime = useContentRuntime();
|
|
14
|
+
if (block.type === "Image")
|
|
15
|
+
return _jsx(ContentImage, { ...block.props, surfaceProps: { ...surfaceProps, id: `${runtime.scopeId}-${block.props.id}` }, elementRef: elementRef });
|
|
16
|
+
if (block.type === "Row" || block.type === "Column") {
|
|
17
|
+
const shared = {
|
|
18
|
+
...surfaceProps, id: `${runtime.scopeId}-${block.props.id}`,
|
|
19
|
+
"aria-label": block.props.ariaLabel ?? surfaceProps?.["aria-label"],
|
|
20
|
+
"data-bs-theme": block.props.colorMode ?? undefined,
|
|
21
|
+
ref: elementRef,
|
|
22
|
+
className: [block.type === "Row" ? rowLayoutClassName(block.props) : "lesson-layout-column", slideAppearance(block.props), block.props.cssClasses, surfaceProps?.className].filter(Boolean).join(" "),
|
|
23
|
+
style: { ...surfaceProps?.style, ...spacingStyles(block.props), ...(block.type === "Row" ? rowLayoutStyle(block.props) : columnLayoutStyle(block.props)) },
|
|
24
|
+
};
|
|
25
|
+
return block.type === "Row" ? _jsx(Row, { ...shared, children: children }) : _jsx(Col, { ...shared, children: children });
|
|
26
|
+
}
|
|
27
|
+
const data = block.props;
|
|
28
|
+
const className = [
|
|
29
|
+
slideAppearance(data),
|
|
30
|
+
data.cssClasses,
|
|
31
|
+
data.alignment ? `text-${data.alignment}` : "",
|
|
32
|
+
data.spacing
|
|
33
|
+
? { compact: "p-1", normal: "p-3", relaxed: "p-5" }[data.spacing]
|
|
34
|
+
: "",
|
|
35
|
+
data.background ? `bg-${data.background}` : "",
|
|
36
|
+
surfaceProps?.className ?? "",
|
|
37
|
+
]
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.join(" ");
|
|
40
|
+
const shared = {
|
|
41
|
+
...surfaceProps,
|
|
42
|
+
id: `${runtime.scopeId}-${data.id}`,
|
|
43
|
+
"aria-label": data.ariaLabel ?? surfaceProps?.["aria-label"],
|
|
44
|
+
className,
|
|
45
|
+
"data-bs-theme": data.colorMode ?? undefined,
|
|
46
|
+
ref: elementRef,
|
|
47
|
+
style: { ...surfaceProps?.style, ...spacingStyles(data) },
|
|
48
|
+
};
|
|
49
|
+
if (isNavigationBlock(block))
|
|
50
|
+
return _jsx(BootstrapNavigationBlock, { block: block, shared: shared, children: children });
|
|
51
|
+
if (isInteractiveBlock(block))
|
|
52
|
+
return (_jsx(InteractiveBootstrapBlock, { block: block, shared: shared, children: children }));
|
|
53
|
+
switch (block.type) {
|
|
54
|
+
case "CloseButton":
|
|
55
|
+
return _jsx(CloseButton, { ...shared, "aria-label": block.props.ariaLabel ?? block.props.label, disabled: block.props.disabled, onClick: () => { if (!runtime.authoring && block.props.parentId)
|
|
56
|
+
runtime.update(block.props.parentId, { open: false }); } });
|
|
57
|
+
case "Placeholder":
|
|
58
|
+
return _jsx("div", { ...shared, "data-content-edit-guide-root": runtime.authoring || undefined, className: [className, block.props.animation ? `placeholder-${block.props.animation}` : ""].filter(Boolean).join(" "), children: _jsx(Placeholder, { "data-content-edit-guide": runtime.authoring || undefined, "data-content-edit-static": runtime.authoring || undefined, "aria-hidden": "true", xs: block.props.xs, sm: block.props.sm ?? undefined, md: block.props.md ?? undefined, lg: block.props.lg ?? undefined, xl: block.props.xl ?? undefined, xxl: block.props.xxl ?? undefined, bg: block.props.variant, size: block.props.size ?? undefined, children: "\u00A0" }) });
|
|
59
|
+
case "PlaceholderButton":
|
|
60
|
+
return _jsx("div", { ...shared, "data-content-edit-guide-root": runtime.authoring || undefined, className: [className, block.props.animation ? `placeholder-${block.props.animation}` : ""].filter(Boolean).join(" "), children: _jsx(Placeholder.Button, { "data-content-edit-guide": runtime.authoring || undefined, "data-content-edit-static": runtime.authoring || undefined, "aria-hidden": "true", tabIndex: -1, disabled: true, xs: block.props.xs, sm: block.props.sm ?? undefined, md: block.props.md ?? undefined, lg: block.props.lg ?? undefined, xl: block.props.xl ?? undefined, xxl: block.props.xxl ?? undefined, variant: block.props.variant, size: block.props.size ?? undefined }) });
|
|
61
|
+
case "Spinner":
|
|
62
|
+
return _jsx(Spinner, { ...shared, "data-content-edit-static": runtime.authoring || undefined, animation: block.props.animation, variant: block.props.variant, size: block.props.size ?? undefined, role: "status", children: _jsx("span", { className: "visually-hidden", children: block.props.label }) });
|
|
63
|
+
case "Stack":
|
|
64
|
+
case "Divider":
|
|
65
|
+
case "Alert":
|
|
66
|
+
case "ContentList":
|
|
67
|
+
case "ContentListItem":
|
|
68
|
+
case "DescriptionList":
|
|
69
|
+
case "DescriptionTerm":
|
|
70
|
+
case "DescriptionDetails":
|
|
71
|
+
return renderContentBlock({ block, children, shared, className, runtime });
|
|
72
|
+
case "Container":
|
|
73
|
+
case "Text":
|
|
74
|
+
case "Figure":
|
|
75
|
+
case "Blockquote":
|
|
76
|
+
case "Figcaption":
|
|
77
|
+
case "Cite":
|
|
78
|
+
return renderLayoutBlock({ block, children, shared, className, authoring: runtime.authoring });
|
|
79
|
+
case "Table":
|
|
80
|
+
case "TableHead":
|
|
81
|
+
case "TableBody":
|
|
82
|
+
case "TableFoot":
|
|
83
|
+
case "TableRow":
|
|
84
|
+
case "TableHeader":
|
|
85
|
+
case "TableCell":
|
|
86
|
+
case "TableCaption":
|
|
87
|
+
return renderTableBlock({ block, children, shared, className });
|
|
88
|
+
case "Indicator":
|
|
89
|
+
case "Badge":
|
|
90
|
+
case "ListGroup":
|
|
91
|
+
case "ListGroupItem":
|
|
92
|
+
return renderIndicatorBlock({ block, children, shared, className });
|
|
93
|
+
case "Card":
|
|
94
|
+
case "CardHeader":
|
|
95
|
+
case "CardBody":
|
|
96
|
+
case "CardFooter":
|
|
97
|
+
case "CardTitle":
|
|
98
|
+
case "CardSubtitle":
|
|
99
|
+
case "CardText":
|
|
100
|
+
case "CardLink":
|
|
101
|
+
case "CardImage":
|
|
102
|
+
case "CardImageOverlay":
|
|
103
|
+
case "CardGroup":
|
|
104
|
+
return renderCardBlock({ block, children, shared, className, authoring: runtime.authoring });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function authoringTextSurface(shared, element, authoring) {
|
|
108
|
+
if (!authoring)
|
|
109
|
+
return shared;
|
|
110
|
+
const headingLevel = ["h1", "h2", "h3", "h4", "h5", "h6"].indexOf(element) + 1;
|
|
111
|
+
let typography = element === "p" || element === "lead" ? "lesson-bootstrap-paragraph" : "";
|
|
112
|
+
if (headingLevel > 0)
|
|
113
|
+
typography = element;
|
|
114
|
+
return {
|
|
115
|
+
...shared,
|
|
116
|
+
className: [shared.className, typography].filter(Boolean).join(" "),
|
|
117
|
+
role: headingLevel > 0 ? "heading" : shared.role,
|
|
118
|
+
"aria-level": headingLevel > 0 ? headingLevel : shared["aria-level"],
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function renderContentBlock({ block, children, shared, className, runtime }) {
|
|
122
|
+
switch (block.type) {
|
|
123
|
+
case "Stack":
|
|
124
|
+
return (_jsx(Stack, { ...shared, direction: block.props.direction, gap: block.props.gap, style: {
|
|
125
|
+
...shared.style,
|
|
126
|
+
...stackLayoutStyle(block.props),
|
|
127
|
+
}, className: `${className} lesson-responsive-stack justify-content-${block.props.justify} align-items-${block.props.align} ${block.props.wrap ? "flex-wrap" : "flex-nowrap"}`, children: children }));
|
|
128
|
+
case "Divider":
|
|
129
|
+
return block.props.direction === "vertical" ? (_jsx("hr", { ...shared, className: `${className} vr`, style: { border: 0, margin: 0, ...shared.style }, "aria-orientation": "vertical" })) : (_jsx("hr", { ...shared }));
|
|
130
|
+
case "Alert":
|
|
131
|
+
return (_jsx(Alert, { ...shared, variant: block.props.variant, dismissible: !runtime.authoring && block.props.dismissible, show: runtime.authoring ||
|
|
132
|
+
(runtime.state[block.props.id]?.open ?? true), onClose: () => runtime.update(block.props.id, { open: false }), children: children }));
|
|
133
|
+
case "ContentList":
|
|
134
|
+
return createElement(block.props.ordered ? "ol" : "ul", {
|
|
135
|
+
...shared,
|
|
136
|
+
className: `${className} ${block.props.unstyled ? "list-unstyled" : ""} ${block.props.inline ? "list-inline" : ""}`,
|
|
137
|
+
}, children);
|
|
138
|
+
case "ContentListItem":
|
|
139
|
+
return _jsx("li", { ...shared, children: children });
|
|
140
|
+
case "DescriptionList":
|
|
141
|
+
return _jsx("dl", { ...shared, children: children });
|
|
142
|
+
case "DescriptionTerm":
|
|
143
|
+
return _jsx("dt", { ...shared, children: children });
|
|
144
|
+
case "DescriptionDetails":
|
|
145
|
+
return _jsx("dd", { ...shared, children: children });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function renderLayoutBlock({ block, children, shared, className, authoring }) {
|
|
149
|
+
switch (block.type) {
|
|
150
|
+
case "Container":
|
|
151
|
+
return (_jsx(Container, { ...shared, fluid: block.props.fluid, className: [
|
|
152
|
+
className,
|
|
153
|
+
responsiveContainerClassName(block.props.fluid),
|
|
154
|
+
`p-${block.props.padding ?? 3}`,
|
|
155
|
+
]
|
|
156
|
+
.filter(Boolean)
|
|
157
|
+
.join(" "), children: children }));
|
|
158
|
+
case "Text": {
|
|
159
|
+
const element = block.props.element === "lead" ? "p" : block.props.element;
|
|
160
|
+
const textShared = authoringTextSurface(shared, block.props.element, authoring);
|
|
161
|
+
return createElement(authoring ? "div" : element, {
|
|
162
|
+
...textShared,
|
|
163
|
+
className: [
|
|
164
|
+
textShared.className,
|
|
165
|
+
block.props.element === "lead" ? "lead" : "",
|
|
166
|
+
]
|
|
167
|
+
.filter(Boolean)
|
|
168
|
+
.join(" "),
|
|
169
|
+
}, children ?? (_jsx(BootstrapInlineText, { text: block.props.text, format: block.props.format })));
|
|
170
|
+
}
|
|
171
|
+
case "Figure":
|
|
172
|
+
return _jsx(Figure, { ...shared, children: children });
|
|
173
|
+
case "Blockquote":
|
|
174
|
+
return (_jsx("blockquote", { ...shared, className: [className, "blockquote"]
|
|
175
|
+
.filter(Boolean)
|
|
176
|
+
.join(" "), children: children }));
|
|
177
|
+
case "Figcaption":
|
|
178
|
+
return _jsx(Figure.Caption, { ...shared, children: children });
|
|
179
|
+
case "Cite":
|
|
180
|
+
return _jsx("cite", { ...shared, children: children });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function renderTableBlock({ block, children, shared, className }) {
|
|
184
|
+
switch (block.type) {
|
|
185
|
+
case "Table":
|
|
186
|
+
return (_jsx(Table, { ...shared, striped: block.props.stripedColumns
|
|
187
|
+
? "columns"
|
|
188
|
+
: block.props.striped, size: block.props.compact ? "sm" : undefined, borderless: block.props.borderless ?? undefined, variant: block.props.variant ?? undefined, className: `${className} ${block.props.captionTop ? "caption-top" : ""}`, bordered: block.props.bordered, hover: block.props.hover, responsive: block.props.responsive
|
|
189
|
+
? (block.props.responsiveBreakpoint ?? true)
|
|
190
|
+
: false, children: children }));
|
|
191
|
+
case "TableHead":
|
|
192
|
+
return _jsx("thead", { ...shared, children: children });
|
|
193
|
+
case "TableBody":
|
|
194
|
+
return _jsx("tbody", { ...shared, children: children });
|
|
195
|
+
case "TableFoot":
|
|
196
|
+
return _jsx("tfoot", { ...shared, children: children });
|
|
197
|
+
case "TableRow":
|
|
198
|
+
return _jsx("tr", { ...shared, children: children });
|
|
199
|
+
case "TableHeader":
|
|
200
|
+
return (_jsx("th", { ...shared, scope: block.props.scope, colSpan: block.props.colSpan, rowSpan: block.props.rowSpan, children: children }));
|
|
201
|
+
case "TableCell":
|
|
202
|
+
return (_jsx("td", { ...shared, colSpan: block.props.colSpan, rowSpan: block.props.rowSpan, children: children }));
|
|
203
|
+
case "TableCaption":
|
|
204
|
+
return _jsx("caption", { ...shared, children: children });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function renderIndicatorBlock({ block, children, shared }) {
|
|
208
|
+
switch (block.type) {
|
|
209
|
+
case "Indicator":
|
|
210
|
+
return (_jsx(Badge, { ...shared, role: "status", as: block.props.element, bg: block.props.variant, pill: block.props.pill, children: block.props.text }));
|
|
211
|
+
case "Badge":
|
|
212
|
+
return (_jsx(Badge, { ...shared, as: block.props.element, bg: block.props.variant, pill: block.props.pill, children: block.props.text }));
|
|
213
|
+
case "ListGroup":
|
|
214
|
+
return (_jsx(ListGroup, { ...shared, horizontal: block.props.horizontalBreakpoint ??
|
|
215
|
+
block.props.horizontal, numbered: block.props.numbered, as: block.props.numbered ? "ol" : "ul", onSelect: undefined, variant: block.props.flush ? "flush" : undefined, children: children }));
|
|
216
|
+
case "ListGroupItem":
|
|
217
|
+
return (_jsx(ListGroup.Item, { as: "li", ...shared, variant: block.props.variant ?? undefined, active: block.props.active, disabled: block.props.disabled, children: children }));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function renderCardBlock({ block, children, shared, className, authoring }) {
|
|
221
|
+
switch (block.type) {
|
|
222
|
+
case "Card":
|
|
223
|
+
return _jsx(Card, { ...shared, children: children });
|
|
224
|
+
case "CardHeader":
|
|
225
|
+
return _jsx(Card.Header, { ...shared, children: children });
|
|
226
|
+
case "CardBody":
|
|
227
|
+
return _jsx(Card.Body, { ...shared, children: children });
|
|
228
|
+
case "CardFooter":
|
|
229
|
+
return _jsx(Card.Footer, { ...shared, children: children });
|
|
230
|
+
case "CardTitle":
|
|
231
|
+
return (_jsx(Card.Title, { ...authoringTextSurface(shared, block.props.element ?? "h5", authoring), as: authoring ? "div" : block.props.element, children: children ?? (_jsx(BootstrapInlineText, { text: block.props.text, format: block.props.format })) }));
|
|
232
|
+
case "CardSubtitle":
|
|
233
|
+
return (_jsx(Card.Subtitle, { ...authoringTextSurface(shared, block.props.element ?? "h6", authoring), as: authoring ? "div" : block.props.element, children: children ?? (_jsx(BootstrapInlineText, { text: block.props.text, format: block.props.format })) }));
|
|
234
|
+
case "CardText":
|
|
235
|
+
return (_jsx(Card.Text, { ...shared, as: authoring ? "div" : "p", children: children ?? (_jsx(BootstrapInlineText, { text: block.props.text, format: block.props.format })) }));
|
|
236
|
+
case "CardLink":
|
|
237
|
+
return (_jsx(Card.Link, { ...shared, href: safeBootstrapUrl(block.props.href), children: block.props.text }));
|
|
238
|
+
case "CardImage":
|
|
239
|
+
return (_jsx(Card.Img, { ...shared, src: block.props.src.startsWith("#")
|
|
240
|
+
? undefined
|
|
241
|
+
: safeBootstrapUrl(block.props.src, false), alt: block.props.alt, className: `${className} ${block.props.thumbnail ? "img-thumbnail" : ""} ${imageFitClass(block.props.objectFit)}`, style: block.props.aspectRatio
|
|
242
|
+
? {
|
|
243
|
+
...spacingStyles(block.props),
|
|
244
|
+
aspectRatio: block.props.aspectRatio.replace("x", " / "),
|
|
245
|
+
objectFit: block.props.objectFit ?? "cover",
|
|
246
|
+
}
|
|
247
|
+
: spacingStyles(block.props), variant: block.props.position }));
|
|
248
|
+
case "CardImageOverlay":
|
|
249
|
+
return _jsx(Card.ImgOverlay, { ...shared, children: children });
|
|
250
|
+
case "CardGroup":
|
|
251
|
+
return _jsx(CardGroup, { ...shared, children: children });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function imageFitClass(fit) {
|
|
255
|
+
return fit ? `object-fit-${fit}` : "";
|
|
256
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BootstrapBlock } from './bootstrapRegistry.js';
|
|
2
|
+
export declare function isBootstrapInlineTextBlock(block: BootstrapBlock): block is Extract<BootstrapBlock, {
|
|
3
|
+
type: 'Text' | 'CardTitle' | 'CardSubtitle' | 'CardText' | 'FormLabel' | 'InputGroupText' | 'DropdownHeader';
|
|
4
|
+
}>;
|
|
5
|
+
export declare function hasBootstrapInlineTextContent(block: BootstrapBlock): boolean;
|
|
6
|
+
export declare function BootstrapInlineCanvasEditor({ text, format, onChange, onClose }: Readonly<{
|
|
7
|
+
text: string;
|
|
8
|
+
format: 'plain' | 'html';
|
|
9
|
+
onChange: (text: string) => void;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
}>): import("react").JSX.Element;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { blockText } from './authoringActions.js';
|
|
4
|
+
import { sanitizeBootstrapHtml } from './BootstrapInlineText.js';
|
|
5
|
+
import { MarkdownEditor } from './MarkdownEditor.js';
|
|
6
|
+
import { EditorActionIcon } from './EditorActionIcon.js';
|
|
7
|
+
export function isBootstrapInlineTextBlock(block) {
|
|
8
|
+
return block.type === 'Text' || block.type === 'CardTitle' || block.type === 'CardSubtitle' || block.type === 'CardText' || block.type === 'FormLabel' || block.type === 'InputGroupText' || block.type === 'DropdownHeader';
|
|
9
|
+
}
|
|
10
|
+
export function hasBootstrapInlineTextContent(block) {
|
|
11
|
+
if (!isBootstrapInlineTextBlock(block))
|
|
12
|
+
return false;
|
|
13
|
+
if (block.type === 'Text' && block.props.element === 'span' && block.props.format === 'html' && /^\s*(?:<br\s*\/?>\s*)+$/i.test(block.props.text))
|
|
14
|
+
return true;
|
|
15
|
+
return Boolean(blockText(block.props.text).replace(/ | /g, ' ').trim());
|
|
16
|
+
}
|
|
17
|
+
export function BootstrapInlineCanvasEditor({ text, format, onChange, onClose }) {
|
|
18
|
+
const source = format === 'html' ? sanitizeBootstrapHtml(text) : text.replace(/[\\`*_[\]<>]/g, String.raw `\$&`);
|
|
19
|
+
const [markdown, setMarkdown] = useState(source);
|
|
20
|
+
const emitted = useRef(text);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (text !== emitted.current) {
|
|
23
|
+
emitted.current = text;
|
|
24
|
+
setMarkdown(source);
|
|
25
|
+
}
|
|
26
|
+
}, [text, source]);
|
|
27
|
+
return (_jsx("div", { role: "presentation", className: "content-inline-editor", "data-puck-overlay-portal": "true", onPointerDown: (event) => event.stopPropagation(), onClick: (event) => event.stopPropagation(), onKeyDownCapture: (event) => {
|
|
28
|
+
if (event.key === 'Escape') {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
event.stopPropagation();
|
|
31
|
+
onClose();
|
|
32
|
+
}
|
|
33
|
+
}, children: _jsx(MarkdownEditor, { label: "Edit text on canvas", hideLabel: true, focusOnMount: true, markdown: markdown, onChange: setMarkdown, onHtmlChange: (html) => {
|
|
34
|
+
const safe = sanitizeBootstrapHtml(html);
|
|
35
|
+
emitted.current = safe;
|
|
36
|
+
onChange(safe);
|
|
37
|
+
}, toolbarEnd: _jsx("button", { type: "button", className: "btn btn-sm btn-outline-primary ms-auto", "aria-label": "Done editing", title: "Done editing", onClick: onClose, children: _jsx(EditorActionIcon, { action: "done" }) }) }) }));
|
|
38
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Only navigation URLs are accepted; executable and embedded-data schemes never render. */
|
|
2
|
+
export declare function safeBootstrapUrl(value: string, allowContact?: boolean): string | undefined;
|
|
3
|
+
/** Inline semantics are rebuilt as React nodes, with no raw HTML or arbitrary attributes. */
|
|
4
|
+
export declare function BootstrapInlineText({ text, format, }: Readonly<{
|
|
5
|
+
text: string;
|
|
6
|
+
format?: 'plain' | 'html';
|
|
7
|
+
}>): import("react").JSX.Element;
|
|
8
|
+
/** The editor uses the exact display allowlist when initializing or serializing rich text. */
|
|
9
|
+
export declare function sanitizeBootstrapHtml(html: string): string;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { INLINE_ELEMENTS, validContentUrl, validInlineClasses } from './inlineMarkup.js';
|
|
4
|
+
const OMIT_ELEMENTS = new Set([
|
|
5
|
+
'script',
|
|
6
|
+
'style',
|
|
7
|
+
'iframe',
|
|
8
|
+
'object',
|
|
9
|
+
'embed',
|
|
10
|
+
'svg',
|
|
11
|
+
'math',
|
|
12
|
+
'template',
|
|
13
|
+
]);
|
|
14
|
+
/** Only navigation URLs are accepted; executable and embedded-data schemes never render. */
|
|
15
|
+
export function safeBootstrapUrl(value, allowContact = true) {
|
|
16
|
+
return validContentUrl(value, allowContact) ? value : undefined;
|
|
17
|
+
}
|
|
18
|
+
function linkAttributes(node, props) {
|
|
19
|
+
const href = safeBootstrapUrl(node.getAttribute('href') ?? '');
|
|
20
|
+
if (href && href.length <= 2048)
|
|
21
|
+
props.href = href;
|
|
22
|
+
const target = node.getAttribute('target');
|
|
23
|
+
if (target === '_self' || target === '_blank')
|
|
24
|
+
props.target = target;
|
|
25
|
+
if (target === '_blank')
|
|
26
|
+
props.rel = 'noopener noreferrer';
|
|
27
|
+
}
|
|
28
|
+
function inlineAttributes(node, tag) {
|
|
29
|
+
const props = {};
|
|
30
|
+
for (const attribute of ['title', 'lang']) {
|
|
31
|
+
const value = node.getAttribute(attribute);
|
|
32
|
+
if (value && value.length <= 2048)
|
|
33
|
+
props[attribute] = value;
|
|
34
|
+
}
|
|
35
|
+
const classes = node.getAttribute('class');
|
|
36
|
+
if (classes && validInlineClasses(classes))
|
|
37
|
+
props.className = classes;
|
|
38
|
+
const dir = node.getAttribute('dir');
|
|
39
|
+
if (dir === 'ltr' || dir === 'rtl' || dir === 'auto')
|
|
40
|
+
props.dir = dir;
|
|
41
|
+
if (tag === 'a')
|
|
42
|
+
linkAttributes(node, props);
|
|
43
|
+
if (tag === 'q') {
|
|
44
|
+
const cite = safeBootstrapUrl(node.getAttribute('cite') ?? '', false);
|
|
45
|
+
if (cite && cite.length <= 2048)
|
|
46
|
+
props.cite = cite;
|
|
47
|
+
}
|
|
48
|
+
if (tag === 'time') {
|
|
49
|
+
const dateTime = node.getAttribute('datetime');
|
|
50
|
+
if (dateTime && dateTime.length <= 2048)
|
|
51
|
+
props.dateTime = dateTime;
|
|
52
|
+
}
|
|
53
|
+
return props;
|
|
54
|
+
}
|
|
55
|
+
function inlineNode(node, key) {
|
|
56
|
+
if (node.nodeType === Node.TEXT_NODE)
|
|
57
|
+
return node.textContent;
|
|
58
|
+
if (!(node instanceof Element))
|
|
59
|
+
return null;
|
|
60
|
+
const tag = node.tagName.toLowerCase();
|
|
61
|
+
if (OMIT_ELEMENTS.has(tag))
|
|
62
|
+
return null;
|
|
63
|
+
const children = Array.from(node.childNodes, (child, index) => inlineNode(child, `${key}.${index}`));
|
|
64
|
+
if (!INLINE_ELEMENTS.has(tag))
|
|
65
|
+
return children;
|
|
66
|
+
const props = { ...inlineAttributes(node, tag), key };
|
|
67
|
+
return createElement(tag, props, ...(tag === 'br' || tag === 'wbr' ? [] : children));
|
|
68
|
+
}
|
|
69
|
+
/** Inline semantics are rebuilt as React nodes, with no raw HTML or arbitrary attributes. */
|
|
70
|
+
export function BootstrapInlineText({ text, format = 'plain', }) {
|
|
71
|
+
if (format === 'plain' || typeof DOMParser === 'undefined')
|
|
72
|
+
return _jsx(_Fragment, { children: text });
|
|
73
|
+
const document = new DOMParser().parseFromString(text, 'text/html');
|
|
74
|
+
return (_jsx(_Fragment, { children: Array.from(document.body.childNodes, (node, index) => inlineNode(node, String(index))) }));
|
|
75
|
+
}
|
|
76
|
+
function sanitizedNodes(node, document) {
|
|
77
|
+
if (node.nodeType === Node.TEXT_NODE)
|
|
78
|
+
return [node.cloneNode(false)];
|
|
79
|
+
if (!(node instanceof Element))
|
|
80
|
+
return [];
|
|
81
|
+
const tag = node.tagName.toLowerCase();
|
|
82
|
+
if (OMIT_ELEMENTS.has(tag))
|
|
83
|
+
return [];
|
|
84
|
+
const children = Array.from(node.childNodes).flatMap((child) => sanitizedNodes(child, document));
|
|
85
|
+
if (!INLINE_ELEMENTS.has(tag))
|
|
86
|
+
return children;
|
|
87
|
+
const element = document.createElement(tag);
|
|
88
|
+
for (const [name, value] of Object.entries(inlineAttributes(node, tag)))
|
|
89
|
+
element.setAttribute(name === 'dateTime' ? 'datetime' : name === 'className' ? 'class' : name, value);
|
|
90
|
+
if (tag !== 'br' && tag !== 'wbr') {
|
|
91
|
+
// Lexical exports underline/strike as CSS on spans. Store only their semantic tags.
|
|
92
|
+
const style = tag === 'span' ? document.createElement('span') : null;
|
|
93
|
+
if (style)
|
|
94
|
+
style.setAttribute('style', node.getAttribute('style') ?? '');
|
|
95
|
+
const decoration = `${style?.style.textDecorationLine ?? ''} ${style?.style.textDecoration ?? ''}`;
|
|
96
|
+
let content = children;
|
|
97
|
+
for (const [token, semantic] of [['underline', 'u'], ['line-through', 's']]) {
|
|
98
|
+
if (!decoration.split(/\s+/).includes(token))
|
|
99
|
+
continue;
|
|
100
|
+
const wrapper = document.createElement(semantic);
|
|
101
|
+
wrapper.append(...content);
|
|
102
|
+
content = [wrapper];
|
|
103
|
+
}
|
|
104
|
+
element.append(...content);
|
|
105
|
+
}
|
|
106
|
+
return [element];
|
|
107
|
+
}
|
|
108
|
+
/** The editor uses the exact display allowlist when initializing or serializing rich text. */
|
|
109
|
+
export function sanitizeBootstrapHtml(html) {
|
|
110
|
+
if (typeof DOMParser === 'undefined')
|
|
111
|
+
return html
|
|
112
|
+
.replaceAll('&', '&')
|
|
113
|
+
.replaceAll('<', '<')
|
|
114
|
+
.replaceAll('>', '>')
|
|
115
|
+
.replaceAll('"', '"')
|
|
116
|
+
.replaceAll("'", ''');
|
|
117
|
+
const document = new DOMParser().parseFromString(html, 'text/html');
|
|
118
|
+
const nodes = Array.from(document.body.childNodes).flatMap((node) => sanitizedNodes(node, document));
|
|
119
|
+
document.body.replaceChildren(...nodes);
|
|
120
|
+
return document.body.innerHTML;
|
|
121
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
import type { BootstrapBlock } from './bootstrapRegistry.js';
|
|
3
|
+
export declare const NAVIGATION_BLOCK_TYPES: readonly ["FormLabel", "TabContainer", "TabContent", "TabPane", "Navbar", "NavbarBrand", "NavbarToggle", "NavbarCollapse", "Nav", "NavLink", "Pagination", "PaginationItem", "InputGroup", "InputGroupText", "ProgressGroup", "DropdownDivider", "DropdownHeader"];
|
|
4
|
+
type NavigationBlock = Extract<BootstrapBlock, {
|
|
5
|
+
type: typeof NAVIGATION_BLOCK_TYPES[number];
|
|
6
|
+
}>;
|
|
7
|
+
export declare function isNavigationBlock(block: BootstrapBlock): block is NavigationBlock;
|
|
8
|
+
export declare function BootstrapNavigationBlock({ block, children, shared }: Readonly<{
|
|
9
|
+
block: NavigationBlock;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
shared: HTMLAttributes<HTMLElement>;
|
|
12
|
+
}>): import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { BootstrapProgressGroup } from './BootstrapProgressGroup.js';
|
|
3
|
+
import { useContentRuntime } from './ContentRuntime.js';
|
|
4
|
+
import { Navbar, Nav, Tab, Container, Form, Pagination, InputGroup, Dropdown } from 'react-bootstrap';
|
|
5
|
+
import { BootstrapInlineText, safeBootstrapUrl } from './BootstrapInlineText.js';
|
|
6
|
+
export const NAVIGATION_BLOCK_TYPES = ['FormLabel', 'TabContainer', 'TabContent', 'TabPane', 'Navbar', 'NavbarBrand', 'NavbarToggle', 'NavbarCollapse', 'Nav', 'NavLink', 'Pagination', 'PaginationItem', 'InputGroup', 'InputGroupText', 'ProgressGroup', 'DropdownDivider', 'DropdownHeader'];
|
|
7
|
+
export function isNavigationBlock(block) {
|
|
8
|
+
return NAVIGATION_BLOCK_TYPES.some(type => type === block.type);
|
|
9
|
+
}
|
|
10
|
+
export function BootstrapNavigationBlock({ block, children, shared }) {
|
|
11
|
+
const runtime = useContentRuntime();
|
|
12
|
+
switch (block.type) {
|
|
13
|
+
case 'FormLabel': return _jsx(Form.Label, { ...shared, column: block.props.cssClasses?.split(' ').includes('col-form-label') || undefined, htmlFor: block.props.htmlFor ? `${runtime.scopeId}-${block.props.htmlFor}` : undefined, children: children ?? _jsx(BootstrapInlineText, { text: block.props.text, format: block.props.format }) });
|
|
14
|
+
case 'TabContainer': return _jsx(Tab.Container, { activeKey: runtime.state[block.props.id]?.selected ?? block.props.defaultActiveKey, onSelect: key => { if (key !== null)
|
|
15
|
+
runtime.update(block.props.id, { selected: key }); }, children: _jsx("div", { ...shared, children: children }) });
|
|
16
|
+
case 'TabContent': return _jsx(Tab.Content, { ...shared, children: children });
|
|
17
|
+
case 'TabPane': return _jsx(Tab.Pane, { ...shared, eventKey: block.props.eventKey, children: children });
|
|
18
|
+
case 'Navbar': return _jsx(Navbar, { ...shared, onSelect: undefined, expand: block.props.expand, children: _jsx(Container, { fluid: true, children: children }) });
|
|
19
|
+
case 'NavbarBrand': return _jsx(Navbar.Brand, { ...shared, href: safeBootstrapUrl(block.props.href ?? "#"), children: children ?? block.props.text });
|
|
20
|
+
case 'NavbarToggle': return _jsx(Navbar.Toggle, { ...shared, "data-puck-overlay-portal": runtime.authoring || undefined, "aria-label": "Toggle navigation" });
|
|
21
|
+
case 'NavbarCollapse': return _jsx(Navbar.Collapse, { ...shared, children: children });
|
|
22
|
+
case 'Nav': return _jsx(Nav, { ...shared, onSelect: undefined, variant: block.props.variant ?? undefined, defaultActiveKey: block.props.defaultActiveKey || undefined, className: [shared.className, block.props.navbar ? 'navbar-nav' : '', block.props.vertical ? 'flex-column' : ''].filter(Boolean).join(' '), children: children });
|
|
23
|
+
case 'NavLink': return _jsx(Nav.Link, { ...shared, "data-puck-overlay-portal": runtime.authoring || undefined, eventKey: block.props.eventKey ?? block.props.id, disabled: block.props.disabled, href: safeBootstrapUrl(block.props.href ?? "#"), onClick: event => { if (block.props.href === '#')
|
|
24
|
+
event.preventDefault(); }, children: children ?? block.props.text });
|
|
25
|
+
case 'Pagination': return _jsx(Pagination, { ...shared, size: block.props.size ?? undefined, children: children });
|
|
26
|
+
case 'PaginationItem': return _jsx(Pagination.Item, { ...shared, active: block.props.active, disabled: block.props.disabled, onClick: event => event.preventDefault(), children: children ?? block.props.text });
|
|
27
|
+
case 'InputGroup': return _jsx(InputGroup, { ...shared, size: block.props.size ?? undefined, children: children });
|
|
28
|
+
case 'InputGroupText': return _jsx(InputGroup.Text, { ...shared, children: children ?? _jsx(BootstrapInlineText, { text: block.props.text, format: block.props.format }) });
|
|
29
|
+
case 'ProgressGroup': return _jsx(BootstrapProgressGroup, { ...shared, children: children });
|
|
30
|
+
case 'DropdownDivider': return _jsx(Dropdown.Divider, { ...shared });
|
|
31
|
+
case 'DropdownHeader': return _jsx(Dropdown.Header, { ...shared, children: children ?? _jsx(BootstrapInlineText, { text: block.props.text, format: block.props.format }) });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
import type { BootstrapBlock } from './bootstrapRegistry.js';
|
|
3
|
+
export declare const BootstrapProgressGroup: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
6
|
+
export declare function BootstrapProgressBlock({ block, shared }: Readonly<{
|
|
7
|
+
block: Extract<BootstrapBlock, {
|
|
8
|
+
type: 'Progress';
|
|
9
|
+
}>;
|
|
10
|
+
shared: HTMLAttributes<HTMLElement>;
|
|
11
|
+
}>): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, forwardRef } from 'react';
|
|
3
|
+
import { useContentRuntime } from './ContentRuntime.js';
|
|
4
|
+
import { ProgressBar } from 'react-bootstrap';
|
|
5
|
+
const NestedProgress = createContext(false);
|
|
6
|
+
export const BootstrapProgressGroup = forwardRef(function BootstrapProgressGroup({ children, ...props }, ref) {
|
|
7
|
+
const { authoring } = useContentRuntime();
|
|
8
|
+
return _jsx(NestedProgress.Provider, { value: true, children: _jsx("div", { ref: ref, ...props, "data-content-edit-guide": authoring || undefined, className: `${props.className ?? ''} progress`, children: children }) });
|
|
9
|
+
});
|
|
10
|
+
export function BootstrapProgressBlock({ block, shared }) {
|
|
11
|
+
const nested = useContext(NestedProgress);
|
|
12
|
+
return _jsx(ProgressBar, { ...shared, isChild: nested, "aria-label": block.props.ariaLabel || 'Progress', now: block.props.value, min: block.props.min, max: block.props.max, label: block.props.label, variant: block.props.variant, striped: block.props.striped, animated: block.props.animated });
|
|
13
|
+
}
|