@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,15 @@
|
|
|
1
|
+
type Action = NonNullable<Extract<ContentBlock, {
|
|
2
|
+
type: 'Button';
|
|
3
|
+
}>['props']['action']>;
|
|
4
|
+
import type { ContentBlock } from "./contentModel.js";
|
|
5
|
+
import { type BootstrapPropertyValue, type BootstrapPropertyDefinition } from "./bootstrapRegistry.js";
|
|
6
|
+
export declare function BootstrapProperties({ block, onChange, onBlocksChange, blocks, acceptsValue, properties, actions, }: Readonly<{
|
|
7
|
+
block: ContentBlock;
|
|
8
|
+
onBlocksChange?: (blocks: readonly ContentBlock[], label: string) => void;
|
|
9
|
+
acceptsValue?: (name: string, value: BootstrapPropertyValue) => boolean;
|
|
10
|
+
properties?: readonly BootstrapPropertyDefinition[];
|
|
11
|
+
actions?: readonly Action[];
|
|
12
|
+
blocks?: readonly ContentBlock[];
|
|
13
|
+
onChange: (patch: Readonly<Record<string, BootstrapPropertyValue>>) => void;
|
|
14
|
+
}>): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { componentPropertyAccepted } from './componentValidation.js';
|
|
3
|
+
const DEFAULT_ACTIONS = ['none', 'link', 'toggle', 'show', 'hide', 'select-tab'];
|
|
4
|
+
import { safeBootstrapUrl } from "./BootstrapInlineText.js";
|
|
5
|
+
import { LayoutPresets } from './LayoutPresets.js';
|
|
6
|
+
import { LayoutPropertyFields } from './LayoutPropertyFields.js';
|
|
7
|
+
import { SpacingEditor } from "./SpacingEditor.js";
|
|
8
|
+
import { appearanceProperties } from "./slideAppearance.js";
|
|
9
|
+
import { useId, useState, useEffect, useRef, useCallback } from "react";
|
|
10
|
+
import { Form } from "react-bootstrap";
|
|
11
|
+
import { bootstrapBlockDefinition, bootstrapPropertyValue, isBootstrapBlock, } from "./bootstrapRegistry.js";
|
|
12
|
+
function containerFluidValue(value) {
|
|
13
|
+
if (value === "fluid")
|
|
14
|
+
return true;
|
|
15
|
+
if (value === "fixed")
|
|
16
|
+
return false;
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
export function BootstrapProperties({ block, onChange, onBlocksChange, blocks = [], acceptsValue = (name, value) => componentPropertyAccepted(block, name, value), properties, actions = DEFAULT_ACTIONS, }) {
|
|
20
|
+
const id = useId();
|
|
21
|
+
const change = (name, value) => onChange({ [name]: value });
|
|
22
|
+
const definition = isBootstrapBlock(block)
|
|
23
|
+
? bootstrapBlockDefinition(block.type)
|
|
24
|
+
: {
|
|
25
|
+
label: block.type,
|
|
26
|
+
properties: [
|
|
27
|
+
...appearanceProperties,
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
return (_jsxs("section", { "aria-label": `${definition.label} properties`, children: [_jsxs("h3", { className: "h6", children: [definition.label, " properties"] }), onBlocksChange && _jsx(LayoutPresets, { selected: block, blocks: blocks, onChange: onBlocksChange }), (block.type === "Row" || block.type === "Column") && _jsx(LayoutPropertyFields, { block: block, onChange: (name, value) => { if (acceptsValue(name, value))
|
|
31
|
+
change(name, value); } }), (block.type === "PracticeSelect" || block.type === "FormSelect") ? (_jsx(PracticeOptionsEditor, { options: block.props.options ?? [], onChange: (options) => {
|
|
32
|
+
const selected = options.find((option) => option.value === block.props.defaultValue);
|
|
33
|
+
onChange({ options, defaultValue: selected?.value ?? "" });
|
|
34
|
+
} }, `${block.props.id}-options`)) : null, block.type === "Button" || block.type === "DropdownItem" ? (_jsx(ActionEditor, { block: block, actions: actions, blocks: blocks, onChange: onChange }, block.props.id)) : null, (properties ?? definition.properties).map((field) => {
|
|
35
|
+
if ((block.type === "Button" ||
|
|
36
|
+
block.type === "DropdownItem") &&
|
|
37
|
+
[
|
|
38
|
+
"action",
|
|
39
|
+
"targetId",
|
|
40
|
+
"targetKey",
|
|
41
|
+
"href",
|
|
42
|
+
"newWindow",
|
|
43
|
+
].includes(field.name))
|
|
44
|
+
return null;
|
|
45
|
+
if (block.type === "Container" && field.name === "fluid")
|
|
46
|
+
return (_jsxs(Form.Group, { controlId: `${id}-fluid`, className: "mb-2", children: [_jsx(Form.Label, { children: "Container width" }), _jsxs(Form.Select, { value: block.props.fluid === true
|
|
47
|
+
? "fluid"
|
|
48
|
+
: block.props.fluid || "fixed", onChange: (event) => change("fluid", containerFluidValue(event.currentTarget.value)), children: [_jsx("option", { value: "fixed", children: "Fixed" }), _jsx("option", { value: "fluid", children: "Full width" }), ["sm", "md", "lg", "xl", "xxl"].map((value) => (_jsxs("option", { value: value, children: ["Full width below ", value] }, value)))] })] }, "fluid"));
|
|
49
|
+
if (field.name === "marginTop")
|
|
50
|
+
return (_jsx(SpacingEditor, { block: block, onChange: onChange }, `${block.props.id}-spacing`));
|
|
51
|
+
if (/^(?:margin|padding)(?:Top|Bottom|Start|End)$/.test(field.name))
|
|
52
|
+
return null;
|
|
53
|
+
const value = bootstrapPropertyValue(block, field.name);
|
|
54
|
+
if (field.kind === "richText")
|
|
55
|
+
return null;
|
|
56
|
+
if (field.kind === "boolean")
|
|
57
|
+
return (_jsx(Form.Check, { id: `${id}-${field.name}`, className: "mb-2", label: field.label, checked: value === true, onChange: (event) => change(field.name, event.currentTarget.checked) }, field.name));
|
|
58
|
+
return (_jsxs(Form.Group, { controlId: `${id}-${field.name}`, className: "mb-2", children: [_jsx(Form.Label, { children: field.label }), renderPropertyInput({
|
|
59
|
+
blockId: block.props.id,
|
|
60
|
+
field: { ...field, kind: field.kind },
|
|
61
|
+
value,
|
|
62
|
+
accepts: (candidate) => acceptsValue(field.name, candidate),
|
|
63
|
+
change: (candidate) => change(field.name, candidate),
|
|
64
|
+
})] }, field.name));
|
|
65
|
+
})] }));
|
|
66
|
+
}
|
|
67
|
+
function renderPropertyInput({ blockId, field, value, accepts, change, }) {
|
|
68
|
+
if (field.kind === "select")
|
|
69
|
+
return (_jsxs(Form.Select, { value: value === null ? "" : String(value), onChange: (event) => change(event.currentTarget.value || null), children: [accepts(null) ? _jsx("option", { value: "", children: "Default" }) : null, field.options?.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value)))] }));
|
|
70
|
+
if (field.kind === "text")
|
|
71
|
+
return (_jsx(DraftTextProperty, { value: typeof value === "string" ? value : "", nullable: accepts(null), accepts: accepts, onCommit: change }, `${blockId}-${field.name}`));
|
|
72
|
+
return (_jsx(Form.Control, { type: "number", value: typeof value === "boolean" || value === null ? "" : value, min: field.min, max: field.max, step: field.step, onChange: (event) => {
|
|
73
|
+
const raw = event.currentTarget.value;
|
|
74
|
+
if (raw === "")
|
|
75
|
+
change(null);
|
|
76
|
+
else
|
|
77
|
+
change(Number(raw));
|
|
78
|
+
} }));
|
|
79
|
+
}
|
|
80
|
+
/** Keep incomplete units and URLs local until the author finishes the field. */
|
|
81
|
+
function DraftTextProperty({ value, nullable, accepts, onCommit }) {
|
|
82
|
+
const [draft, setDraft] = useState(value);
|
|
83
|
+
const [invalid, setInvalid] = useState(false);
|
|
84
|
+
useEffect(() => { setDraft(value); setInvalid(false); }, [value]);
|
|
85
|
+
const commit = () => {
|
|
86
|
+
const candidate = draft === "" && nullable ? null : draft;
|
|
87
|
+
if (!accepts(candidate)) {
|
|
88
|
+
setInvalid(true);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
setInvalid(false);
|
|
92
|
+
if (draft !== value)
|
|
93
|
+
onCommit(candidate);
|
|
94
|
+
};
|
|
95
|
+
return _jsxs(_Fragment, { children: [_jsx(Form.Control, { value: draft, isInvalid: invalid, "aria-invalid": invalid || undefined, onChange: (event) => { setDraft(event.currentTarget.value); setInvalid(false); }, onBlur: commit, onKeyDown: (event) => {
|
|
96
|
+
if (event.key === "Enter") {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
commit();
|
|
99
|
+
}
|
|
100
|
+
if (event.key === "Escape") {
|
|
101
|
+
setDraft(value);
|
|
102
|
+
setInvalid(false);
|
|
103
|
+
}
|
|
104
|
+
} }), invalid ? _jsx(Form.Control.Feedback, { type: "invalid", children: "Enter a valid value." }) : null] });
|
|
105
|
+
}
|
|
106
|
+
/** Keep client row identities out of saved choices, including incomplete duplicate values. */
|
|
107
|
+
function reconcileOptionRows(previous, options, create) {
|
|
108
|
+
const available = [...previous];
|
|
109
|
+
const matches = options.map((option) => takeMatchingOptionRow(available, option));
|
|
110
|
+
return options.map((option, index) => {
|
|
111
|
+
let reusable = matches[index];
|
|
112
|
+
const positional = previous[index];
|
|
113
|
+
if (!reusable && positional && available.includes(positional)) {
|
|
114
|
+
reusable = positional;
|
|
115
|
+
available.splice(available.indexOf(positional), 1);
|
|
116
|
+
}
|
|
117
|
+
if (!reusable)
|
|
118
|
+
return create(option);
|
|
119
|
+
return { key: reusable.key, option };
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function takeMatchingOptionRow(available, option) {
|
|
123
|
+
let index = available.findIndex((row) => row.option === option);
|
|
124
|
+
if (index < 0)
|
|
125
|
+
index = available.findIndex((row) => row.option.value === option.value && row.option.label === option.label &&
|
|
126
|
+
row.option.disabled === option.disabled);
|
|
127
|
+
if (index < 0)
|
|
128
|
+
return undefined;
|
|
129
|
+
return available.splice(index, 1)[0];
|
|
130
|
+
}
|
|
131
|
+
function PracticeOptionsEditor({ options, onChange, }) {
|
|
132
|
+
const id = useId();
|
|
133
|
+
const nextRowId = useRef(0);
|
|
134
|
+
const createRow = useCallback((option) => ({
|
|
135
|
+
key: `${id}-choice-${nextRowId.current++}`,
|
|
136
|
+
option,
|
|
137
|
+
}), [id]);
|
|
138
|
+
const [rows, setRows] = useState(() => options.map((option) => createRow(option)));
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
setRows((previous) => reconcileOptionRows(previous, options, createRow));
|
|
141
|
+
}, [options, createRow]);
|
|
142
|
+
const draft = rows.map((row) => row.option);
|
|
143
|
+
const valid = draft.length <= 50 &&
|
|
144
|
+
new Set(draft.map((option) => option.value)).size === draft.length;
|
|
145
|
+
const changeOptions = (next) => setRows((previous) => reconcileOptionRows(previous, next, createRow));
|
|
146
|
+
return (_jsxs("fieldset", { className: "mb-3", children: [_jsx("legend", { className: "h6", children: "Choices" }), rows.map(({ option, key }, index) => (_jsxs("div", { className: "border rounded p-2 mb-2", children: [_jsxs(Form.Group, { controlId: `${id}-${index}-label`, children: [_jsxs(Form.Label, { children: ["Choice ", index + 1, " label"] }), _jsx(Form.Control, { value: option.label, onChange: (event) => changeOptions(draft.map((entry, position) => position === index
|
|
147
|
+
? {
|
|
148
|
+
...entry,
|
|
149
|
+
label: event.currentTarget
|
|
150
|
+
.value,
|
|
151
|
+
}
|
|
152
|
+
: entry)) })] }), _jsxs(Form.Group, { controlId: `${id}-${index}-value`, children: [_jsxs(Form.Label, { children: ["Choice ", index + 1, " value"] }), _jsx(Form.Control, { value: option.value, onChange: (event) => changeOptions(draft.map((entry, position) => position === index
|
|
153
|
+
? {
|
|
154
|
+
...entry,
|
|
155
|
+
value: event.currentTarget
|
|
156
|
+
.value,
|
|
157
|
+
}
|
|
158
|
+
: entry)) })] }), _jsx(Form.Check, { id: `${id}-${index}-disabled`, label: "Disabled", checked: option.disabled ?? false, onChange: (event) => changeOptions(draft.map((entry, position) => position === index
|
|
159
|
+
? {
|
|
160
|
+
...entry,
|
|
161
|
+
disabled: event.currentTarget.checked,
|
|
162
|
+
}
|
|
163
|
+
: entry)) }), _jsxs("button", { type: "button", className: "btn btn-outline-danger btn-sm", onClick: () => changeOptions(draft.filter((_, position) => position !== index)), children: ["Remove choice ", index + 1] })] }, key))), _jsx("button", { type: "button", className: "btn btn-primary btn-sm me-2", disabled: !valid, onClick: () => onChange([...draft]), children: "Apply choices" }), _jsx("button", { type: "button", className: "btn btn-outline-primary btn-sm", disabled: draft.length >= 50, onClick: () => changeOptions([
|
|
164
|
+
...draft,
|
|
165
|
+
{
|
|
166
|
+
label: `Choice ${draft.length + 1}`,
|
|
167
|
+
value: `choice-${draft.length + 1}`,
|
|
168
|
+
disabled: false,
|
|
169
|
+
},
|
|
170
|
+
]), children: "Add choice" })] }));
|
|
171
|
+
}
|
|
172
|
+
function ActionEditor({ block, blocks, actions, onChange, }) {
|
|
173
|
+
const id = useId();
|
|
174
|
+
const [action, setAction] = useState(block.props.action ?? "none");
|
|
175
|
+
const [targetId, setTargetId] = useState(block.props.targetId ?? "");
|
|
176
|
+
const [targetKey, setTargetKey] = useState(block.props.targetKey ?? "");
|
|
177
|
+
const [href, setHref] = useState(block.props.href ?? "");
|
|
178
|
+
const [newWindow, setNewWindow] = useState(block.props.newWindow ?? false);
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
setAction(block.props.action ?? "none");
|
|
181
|
+
setTargetId(block.props.targetId ?? "");
|
|
182
|
+
setTargetKey(block.props.targetKey ?? "");
|
|
183
|
+
setHref(block.props.href ?? "");
|
|
184
|
+
setNewWindow(block.props.newWindow ?? false);
|
|
185
|
+
}, [
|
|
186
|
+
block.props.action,
|
|
187
|
+
block.props.targetId,
|
|
188
|
+
block.props.targetKey,
|
|
189
|
+
block.props.href,
|
|
190
|
+
block.props.newWindow,
|
|
191
|
+
]);
|
|
192
|
+
const targets = blocks.filter((candidate) => action === "select-tab"
|
|
193
|
+
? candidate.type === "Tabs"
|
|
194
|
+
: ["Reveal", "Modal", "Offcanvas", "Toast"].includes(candidate.type));
|
|
195
|
+
const tabs = blocks
|
|
196
|
+
.filter((candidate) => candidate.type === "Tab")
|
|
197
|
+
.filter((candidate) => candidate.props.parentId === targetId && !candidate.props.disabled);
|
|
198
|
+
const needsTarget = ["toggle", "show", "hide", "select-tab"].includes(action);
|
|
199
|
+
return (_jsxs("fieldset", { className: "border rounded p-2 mb-3", children: [_jsx("legend", { className: "h6", children: "Button action" }), _jsxs(Form.Group, { controlId: `${id}-action`, children: [_jsx(Form.Label, { children: "Action" }), _jsx(Form.Select, { value: action, onChange: (event) => {
|
|
200
|
+
const value = actions.find((candidate) => candidate === event.currentTarget.value);
|
|
201
|
+
if (value)
|
|
202
|
+
setAction(value);
|
|
203
|
+
}, children: actions.map((value) => (_jsx("option", { value: value, children: value }, value))) })] }), action === "link" ? (_jsxs(_Fragment, { children: [_jsxs(Form.Group, { controlId: `${id}-href`, children: [_jsx(Form.Label, { children: "Link URL" }), _jsx(Form.Control, { value: href, onChange: (event) => setHref(event.currentTarget.value) })] }), _jsx(Form.Check, { id: `${id}-window`, label: "Open in a new window", checked: newWindow, onChange: (event) => setNewWindow(event.currentTarget.checked) })] })) : null, needsTarget ? (_jsxs(Form.Group, { controlId: `${id}-target`, children: [_jsx(Form.Label, { children: "Target component" }), _jsxs(Form.Select, { value: targetId, onChange: (event) => {
|
|
204
|
+
setTargetId(event.currentTarget.value);
|
|
205
|
+
setTargetKey("");
|
|
206
|
+
}, children: [_jsx("option", { value: "", children: "Choose a component" }), targets.map((candidate) => (_jsxs("option", { value: candidate.props.id, children: [candidate.type, " \u00B7 ", candidate.props.id] }, candidate.props.id)))] })] })) : null, action === "select-tab" ? (_jsxs(Form.Group, { controlId: `${id}-tab`, children: [_jsx(Form.Label, { children: "Target tab" }), _jsxs(Form.Select, { value: targetKey, onChange: (event) => setTargetKey(event.currentTarget.value), children: [_jsx("option", { value: "", children: "Choose a tab" }), tabs.map((candidate) => (_jsx("option", { value: candidate.props.eventKey, children: candidate.props.title }, candidate.props.id)))] })] })) : null, _jsx("button", { type: "button", className: "btn btn-primary btn-sm mt-2", disabled: (needsTarget &&
|
|
207
|
+
!targets.some((target) => target.props.id === targetId)) ||
|
|
208
|
+
(action === "select-tab" &&
|
|
209
|
+
!tabs.some((tab) => tab.props.eventKey === targetKey)) ||
|
|
210
|
+
(action === "link" && !safeBootstrapUrl(href)), onClick: () => onChange({
|
|
211
|
+
action,
|
|
212
|
+
targetId: needsTarget ? targetId : null,
|
|
213
|
+
targetKey: action === "select-tab" ? targetKey : null,
|
|
214
|
+
href: action === "link" ? href : null,
|
|
215
|
+
newWindow: action === "link" && newWindow,
|
|
216
|
+
}), children: "Apply action" })] }));
|
|
217
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CanvasEditorKind } from './canvasPreferences.js';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import { type EditorColorMode, type EditorTheme } from './editorThemes.js';
|
|
4
|
+
export declare function CanvasThemeProvider({ children, editor }: Readonly<{
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
editor?: CanvasEditorKind;
|
|
7
|
+
}>): import("react").JSX.Element;
|
|
8
|
+
export declare function useCanvasTheme(): Readonly<{
|
|
9
|
+
theme: EditorTheme;
|
|
10
|
+
colorMode: EditorColorMode;
|
|
11
|
+
setColorMode: (mode: EditorColorMode) => void;
|
|
12
|
+
setTheme: (theme: EditorTheme) => void;
|
|
13
|
+
width: number | null;
|
|
14
|
+
setWidth: (width: number | null) => void;
|
|
15
|
+
}> | null;
|
|
16
|
+
export declare function useCanvasThemeAttributes(): {
|
|
17
|
+
readonly 'data-canvas-theme': "Sandstone" | "Bootstrap" | "Flatly" | "Darkly" | "Litera" | "Lux" | "Minty" | "Slate" | "Superhero" | "Cyborg";
|
|
18
|
+
readonly 'data-bs-theme': EditorColorMode;
|
|
19
|
+
readonly 'data-editor-color-scheme': EditorColorMode;
|
|
20
|
+
} | {
|
|
21
|
+
readonly 'data-canvas-theme'?: undefined;
|
|
22
|
+
readonly 'data-bs-theme'?: undefined;
|
|
23
|
+
readonly 'data-editor-color-scheme'?: undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare function CanvasThemeSelect(): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ColorModeSelect } from './ColorModeSelect.js';
|
|
3
|
+
import { loadCanvasPreferences, saveCanvasPreferences } from './canvasPreferences.js';
|
|
4
|
+
import { createContext, useContext, useMemo, useState, useEffect, useCallback } from 'react';
|
|
5
|
+
import { EDITOR_THEMES, isEditorTheme, editorColorScheme } from './editorThemes.js';
|
|
6
|
+
const CanvasThemeContext = createContext(null);
|
|
7
|
+
export function CanvasThemeProvider({ children, editor }) {
|
|
8
|
+
const [preferences, setPreferences] = useState(() => loadCanvasPreferences(editor));
|
|
9
|
+
const setTheme = useCallback((theme) => setPreferences(previous => ({ ...previous, theme })), []);
|
|
10
|
+
const setColorMode = useCallback((colorMode) => setPreferences(previous => ({ ...previous, colorMode })), []);
|
|
11
|
+
const setWidth = useCallback((width) => {
|
|
12
|
+
if (width !== null && (!Number.isInteger(width) || width < 240 || width > 7680))
|
|
13
|
+
return;
|
|
14
|
+
setPreferences(previous => ({ ...previous, width }));
|
|
15
|
+
}, []);
|
|
16
|
+
useEffect(() => { if (editor)
|
|
17
|
+
saveCanvasPreferences(editor, preferences); }, [editor, preferences]);
|
|
18
|
+
const value = useMemo(() => ({ theme: preferences.theme, colorMode: preferences.colorMode, setColorMode, setTheme, width: preferences.width, setWidth }), [preferences, setTheme, setWidth, setColorMode]);
|
|
19
|
+
return _jsx(CanvasThemeContext.Provider, { value: value, children: children });
|
|
20
|
+
}
|
|
21
|
+
export function useCanvasTheme() { return useContext(CanvasThemeContext); }
|
|
22
|
+
export function useCanvasThemeAttributes() {
|
|
23
|
+
const state = useContext(CanvasThemeContext);
|
|
24
|
+
return state ? { 'data-canvas-theme': state.theme, 'data-bs-theme': state.colorMode, 'data-editor-color-scheme': editorColorScheme(state.theme, state.colorMode) } : {};
|
|
25
|
+
}
|
|
26
|
+
export function CanvasThemeSelect() {
|
|
27
|
+
const state = useContext(CanvasThemeContext);
|
|
28
|
+
if (!state)
|
|
29
|
+
return null;
|
|
30
|
+
return _jsxs(_Fragment, { children: [_jsx("select", { "aria-label": "Canvas theme", className: "form-select form-select-sm w-auto", value: state.theme, onChange: event => {
|
|
31
|
+
if (isEditorTheme(event.currentTarget.value))
|
|
32
|
+
state.setTheme(event.currentTarget.value);
|
|
33
|
+
}, children: EDITOR_THEMES.map(theme => _jsx("option", { children: theme }, theme)) }), _jsx(ColorModeSelect, { label: "Canvas color mode", value: state.colorMode, onChange: state.setColorMode })] });
|
|
34
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Ref } from 'react';
|
|
2
|
+
type Action = 'duplicate' | 'up' | 'down' | 'add' | 'delete';
|
|
3
|
+
/** One owner for page/slide row actions; document policy stays with the host. */
|
|
4
|
+
export declare function CollectionRowActions({ index, count, readOnly, duplicateDisabled, addDisabled, labels, titles, className, addButtonRef, onDuplicate, onMove, onAdd, onDelete, }: Readonly<{
|
|
5
|
+
addButtonRef?: Ref<HTMLButtonElement>;
|
|
6
|
+
index: number;
|
|
7
|
+
count: number;
|
|
8
|
+
readOnly: boolean;
|
|
9
|
+
duplicateDisabled: boolean;
|
|
10
|
+
addDisabled: boolean;
|
|
11
|
+
labels: Readonly<Record<Action, string>>;
|
|
12
|
+
titles: Readonly<Record<Action, string>>;
|
|
13
|
+
className: string;
|
|
14
|
+
onDuplicate: () => void;
|
|
15
|
+
onMove: (offset: -1 | 1) => void;
|
|
16
|
+
onAdd: () => void;
|
|
17
|
+
onDelete: () => void;
|
|
18
|
+
}>): import("react").JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { EditorActionIcon } from './EditorActionIcon.js';
|
|
3
|
+
const ACTIONS = ['duplicate', 'up', 'down', 'add', 'delete'];
|
|
4
|
+
/** One owner for page/slide row actions; document policy stays with the host. */
|
|
5
|
+
export function CollectionRowActions({ index, count, readOnly, duplicateDisabled, addDisabled, labels, titles, className, addButtonRef, onDuplicate, onMove, onAdd, onDelete, }) {
|
|
6
|
+
const disabled = { duplicate: duplicateDisabled, up: index === 0, down: index === count - 1, add: addDisabled, delete: count === 1 };
|
|
7
|
+
const actions = { duplicate: onDuplicate, up: () => onMove(-1), down: () => onMove(1), add: onAdd, delete: onDelete };
|
|
8
|
+
return _jsx("div", { className: className, children: ACTIONS.map(action => _jsx("button", { ref: action === 'add' ? addButtonRef : undefined, type: "button", className: "editor-icon-action", "aria-label": labels[action], title: titles[action], disabled: readOnly || disabled[action], onClick: () => actions[action](), children: _jsx(EditorActionIcon, { action: action }) }, action)) });
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type EditorColorMode } from './editorThemes.js';
|
|
2
|
+
/** Native, keyboard-accessible mode control shared by site and canvas toolbars. */
|
|
3
|
+
export declare function ColorModeSelect({ label, value, onChange, disabled }: Readonly<{
|
|
4
|
+
label: string;
|
|
5
|
+
value: EditorColorMode;
|
|
6
|
+
onChange: (mode: EditorColorMode) => void;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}>): import("react").JSX.Element;
|
|
9
|
+
export declare function useSiteColorMode(storageKey: string): readonly [EditorColorMode, import("react").Dispatch<import("react").SetStateAction<EditorColorMode>>];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { isEditorColorMode } from './editorThemes.js';
|
|
4
|
+
/** Native, keyboard-accessible mode control shared by site and canvas toolbars. */
|
|
5
|
+
export function ColorModeSelect({ label, value, onChange, disabled = false }) {
|
|
6
|
+
return _jsxs("select", { "aria-label": label, title: label, className: "form-select form-select-sm w-auto", value: value, disabled: disabled, onChange: event => {
|
|
7
|
+
if (isEditorColorMode(event.currentTarget.value))
|
|
8
|
+
onChange(event.currentTarget.value);
|
|
9
|
+
}, children: [_jsx("option", { value: "light", children: "Light" }), _jsx("option", { value: "dark", children: "Dark" })] });
|
|
10
|
+
}
|
|
11
|
+
export function useSiteColorMode(storageKey) {
|
|
12
|
+
const [mode, setMode] = useState(() => {
|
|
13
|
+
try {
|
|
14
|
+
const saved = localStorage.getItem(storageKey);
|
|
15
|
+
return saved && isEditorColorMode(saved) ? saved : 'light';
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return 'light';
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
try {
|
|
23
|
+
localStorage.setItem(storageKey, mode);
|
|
24
|
+
}
|
|
25
|
+
catch { /* Browser storage is optional for editing. */ }
|
|
26
|
+
}, [storageKey, mode]);
|
|
27
|
+
return [mode, setMode];
|
|
28
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type HTMLAttributes } from 'react';
|
|
2
|
+
/** One empty-slot surface for native content and Puck-managed column children. */
|
|
3
|
+
export declare const ColumnContent: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & {
|
|
4
|
+
empty: boolean;
|
|
5
|
+
onAdd?: () => void;
|
|
6
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
/** One empty-slot surface for native content and Puck-managed column children. */
|
|
4
|
+
export const ColumnContent = forwardRef(function ColumnContent({ empty, onAdd, children, className = '', ...props }, ref) {
|
|
5
|
+
return _jsxs("div", { ...props, ref: ref, className: `content-column-content ${className}`, "data-empty": empty, children: [children, empty && _jsx("button", { type: "button", className: "content-empty-component content-column-placeholder", "data-puck-overlay-portal": "true", onPointerDown: event => event.stopPropagation(), onClick: event => { event.stopPropagation(); onAdd?.(); }, children: "Add content to Column" })] });
|
|
6
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function ComponentPicker<Type extends string>({ groups, label, canInsert, full, onInsert }: Readonly<{
|
|
2
|
+
groups: readonly Readonly<{
|
|
3
|
+
label: string;
|
|
4
|
+
types: readonly Type[];
|
|
5
|
+
}>[];
|
|
6
|
+
label: (type: Type) => string;
|
|
7
|
+
canInsert: (type: Type) => boolean;
|
|
8
|
+
full: boolean | ((type: Type) => boolean);
|
|
9
|
+
onInsert: (type: Type) => void;
|
|
10
|
+
}>): import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { useId, useState } from 'react';
|
|
5
|
+
import { Button } from 'react-bootstrap';
|
|
6
|
+
import { EditorTabs } from './EditorTabs.js';
|
|
7
|
+
import { ComponentPickerIcon } from './ComponentPickerIcon.js';
|
|
8
|
+
import { componentPickerFamilies } from './componentPickerFamilies.js';
|
|
9
|
+
export function ComponentPicker({ groups, label, canInsert, full, onInsert }) {
|
|
10
|
+
const contrast = useRef(null);
|
|
11
|
+
useEditorControlContrast(contrast);
|
|
12
|
+
const id = useId();
|
|
13
|
+
const available = groups.filter(group => group.types.length > 0);
|
|
14
|
+
const [requested, setRequested] = useState(available[0]?.label ?? '');
|
|
15
|
+
const active = available.some(group => group.label === requested) ? requested : available[0]?.label ?? '';
|
|
16
|
+
const panelId = (name) => `${id}-panel-${encodeURIComponent(name)}`;
|
|
17
|
+
return _jsxs("div", { ref: contrast, className: "component-picker", children: [_jsx(EditorTabs, { id: id, label: "Component categories", items: available.map(group => group.label), value: active, onChange: setRequested, panelId: panelId }), available.map((group, index) => _jsx("section", { role: "tabpanel", id: panelId(group.label), "aria-labelledby": `${id}-${index}`, hidden: active !== group.label, className: "component-picker-panel", tabIndex: 0, children: componentPickerFamilies(group.types, label).map((family, familyIndex) => _jsxs("section", { className: `component-picker-family${family.types.length > 2 ? ' component-picker-family-wide' : ''}`, "aria-labelledby": `${panelId(group.label)}-family-${familyIndex}`, children: [_jsx("h3", { id: `${panelId(group.label)}-family-${familyIndex}`, className: "component-picker-heading", children: family.label }), _jsx("div", { className: "component-picker-grid", children: family.types.map(type => {
|
|
18
|
+
const allowed = canInsert(type);
|
|
19
|
+
const atLimit = typeof full === 'function' ? full(type) : full;
|
|
20
|
+
return _jsxs(Button, { type: "button", variant: "outline-secondary", className: "component-picker-item", disabled: !allowed || atLimit, title: atLimit ? 'Component limit reached' : allowed ? `Add ${label(type)}` : 'Select an owning component in the outline first', onClick: () => onInsert(type), children: [_jsx(ComponentPickerIcon, { type: type }), _jsx("span", { children: label(type) })] }, type);
|
|
21
|
+
}) })] }, family.id)) }, group.label))] });
|
|
22
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
const shapes = {
|
|
3
|
+
layout: ['M3 3h18v18H3zM3 9h18M9 9v12'],
|
|
4
|
+
row: ['M3 4h18v6H3zM3 14h18v6H3z'],
|
|
5
|
+
column: ['M3 4h7v16H3zM14 4h7v16h-7z'],
|
|
6
|
+
text: ['M4 5h16M4 10h16M4 15h16M4 20h10'],
|
|
7
|
+
heading: ['M5 4v16M19 4v16M5 12h14'],
|
|
8
|
+
table: ['M3 4h18v16H3zM3 9h18M3 14h18M9 4v16M15 4v16'],
|
|
9
|
+
input: ['M3 6h18v12H3zM7 9v6M11 12h6'],
|
|
10
|
+
select: ['M3 6h18v12H3zM15 11l2 2 2-2M6 12h5'],
|
|
11
|
+
check: ['M4 4h16v16H4zM7 12l3 3 7-7'],
|
|
12
|
+
range: ['M3 12h6M15 12h6M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0'],
|
|
13
|
+
tabs: ['M3 8V4h6v4M9 8V4h6v4M15 8V4h6v16H3V8zM7 13h10M7 16h6'],
|
|
14
|
+
menu: ['M4 5h16M4 12h16M4 19h16'],
|
|
15
|
+
button: ['M3 6h18v12H3zM8 12h8'],
|
|
16
|
+
accordion: ['M3 3h18v7H3zM3 14h18v7H3zM15 6l2 2 2-2M15 17l2 2 2-2'],
|
|
17
|
+
list: ['M9 5h12M9 12h12M9 19h12M3 5h1M3 12h1M3 19h1'],
|
|
18
|
+
image: ['M3 3h18v18H3zM3 17l5-6 4 4 3-3 6 7M15 7h.01'],
|
|
19
|
+
video: ['M3 4h18v16H3zM10 8l6 4-6 4z'],
|
|
20
|
+
audio: ['M3 9h4l5-5v16l-5-5H3zM16 8q4 4 0 8M19 5q7 7 0 14'],
|
|
21
|
+
phone: ['M7 2h10v20H7zM10 5h4M11 19h2'],
|
|
22
|
+
card: ['M3 3h18v18H3zM3 9h18M7 13h10M7 17h6'],
|
|
23
|
+
message: ['M3 4h18v13H9l-6 4zM7 8h10M7 12h7'],
|
|
24
|
+
close: ['M5 5l14 14M19 5L5 19'],
|
|
25
|
+
placeholder: ['M3 4h18v5H3zM3 13h12v5H3z'],
|
|
26
|
+
spinner: ['M12 3a9 9 0 1 1-9 9'],
|
|
27
|
+
progress: ['M3 8h18v8H3zM3 8h10v8'],
|
|
28
|
+
};
|
|
29
|
+
const families = [
|
|
30
|
+
{ icon: 'close', types: ['CloseButton'] }, { icon: 'placeholder', types: ['Placeholder', 'PlaceholderButton'] },
|
|
31
|
+
{ icon: 'spinner', types: ['Spinner'] },
|
|
32
|
+
{ icon: 'row', types: ['Row', 'Stack'] }, { icon: 'column', types: ['Column'] },
|
|
33
|
+
{ icon: 'heading', types: ['Heading', 'CardTitle', 'CardSubtitle', 'DescriptionTerm'] },
|
|
34
|
+
{ icon: 'text', types: ['Text', 'Paragraph', 'Cite', 'Blockquote', 'Figcaption', 'CardText', 'FormLabel', 'DescriptionDetails', 'DropdownHeader'] },
|
|
35
|
+
{ icon: 'table', types: ['Table', 'TableCaption', 'TableHead', 'TableBody', 'TableFoot', 'TableRow', 'TableHeader', 'TableCell'] },
|
|
36
|
+
{ icon: 'input', types: ['FormControl', 'PracticeInput', 'InputGroup', 'InputGroupText'] },
|
|
37
|
+
{ icon: 'select', types: ['FormSelect', 'PracticeSelect'] }, { icon: 'check', types: ['PracticeCheck'] },
|
|
38
|
+
{ icon: 'range', types: ['FormRange', 'PracticeRange'] },
|
|
39
|
+
{ icon: 'tabs', types: ['Tabs', 'Tab', 'TabContainer', 'TabContent', 'TabPane', 'Navbar', 'NavbarBrand', 'NavbarCollapse', 'Nav', 'NavLink', 'Pagination', 'PaginationItem', 'Breadcrumb', 'BreadcrumbItem'] },
|
|
40
|
+
{ icon: 'menu', types: ['NavbarToggle', 'Dropdown', 'DropdownItem', 'DropdownDivider'] },
|
|
41
|
+
{ icon: 'button', types: ['Button', 'ButtonGroup'] }, { icon: 'accordion', types: ['Accordion', 'AccordionItem', 'Reveal'] },
|
|
42
|
+
{ icon: 'list', types: ['ContentList', 'ContentListItem', 'DescriptionList', 'ListGroup', 'ListGroupItem'] },
|
|
43
|
+
{ icon: 'image', types: ['Image', 'Figure', 'Carousel', 'CarouselItem'] }, { icon: 'video', types: ['Video', 'Embed'] },
|
|
44
|
+
{ icon: 'audio', types: ['Audio'] }, { icon: 'phone', types: ['Simulator'] },
|
|
45
|
+
{ icon: 'card', types: ['Card', 'CardBody', 'CardHeader', 'CardFooter', 'CardGroup'] },
|
|
46
|
+
{ icon: 'message', types: ['Callout', 'Alert', 'Badge', 'Toast', 'Tooltip', 'Popover', 'Modal', 'Offcanvas'] },
|
|
47
|
+
{ icon: 'progress', types: ['Progress', 'ProgressGroup'] },
|
|
48
|
+
];
|
|
49
|
+
export function ComponentPickerIcon({ type }) {
|
|
50
|
+
const icon = families.find(family => family.types.includes(type))?.icon ?? 'layout';
|
|
51
|
+
return _jsx("svg", { "aria-hidden": "true", width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: shapes[icon].map(path => _jsx("path", { d: path }, path)) });
|
|
52
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Config, type Data, type UserGenerics } from '@puckeditor/core';
|
|
2
|
+
type ContentData<C extends Config> = UserGenerics<C>['UserData'];
|
|
3
|
+
/** Controlled canvas. Hosts own the palette, inspector, document validation and history. */
|
|
4
|
+
export type ContentEditorProps<C extends Config> = Readonly<{
|
|
5
|
+
config: C;
|
|
6
|
+
data: ContentData<C> & Data;
|
|
7
|
+
/** Empty string selects the root; null retains a selection outside the content canvas. */
|
|
8
|
+
selectedId: string | null;
|
|
9
|
+
onSelect: (id: string) => void;
|
|
10
|
+
onChange: (data: ContentData<C>) => void;
|
|
11
|
+
/** Increment after rejecting an engine edit to restore the authoritative document. */
|
|
12
|
+
rejectionRevision?: number;
|
|
13
|
+
}>;
|
|
14
|
+
/** Uses the existing inline Puck canvas without imposing another editor shell. */
|
|
15
|
+
export declare function ContentEditor<C extends Config>({ config, data, selectedId, onSelect, onChange, rejectionRevision, }: ContentEditorProps<C>): import("react").JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Puck, createUsePuck } from '@puckeditor/core';
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
const useContentPuck = createUsePuck();
|
|
5
|
+
function CanvasStateBridge({ data, selectedId, onSelect, rejectionRevision = 0, }) {
|
|
6
|
+
const api = useContentPuck((state) => state);
|
|
7
|
+
const { dispatch, selectedItem } = api;
|
|
8
|
+
const latest = useRef({ api, onSelect, selectedId });
|
|
9
|
+
latest.current = { api, onSelect, selectedId };
|
|
10
|
+
const engineId = selectedItem?.props.id ?? '';
|
|
11
|
+
const previousSelection = useRef(engineId);
|
|
12
|
+
const pendingSelection = useRef(undefined);
|
|
13
|
+
const serialized = JSON.stringify(data);
|
|
14
|
+
const previous = useRef(serialized);
|
|
15
|
+
const previousRejection = useRef(rejectionRevision);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (previous.current === serialized && previousRejection.current === rejectionRevision)
|
|
18
|
+
return;
|
|
19
|
+
previousRejection.current = rejectionRevision;
|
|
20
|
+
previous.current = serialized;
|
|
21
|
+
pendingSelection.current = selectedId ?? '';
|
|
22
|
+
dispatch({ type: 'setData', data, recordHistory: false });
|
|
23
|
+
}, [serialized, data, dispatch, selectedId, rejectionRevision]);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const current = latest.current.api;
|
|
26
|
+
const selector = selectedId ? current.getSelectorForId(selectedId) : null;
|
|
27
|
+
// A newly inserted item may not yet be in the engine's projection.
|
|
28
|
+
if (selectedId && !selector)
|
|
29
|
+
return;
|
|
30
|
+
if (JSON.stringify(current.appState.ui.itemSelector) !== JSON.stringify(selector ?? null)) {
|
|
31
|
+
pendingSelection.current = selectedId ?? '';
|
|
32
|
+
current.dispatch({
|
|
33
|
+
type: 'setUi',
|
|
34
|
+
ui: { itemSelector: selector ?? null },
|
|
35
|
+
recordHistory: false,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}, [selectedId, api.appState.data]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (pendingSelection.current !== undefined) {
|
|
41
|
+
if (engineId !== pendingSelection.current)
|
|
42
|
+
return;
|
|
43
|
+
pendingSelection.current = undefined;
|
|
44
|
+
previousSelection.current = engineId;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (previousSelection.current === engineId)
|
|
48
|
+
return;
|
|
49
|
+
const current = latest.current;
|
|
50
|
+
// Puck's native container listeners also see clicks from the rich-text toolbar.
|
|
51
|
+
// Keep the authored selection while its editor or portalled menu owns focus.
|
|
52
|
+
if (current.selectedId && document.activeElement?.closest('.content-inline-editor, .mdxeditor-popup-container')) {
|
|
53
|
+
const selector = current.api.getSelectorForId(current.selectedId);
|
|
54
|
+
if (selector) {
|
|
55
|
+
pendingSelection.current = current.selectedId;
|
|
56
|
+
current.api.dispatch({ type: 'setUi', ui: { itemSelector: selector }, recordHistory: false });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
previousSelection.current = engineId;
|
|
61
|
+
if (!engineId && latest.current.selectedId === null)
|
|
62
|
+
return;
|
|
63
|
+
latest.current.onSelect(engineId);
|
|
64
|
+
}, [engineId]);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
/** Uses the existing inline Puck canvas without imposing another editor shell. */
|
|
68
|
+
export function ContentEditor({ config, data, selectedId, onSelect, onChange, rejectionRevision, }) {
|
|
69
|
+
return (_jsxs(Puck, { config: config, data: data, iframe: { enabled: false }, permissions: { delete: false, duplicate: false, insert: false }, overrides: { actionBar: EmptyActionBar }, onChange: onChange, children: [_jsx(CanvasStateBridge, { data: data, selectedId: selectedId, onSelect: onSelect, rejectionRevision: rejectionRevision }), _jsx(Puck.Preview, {})] }));
|
|
70
|
+
}
|
|
71
|
+
function EmptyActionBar() {
|
|
72
|
+
return _jsx(_Fragment, {});
|
|
73
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
|
+
import type { SlideImageProps } from './contracts/types.gen.js';
|
|
3
|
+
export declare const IMAGE_DEFAULT_PROPS: {
|
|
4
|
+
readonly src: "";
|
|
5
|
+
readonly alt: "";
|
|
6
|
+
readonly caption: "";
|
|
7
|
+
readonly size: "full";
|
|
8
|
+
readonly alignment: "center";
|
|
9
|
+
};
|
|
10
|
+
/** Sources remain editable text in draft JSON; only supported URLs reach an img. */
|
|
11
|
+
export declare function imageSource(value: string): string | null;
|
|
12
|
+
/** Canvas and learner playback deliberately share this exact presentation. */
|
|
13
|
+
export declare function ContentImage({ src, alt, caption, size, alignment, objectFit, aspectRatio, thumbnail, rounded, roundedCircle, surfaceProps, elementRef, objectPosition, ...appearance }: Readonly<Omit<SlideImageProps, 'id' | 'parentId'> & {
|
|
14
|
+
surfaceProps?: HTMLAttributes<HTMLElement>;
|
|
15
|
+
elementRef?: (node: HTMLElement | null) => void;
|
|
16
|
+
}>): import("react").JSX.Element;
|