@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,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useState } from 'react';
|
|
3
|
+
import { Form } from 'react-bootstrap';
|
|
4
|
+
import { formatSpacing, isSpacingValue, parseSpacing } from './spacingShorthand.js';
|
|
5
|
+
function SpacingField({ kind, value, error: sourceError, onChange, }) {
|
|
6
|
+
const id = useId();
|
|
7
|
+
const [draft, setDraft] = useState(null);
|
|
8
|
+
const current = draft?.source === value ? draft : null;
|
|
9
|
+
const error = current?.error ?? sourceError;
|
|
10
|
+
const commit = () => {
|
|
11
|
+
if (!current || current.text === value) {
|
|
12
|
+
setDraft(null);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const parsed = parseSpacing(current.text, kind);
|
|
16
|
+
if (!parsed.success)
|
|
17
|
+
setDraft({
|
|
18
|
+
source: value,
|
|
19
|
+
text: current.text,
|
|
20
|
+
error: parsed.error,
|
|
21
|
+
});
|
|
22
|
+
else {
|
|
23
|
+
onChange(parsed.patch);
|
|
24
|
+
setDraft(null);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return (_jsxs(Form.Group, { controlId: id, className: "mb-2", children: [_jsx(Form.Label, { children: kind === 'margin' ? 'Margin' : 'Padding' }), _jsx(Form.Control, { type: "text", value: current?.text ?? value, placeholder: "Default", "aria-describedby": error ? `${id}-error` : undefined, "aria-invalid": Boolean(error), isInvalid: Boolean(error), onChange: (event) => setDraft({
|
|
28
|
+
source: value,
|
|
29
|
+
text: event.currentTarget.value,
|
|
30
|
+
error: '',
|
|
31
|
+
}), onBlur: commit, onKeyDown: (event) => {
|
|
32
|
+
if (event.key === 'Enter') {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
event.stopPropagation();
|
|
35
|
+
commit();
|
|
36
|
+
}
|
|
37
|
+
if (event.key === 'Escape') {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
event.stopPropagation();
|
|
40
|
+
setDraft(null);
|
|
41
|
+
}
|
|
42
|
+
} }), _jsx(Form.Control.Feedback, { type: "invalid", id: `${id}-error`, children: error })] }));
|
|
43
|
+
}
|
|
44
|
+
export function SpacingEditor({ block, onChange, }) {
|
|
45
|
+
const properties = new Map(Object.entries(block.props));
|
|
46
|
+
return (_jsx(_Fragment, { children: ['margin', 'padding'].map((kind) => {
|
|
47
|
+
const values = ['Top', 'End', 'Bottom', 'Start'].map((side) => properties.get(`${kind}${side}`) ?? null);
|
|
48
|
+
const supported = values.every(isSpacingValue);
|
|
49
|
+
return (_jsx(SpacingField, { kind: kind, value: supported ? formatSpacing(values) : '', error: supported
|
|
50
|
+
? ''
|
|
51
|
+
: `Saved ${kind} contains an unsupported value. Enter spacing to replace it.`, onChange: onChange }, `${block.props.id}-${kind}`));
|
|
52
|
+
}) }));
|
|
53
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ContentBlock } from "./contentModel.js";
|
|
2
|
+
type Block = ContentBlock;
|
|
3
|
+
export declare function blockText(text: string): string;
|
|
4
|
+
export declare function blockLabel(block: Block): string;
|
|
5
|
+
export declare function blockFamily(blocks: readonly Block[], id: string): Block[];
|
|
6
|
+
export declare function duplicateBlocks(blocks: readonly Block[], identities?: ReadonlyMap<string, string>, clearExternalTargets?: boolean): Block[];
|
|
7
|
+
/** Reorder complete sibling families without changing identities or hierarchy. */
|
|
8
|
+
export declare function reorderBlocks(blocks: readonly Block[], sourceId: string, targetId: string, after?: boolean): Block[];
|
|
9
|
+
/** Remove a subtree and neutralize references to its targets and tab keys. */
|
|
10
|
+
export declare function removeBlockFamily(blocks: readonly Block[], id: string): Block[];
|
|
11
|
+
/** Structural edits repair tab selection without breaking surviving visibility targets. */
|
|
12
|
+
export declare function repairContentReferences(remaining: readonly Block[], removed?: ReadonlySet<string>): Block[];
|
|
13
|
+
/** Duplicate a subtree after its last member even when source JSON interleaves families. */
|
|
14
|
+
export declare function duplicateBlockFamily(blocks: readonly ContentBlock[], id: string): Readonly<{
|
|
15
|
+
content: ContentBlock[];
|
|
16
|
+
selectedId: string;
|
|
17
|
+
}> | undefined;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { authoringUuid } from "./authoringUuid.js";
|
|
2
|
+
import { layoutParent } from "./layout.js";
|
|
3
|
+
import { stripHtmlTags, stripMarkdownLinks } from './authoringText.js';
|
|
4
|
+
export function blockText(text) {
|
|
5
|
+
return stripMarkdownLinks(stripHtmlTags(text))
|
|
6
|
+
.replace(/[#*_`\n]/g, " ")
|
|
7
|
+
.trim();
|
|
8
|
+
}
|
|
9
|
+
export function blockLabel(block) {
|
|
10
|
+
let text = "";
|
|
11
|
+
if ("text" in block.props)
|
|
12
|
+
text = blockText(block.props.text ?? "");
|
|
13
|
+
else if (block.type === "Image")
|
|
14
|
+
text = block.props.alt || block.props.caption;
|
|
15
|
+
return text ? `${block.type} · ${text.slice(0, 48)}` : block.type;
|
|
16
|
+
}
|
|
17
|
+
export function blockFamily(blocks, id) {
|
|
18
|
+
const ids = new Set([id]);
|
|
19
|
+
const visit = (parent) => {
|
|
20
|
+
for (const block of blocks) {
|
|
21
|
+
if (layoutParent(block) !== parent || ids.has(block.props.id))
|
|
22
|
+
continue;
|
|
23
|
+
ids.add(block.props.id);
|
|
24
|
+
visit(block.props.id);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
visit(id);
|
|
28
|
+
return blocks.filter((block) => ids.has(block.props.id));
|
|
29
|
+
}
|
|
30
|
+
export function duplicateBlocks(blocks, identities, clearExternalTargets = false) {
|
|
31
|
+
const ids = new Map(blocks.map((block) => [
|
|
32
|
+
block.props.id,
|
|
33
|
+
identities?.get(block.props.id) ?? authoringUuid(),
|
|
34
|
+
]));
|
|
35
|
+
// Every lookup here belongs to the same dense source list used to construct ids.
|
|
36
|
+
// Duplicate source identities deliberately share the last generated identity.
|
|
37
|
+
const sourceIdentity = (id) => ids.get(id);
|
|
38
|
+
function clone(block) {
|
|
39
|
+
const parent = layoutParent(block);
|
|
40
|
+
const props = block.props;
|
|
41
|
+
const compoundOwner = (candidate) => {
|
|
42
|
+
let owner = layoutParent(candidate);
|
|
43
|
+
let nav;
|
|
44
|
+
const visited = new Set();
|
|
45
|
+
while (owner && !visited.has(owner)) {
|
|
46
|
+
visited.add(owner);
|
|
47
|
+
const parentBlock = blocks.find(item => item.props.id === owner);
|
|
48
|
+
if (!parentBlock)
|
|
49
|
+
break;
|
|
50
|
+
if (['Tabs', 'Carousel', 'TabContainer'].includes(parentBlock.type))
|
|
51
|
+
return owner;
|
|
52
|
+
if (parentBlock.type === 'Nav')
|
|
53
|
+
nav ??= owner;
|
|
54
|
+
owner = layoutParent(parentBlock);
|
|
55
|
+
}
|
|
56
|
+
return nav ?? candidate.props.id;
|
|
57
|
+
};
|
|
58
|
+
const keyFor = (owner, key) => {
|
|
59
|
+
const child = blocks.find((candidate) => (layoutParent(candidate) === owner || compoundOwner(candidate) === owner) &&
|
|
60
|
+
(("eventKey" in candidate.props && candidate.props.eventKey === key) || candidate.props.id === key));
|
|
61
|
+
return child ? sourceIdentity(child.props.id) : key;
|
|
62
|
+
};
|
|
63
|
+
const target = "targetId" in props && typeof props.targetId === "string"
|
|
64
|
+
? props.targetId
|
|
65
|
+
: undefined;
|
|
66
|
+
const clearTarget = Boolean(clearExternalTargets && target && !ids.has(target));
|
|
67
|
+
return {
|
|
68
|
+
...structuredClone(block),
|
|
69
|
+
props: {
|
|
70
|
+
...structuredClone(block.props),
|
|
71
|
+
id: sourceIdentity(block.props.id),
|
|
72
|
+
...(parent ? { parentId: ids.get(parent) ?? parent } : {}),
|
|
73
|
+
...(block.type === 'FormLabel' && block.props.htmlFor ? { htmlFor: ids.get(block.props.htmlFor) ?? (clearExternalTargets ? null : block.props.htmlFor) } : {}),
|
|
74
|
+
...("eventKey" in props && typeof props.eventKey === 'string' && props.eventKey
|
|
75
|
+
? { eventKey: keyFor(compoundOwner(block), props.eventKey) }
|
|
76
|
+
: {}),
|
|
77
|
+
...("defaultActiveKey" in props && props.defaultActiveKey
|
|
78
|
+
? {
|
|
79
|
+
defaultActiveKey: keyFor(block.type === 'Nav' ? compoundOwner(block) : props.id, props.defaultActiveKey),
|
|
80
|
+
}
|
|
81
|
+
: {}),
|
|
82
|
+
...(target
|
|
83
|
+
? {
|
|
84
|
+
targetId: clearTarget
|
|
85
|
+
? null
|
|
86
|
+
: (ids.get(target) ?? target),
|
|
87
|
+
}
|
|
88
|
+
: {}),
|
|
89
|
+
...(target && "targetKey" in props && props.targetKey
|
|
90
|
+
? {
|
|
91
|
+
targetKey: clearTarget
|
|
92
|
+
? null
|
|
93
|
+
: keyFor(target, props.targetKey),
|
|
94
|
+
}
|
|
95
|
+
: {}),
|
|
96
|
+
...(clearTarget ? { action: "none" } : {}),
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return blocks.map(clone);
|
|
101
|
+
}
|
|
102
|
+
/** Reorder complete sibling families without changing identities or hierarchy. */
|
|
103
|
+
export function reorderBlocks(blocks, sourceId, targetId, after = false) {
|
|
104
|
+
const source = blocks.find((block) => block.props.id === sourceId);
|
|
105
|
+
const target = blocks.find((block) => block.props.id === targetId);
|
|
106
|
+
if (!source ||
|
|
107
|
+
!target ||
|
|
108
|
+
source === target ||
|
|
109
|
+
layoutParent(source) !== layoutParent(target))
|
|
110
|
+
return [...blocks];
|
|
111
|
+
const moving = blockFamily(blocks, sourceId);
|
|
112
|
+
const movingIds = new Set(moving.map((block) => block.props.id));
|
|
113
|
+
const rest = blocks.filter((block) => !movingIds.has(block.props.id));
|
|
114
|
+
const targetIds = new Set(blockFamily(rest, targetId).map((block) => block.props.id));
|
|
115
|
+
const position = after
|
|
116
|
+
? rest.reduce((last, block, index) => targetIds.has(block.props.id) ? index + 1 : last, 0)
|
|
117
|
+
: rest.findIndex((block) => block.props.id === targetId);
|
|
118
|
+
rest.splice(position, 0, ...moving);
|
|
119
|
+
return rest;
|
|
120
|
+
}
|
|
121
|
+
/** Remove a subtree and neutralize references to its targets and tab keys. */
|
|
122
|
+
export function removeBlockFamily(blocks, id) {
|
|
123
|
+
const removed = new Set(blockFamily(blocks, id).map(block => block.props.id));
|
|
124
|
+
const remaining = blocks.filter(block => !removed.has(block.props.id));
|
|
125
|
+
return repairContentReferences(remaining, removed);
|
|
126
|
+
}
|
|
127
|
+
/** Structural edits repair tab selection without breaking surviving visibility targets. */
|
|
128
|
+
export function repairContentReferences(remaining, removed = new Set()) {
|
|
129
|
+
return remaining.map(block => {
|
|
130
|
+
if (block.type === 'FormLabel' && block.props.htmlFor && removed.has(block.props.htmlFor))
|
|
131
|
+
return { ...block, props: { ...block.props, htmlFor: null } };
|
|
132
|
+
if (block.type === 'Button' || block.type === 'DropdownItem') {
|
|
133
|
+
const target = block.props.targetId;
|
|
134
|
+
const missingTarget = target && removed.has(target);
|
|
135
|
+
const missingTab = block.props.action === 'select-tab' && !remaining.some(child => child.type === 'Tab' && layoutParent(child) === target &&
|
|
136
|
+
child.props.eventKey === block.props.targetKey && !child.props.disabled);
|
|
137
|
+
if (missingTarget || missingTab) {
|
|
138
|
+
const { targetId: _target, targetKey: _key, ...props } = block.props;
|
|
139
|
+
return { ...block, props: { ...props, action: 'none' } };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (block.type === 'TabContainer' && block.props.defaultActiveKey) {
|
|
143
|
+
const panes = blockFamily(remaining, block.props.id).filter(item => item.type === 'TabPane');
|
|
144
|
+
if (!panes.some(item => item.props.eventKey === block.props.defaultActiveKey))
|
|
145
|
+
return { ...block, props: { ...block.props, defaultActiveKey: panes[0]?.props.eventKey ?? '' } };
|
|
146
|
+
}
|
|
147
|
+
if (block.type === 'Nav' && block.props.defaultActiveKey) {
|
|
148
|
+
const links = remaining.filter((item) => item.type === 'NavLink' && layoutParent(item) === block.props.id);
|
|
149
|
+
if (!links.some(item => (item.props.eventKey ?? item.props.id) === block.props.defaultActiveKey))
|
|
150
|
+
return { ...block, props: { ...block.props, defaultActiveKey: links[0]?.props.eventKey ?? links[0]?.props.id ?? '' } };
|
|
151
|
+
}
|
|
152
|
+
if ((block.type === 'Accordion' || block.type === 'Tabs' || block.type === 'Carousel') &&
|
|
153
|
+
block.props.defaultActiveKey && !remaining.some(child => layoutParent(child) === block.props.id && 'eventKey' in child.props && child.props.eventKey === block.props.defaultActiveKey)) {
|
|
154
|
+
return { ...block, props: { ...block.props, defaultActiveKey: '' } };
|
|
155
|
+
}
|
|
156
|
+
return block;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/** Duplicate a subtree after its last member even when source JSON interleaves families. */
|
|
160
|
+
export function duplicateBlockFamily(blocks, id) {
|
|
161
|
+
const family = blockFamily(blocks, id);
|
|
162
|
+
const rootIndex = family.findIndex(block => block.props.id === id);
|
|
163
|
+
if (rootIndex < 0)
|
|
164
|
+
return undefined;
|
|
165
|
+
const copies = duplicateBlocks(family);
|
|
166
|
+
const root = copies[rootIndex];
|
|
167
|
+
if (!root)
|
|
168
|
+
return undefined;
|
|
169
|
+
const ids = new Set(family.map(block => block.props.id));
|
|
170
|
+
const end = blocks.reduce((last, block, index) => ids.has(block.props.id) ? index : last, -1);
|
|
171
|
+
return { content: [...blocks.slice(0, end + 1), ...copies, ...blocks.slice(end + 1)], selectedId: root.props.id };
|
|
172
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Remove complete tags without repeatedly rescanning malformed opening brackets. */
|
|
2
|
+
export declare function stripHtmlTags(value: string): string;
|
|
3
|
+
/** Retain link/image labels with the existing simple Markdown delimiter semantics. */
|
|
4
|
+
export declare function stripMarkdownLinks(value: string): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Remove complete tags without repeatedly rescanning malformed opening brackets. */
|
|
2
|
+
export function stripHtmlTags(value) {
|
|
3
|
+
const parts = [];
|
|
4
|
+
let copiedThrough = 0;
|
|
5
|
+
let opening = value.indexOf('<');
|
|
6
|
+
while (opening !== -1) {
|
|
7
|
+
const closing = value.indexOf('>', opening + 1);
|
|
8
|
+
if (closing === -1)
|
|
9
|
+
break;
|
|
10
|
+
parts.push(value.slice(copiedThrough, opening));
|
|
11
|
+
copiedThrough = closing + 1;
|
|
12
|
+
opening = value.indexOf('<', copiedThrough);
|
|
13
|
+
}
|
|
14
|
+
parts.push(value.slice(copiedThrough));
|
|
15
|
+
return parts.join('');
|
|
16
|
+
}
|
|
17
|
+
/** Retain link/image labels with the existing simple Markdown delimiter semantics. */
|
|
18
|
+
export function stripMarkdownLinks(value) {
|
|
19
|
+
const parts = [];
|
|
20
|
+
let copiedThrough = 0;
|
|
21
|
+
let searchFrom = 0;
|
|
22
|
+
while (searchFrom < value.length) {
|
|
23
|
+
const opening = value.indexOf('[', searchFrom);
|
|
24
|
+
if (opening === -1)
|
|
25
|
+
break;
|
|
26
|
+
const closing = value.indexOf(']', opening + 1);
|
|
27
|
+
if (closing === -1)
|
|
28
|
+
break;
|
|
29
|
+
if (value[closing + 1] !== '(') {
|
|
30
|
+
searchFrom = closing + 1;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const end = value.indexOf(')', closing + 2);
|
|
34
|
+
if (end === -1)
|
|
35
|
+
break;
|
|
36
|
+
const start = opening > copiedThrough && value[opening - 1] === '!'
|
|
37
|
+
? opening - 1
|
|
38
|
+
: opening;
|
|
39
|
+
parts.push(value.slice(copiedThrough, start), value.slice(opening + 1, closing));
|
|
40
|
+
copiedThrough = end + 1;
|
|
41
|
+
searchFrom = copiedThrough;
|
|
42
|
+
}
|
|
43
|
+
parts.push(value.slice(copiedThrough));
|
|
44
|
+
return parts.join('');
|
|
45
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** UUID v4 for authoring identifiers, including local HTTP hosts. */
|
|
2
|
+
export function authoringUuid() {
|
|
3
|
+
if (typeof crypto.randomUUID === 'function')
|
|
4
|
+
return crypto.randomUUID();
|
|
5
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
6
|
+
const view = new DataView(bytes.buffer);
|
|
7
|
+
view.setUint8(6, (view.getUint8(6) & 0x0f) | 0x40);
|
|
8
|
+
view.setUint8(8, (view.getUint8(8) & 0x3f) | 0x80);
|
|
9
|
+
const hex = Array.from(bytes, (value) => value.toString(16).padStart(2, '0')).join('');
|
|
10
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ContentBlock } from './contentModel.js';
|
|
2
|
+
import { type BootstrapBlockType } from './bootstrapRegistry.js';
|
|
3
|
+
type ImageFactory = (id: string, parentId: string) => Extract<ContentBlock, {
|
|
4
|
+
type: 'Image';
|
|
5
|
+
}>;
|
|
6
|
+
export declare function createBootstrapFamily(type: BootstrapBlockType, parent: ContentBlock | undefined, image: ImageFactory): {
|
|
7
|
+
block: import("./contracts/types.gen.js").SlideCloseButton | import("./contracts/types.gen.js").SlidePlaceholder | import("./contracts/types.gen.js").SlidePlaceholderButton | import("./contracts/types.gen.js").SlideSpinner | import("./contracts/types.gen.js").SlideFormLabel | import("./contracts/types.gen.js").SlideTabContainer | import("./contracts/types.gen.js").SlideTabContent | import("./contracts/types.gen.js").SlideTabPane | import("./contracts/types.gen.js").SlideNavbar | import("./contracts/types.gen.js").SlideNavbarBrand | import("./contracts/types.gen.js").SlideNavbarToggle | import("./contracts/types.gen.js").SlideNavbarCollapse | import("./contracts/types.gen.js").SlideNav | import("./contracts/types.gen.js").SlideNavLink | import("./contracts/types.gen.js").SlidePagination | import("./contracts/types.gen.js").SlidePaginationItem | import("./contracts/types.gen.js").SlideInputGroup | import("./contracts/types.gen.js").SlideInputGroupText | import("./contracts/types.gen.js").SlideProgressGroup | import("./contracts/types.gen.js").SlideDropdownDivider | import("./contracts/types.gen.js").SlideDropdownHeader | import("./contracts/types.gen.js").SlideStack | import("./contracts/types.gen.js").SlideDivider | import("./contracts/types.gen.js").SlideAlert | import("./contracts/types.gen.js").SlideContentList | import("./contracts/types.gen.js").SlideContentListItem | import("./contracts/types.gen.js").SlideDescriptionList | import("./contracts/types.gen.js").SlideDescriptionTerm | import("./contracts/types.gen.js").SlideDescriptionDetails | import("./contracts/types.gen.js").SlideContainer | import("./contracts/types.gen.js").SlideText | import("./contracts/types.gen.js").SlideFigure | import("./contracts/types.gen.js").SlideBlockquote | import("./contracts/types.gen.js").SlideFigcaption | import("./contracts/types.gen.js").SlideCite | import("./contracts/types.gen.js").SlideTable | import("./contracts/types.gen.js").SlideTableHead | import("./contracts/types.gen.js").SlideTableBody | import("./contracts/types.gen.js").SlideTableFoot | import("./contracts/types.gen.js").SlideTableRow | import("./contracts/types.gen.js").SlideTableHeader | import("./contracts/types.gen.js").SlideTableCell | import("./contracts/types.gen.js").SlideTableCaption | import("./contracts/types.gen.js").SlideIndicator | import("./contracts/types.gen.js").SlideBadge | import("./contracts/types.gen.js").SlideListGroup | import("./contracts/types.gen.js").SlideListGroupItem | import("./contracts/types.gen.js").SlideCard | import("./contracts/types.gen.js").SlideCardHeader | import("./contracts/types.gen.js").SlideCardBody | import("./contracts/types.gen.js").SlideCardFooter | import("./contracts/types.gen.js").SlideCardTitle | import("./contracts/types.gen.js").SlideCardSubtitle | import("./contracts/types.gen.js").SlideCardText | import("./contracts/types.gen.js").SlideCardLink | import("./contracts/types.gen.js").SlideCardImage | import("./contracts/types.gen.js").SlideCardImageOverlay | import("./contracts/types.gen.js").SlideCardGroup | import("./contracts/types.gen.js").SlideFormControl | import("./contracts/types.gen.js").SlideFormSelect | import("./contracts/types.gen.js").SlideFormRange | import("./contracts/types.gen.js").SlideGroup | import("./contracts/types.gen.js").SlideRatio | import("./contracts/types.gen.js").SlideAccordion | import("./contracts/types.gen.js").SlideAccordionItem | import("./contracts/types.gen.js").SlideTabs | import("./contracts/types.gen.js").SlideTab | import("./contracts/types.gen.js").SlideButton | import("./contracts/types.gen.js").SlideButtonGroup | import("./contracts/types.gen.js").SlideReveal | import("./contracts/types.gen.js").SlideTooltip | import("./contracts/types.gen.js").SlidePopover | import("./contracts/types.gen.js").SlideCarousel | import("./contracts/types.gen.js").SlideCarouselItem | import("./contracts/types.gen.js").SlideProgress | import("./contracts/types.gen.js").SlideModal | import("./contracts/types.gen.js").SlideOffcanvas | import("./contracts/types.gen.js").SlideDropdown | import("./contracts/types.gen.js").SlideToast | import("./contracts/types.gen.js").SlidePracticeInput | import("./contracts/types.gen.js").SlidePracticeSelect | import("./contracts/types.gen.js").SlidePracticeCheck | import("./contracts/types.gen.js").SlidePracticeRange | import("./contracts/types.gen.js").SlideBreadcrumb | import("./contracts/types.gen.js").SlideBreadcrumbItem | import("./contracts/types.gen.js").SlideVideo | import("./contracts/types.gen.js").SlideAudio | import("./contracts/types.gen.js").SlideEmbed | import("./contracts/types.gen.js").SlideDropdownItem | import("./contracts/types.gen.js").SlideColumn | import("./contracts/types.gen.js").SlideImage | import("./contracts/types.gen.js").SlideRow;
|
|
8
|
+
additions: ContentBlock[];
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { createBootstrapBlock } from './bootstrapRegistry.js';
|
|
2
|
+
import { authoringUuid } from './authoringUuid.js';
|
|
3
|
+
const COMPOUND_ITEM_TYPES = {
|
|
4
|
+
Accordion: 'AccordionItem',
|
|
5
|
+
Tabs: 'Tab',
|
|
6
|
+
Carousel: 'CarouselItem',
|
|
7
|
+
};
|
|
8
|
+
const TEXT_CONTAINER_TYPES = new Set([
|
|
9
|
+
'Group',
|
|
10
|
+
'Reveal',
|
|
11
|
+
'Modal',
|
|
12
|
+
'Offcanvas',
|
|
13
|
+
'Tooltip',
|
|
14
|
+
'Popover',
|
|
15
|
+
'Toast',
|
|
16
|
+
'AccordionItem',
|
|
17
|
+
'Tab',
|
|
18
|
+
'CarouselItem',
|
|
19
|
+
'Stack',
|
|
20
|
+
'Alert',
|
|
21
|
+
'ContentListItem',
|
|
22
|
+
'DescriptionTerm',
|
|
23
|
+
'DescriptionDetails',
|
|
24
|
+
'Container',
|
|
25
|
+
'Blockquote',
|
|
26
|
+
'Figcaption',
|
|
27
|
+
'TableCaption',
|
|
28
|
+
'TableHeader',
|
|
29
|
+
'TableCell',
|
|
30
|
+
'ListGroupItem',
|
|
31
|
+
'CardHeader',
|
|
32
|
+
'CardBody',
|
|
33
|
+
'CardFooter',
|
|
34
|
+
'CardImageOverlay',
|
|
35
|
+
]);
|
|
36
|
+
function appendBootstrapChildren(block, child, additions, image) {
|
|
37
|
+
switch (block.type) {
|
|
38
|
+
case 'Navbar': {
|
|
39
|
+
child('NavbarBrand', block);
|
|
40
|
+
child('NavbarToggle', block);
|
|
41
|
+
const nav = child('Nav', child('NavbarCollapse', block));
|
|
42
|
+
nav.props.navbar = true;
|
|
43
|
+
child('NavLink', nav);
|
|
44
|
+
child('NavLink', nav);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
case 'Nav':
|
|
48
|
+
child('NavLink', block);
|
|
49
|
+
child('NavLink', block);
|
|
50
|
+
return;
|
|
51
|
+
case 'Pagination':
|
|
52
|
+
child('PaginationItem', block);
|
|
53
|
+
child('PaginationItem', block);
|
|
54
|
+
return;
|
|
55
|
+
case 'InputGroup':
|
|
56
|
+
child('InputGroupText', block);
|
|
57
|
+
child('FormControl', block);
|
|
58
|
+
return;
|
|
59
|
+
case 'ProgressGroup':
|
|
60
|
+
child('Progress', block);
|
|
61
|
+
child('Progress', block);
|
|
62
|
+
return;
|
|
63
|
+
case 'TabContainer': {
|
|
64
|
+
const nav = child('Nav', block);
|
|
65
|
+
nav.props.variant = 'tabs';
|
|
66
|
+
const content = child('TabContent', block);
|
|
67
|
+
for (const key of ['home', 'profile']) {
|
|
68
|
+
const link = child('NavLink', nav);
|
|
69
|
+
link.props.eventKey = key;
|
|
70
|
+
link.props.text = key;
|
|
71
|
+
const pane = child('TabPane', content);
|
|
72
|
+
pane.props.eventKey = key;
|
|
73
|
+
child('Text', pane);
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
case 'Accordion':
|
|
78
|
+
case 'Tabs':
|
|
79
|
+
case 'Carousel':
|
|
80
|
+
for (let position = 0; position < 2; position += 1)
|
|
81
|
+
child('Text', child(COMPOUND_ITEM_TYPES[block.type], block));
|
|
82
|
+
return;
|
|
83
|
+
case 'ButtonGroup':
|
|
84
|
+
child('Button', block);
|
|
85
|
+
child('Button', block);
|
|
86
|
+
return;
|
|
87
|
+
case 'Dropdown':
|
|
88
|
+
child('DropdownItem', block);
|
|
89
|
+
return;
|
|
90
|
+
case 'Breadcrumb':
|
|
91
|
+
child('BreadcrumbItem', block);
|
|
92
|
+
return;
|
|
93
|
+
case 'Ratio':
|
|
94
|
+
additions.push({
|
|
95
|
+
type: 'Image',
|
|
96
|
+
props: { ...image(authoringUuid(), block.props.id).props },
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
case 'Table': {
|
|
100
|
+
const headRow = child('TableRow', child('TableHead', block));
|
|
101
|
+
child('Text', child('TableHeader', headRow));
|
|
102
|
+
child('Text', child('TableHeader', headRow));
|
|
103
|
+
const row = child('TableRow', child('TableBody', block));
|
|
104
|
+
child('Text', child('TableCell', row));
|
|
105
|
+
child('Text', child('TableCell', row));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
case 'ContentList':
|
|
109
|
+
child('Text', child('ContentListItem', block));
|
|
110
|
+
return;
|
|
111
|
+
case 'DescriptionList':
|
|
112
|
+
child('Text', child('DescriptionTerm', block));
|
|
113
|
+
child('Text', child('DescriptionDetails', block));
|
|
114
|
+
return;
|
|
115
|
+
case 'Card': {
|
|
116
|
+
const body = child('CardBody', block);
|
|
117
|
+
child('CardTitle', body);
|
|
118
|
+
child('CardText', body);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
case 'CardGroup':
|
|
122
|
+
child('CardText', child('CardBody', child('Card', block)));
|
|
123
|
+
return;
|
|
124
|
+
case 'ListGroup':
|
|
125
|
+
child('Text', child('ListGroupItem', block));
|
|
126
|
+
return;
|
|
127
|
+
case 'Figure':
|
|
128
|
+
additions.push(image(authoringUuid(), block.props.id));
|
|
129
|
+
child('Text', child('Figcaption', block));
|
|
130
|
+
return;
|
|
131
|
+
case 'Cite':
|
|
132
|
+
child('Text', block).props.element = 'span';
|
|
133
|
+
return;
|
|
134
|
+
default:
|
|
135
|
+
if (TEXT_CONTAINER_TYPES.has(block.type))
|
|
136
|
+
child('Text', block);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export function createBootstrapFamily(type, parent, image) {
|
|
140
|
+
const block = createBootstrapBlock(type, authoringUuid(), parent?.props.id);
|
|
141
|
+
if (block.type === 'Text' && parent?.type === 'Cite')
|
|
142
|
+
block.props.element = 'span';
|
|
143
|
+
const additions = [block];
|
|
144
|
+
const child = (kind, owner) => {
|
|
145
|
+
const item = createBootstrapBlock(kind, authoringUuid(), owner.props.id);
|
|
146
|
+
additions.push(item);
|
|
147
|
+
return item;
|
|
148
|
+
};
|
|
149
|
+
appendBootstrapChildren(block, child, additions, image);
|
|
150
|
+
return { block, additions };
|
|
151
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type GridImportBlock = Readonly<{
|
|
2
|
+
type: string;
|
|
3
|
+
props: Readonly<Record<string, unknown>> & {
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
}>;
|
|
7
|
+
/** Pure conversion shared by the reference importer and saved-document migration. */
|
|
8
|
+
export declare function importBootstrapGrid(blocks: readonly GridImportBlock[]): readonly GridImportBlock[];
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const classesOf = (block) => typeof block.props.cssClasses === 'string' ? block.props.cssClasses : '';
|
|
2
|
+
const gridBreakpoints = [
|
|
3
|
+
['', '', 'mobile'], ['sm', 'Sm', 'small'], ['md', 'Md', 'medium'],
|
|
4
|
+
['lg', 'Lg', 'large'], ['xl', 'Xl', 'extraLarge'], ['xxl', 'Xxl', 'extraExtraLarge'],
|
|
5
|
+
];
|
|
6
|
+
/** Keep grid settings in editable properties rather than opaque wrapper classes. */
|
|
7
|
+
function gridProperties(classes, type) {
|
|
8
|
+
const props = type === 'Row'
|
|
9
|
+
? { gap: 0, horizontalGap: 4, verticalGap: 0, alignment: 'stretch' }
|
|
10
|
+
: { mobileWidth: 12, width: 12 };
|
|
11
|
+
const remaining = new Set(classes.split(/\s+/).filter(Boolean));
|
|
12
|
+
if (type === 'Row')
|
|
13
|
+
remaining.delete('row');
|
|
14
|
+
for (const [breakpoint, suffix, prefix] of gridBreakpoints) {
|
|
15
|
+
const infix = breakpoint ? `${breakpoint}-` : '';
|
|
16
|
+
for (const name of [...remaining].sort((a, b) => Number(/^g[xy]-/.test(a)) - Number(/^g[xy]-/.test(b)))) {
|
|
17
|
+
if (type === 'Row') {
|
|
18
|
+
const gutter = name.match(new RegExp(`^g([xy]?)-${infix}([0-5])$`));
|
|
19
|
+
if (gutter) {
|
|
20
|
+
for (const axis of gutter[1] ? [gutter[1]] : ['x', 'y']) {
|
|
21
|
+
const key = suffix ? `gutter${axis.toUpperCase()}${suffix}` : axis === 'x' ? 'horizontalGap' : 'verticalGap';
|
|
22
|
+
props[key] = Number(gutter[2]);
|
|
23
|
+
}
|
|
24
|
+
remaining.delete(name);
|
|
25
|
+
}
|
|
26
|
+
const count = name.match(new RegExp(`^row-cols-${infix}([1-6])$`));
|
|
27
|
+
if (count) {
|
|
28
|
+
props[`columns${suffix}`] = Number(count[1]);
|
|
29
|
+
remaining.delete(name);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const width = name.match(new RegExp(`^col${breakpoint ? `-${breakpoint}` : ''}(?:-(auto|[1-9]|1[0-2]))?$`));
|
|
34
|
+
if (width) {
|
|
35
|
+
props[`${prefix}WidthMode`] = width[1] === 'auto' ? 'auto' : width[1] ? 'fixed' : 'equal';
|
|
36
|
+
if (width[1] && width[1] !== 'auto')
|
|
37
|
+
props[`${prefix}Width`] = Number(width[1]);
|
|
38
|
+
remaining.delete(name);
|
|
39
|
+
}
|
|
40
|
+
const offset = name.match(new RegExp(`^offset-${infix}([0-9]|1[01])$`));
|
|
41
|
+
if (offset) {
|
|
42
|
+
props[`${prefix}Offset`] = Number(offset[1]);
|
|
43
|
+
remaining.delete(name);
|
|
44
|
+
}
|
|
45
|
+
const order = name.match(new RegExp(`^order-${infix}([0-5])$`));
|
|
46
|
+
if (order) {
|
|
47
|
+
props[`${prefix}Order`] = Number(order[1]);
|
|
48
|
+
remaining.delete(name);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (type === 'Column') {
|
|
54
|
+
// The portable model's legacy width applies at md. Do not reset inherited xs/sm sizing there.
|
|
55
|
+
props.width = props.mediumWidth ?? props.smallWidth ?? props.mobileWidth;
|
|
56
|
+
props.widthMode = props.mediumWidthMode ?? props.smallWidthMode ?? props.mobileWidthMode ?? 'fixed';
|
|
57
|
+
}
|
|
58
|
+
const sides = { t: ['Top'], b: ['Bottom'], s: ['Start'], e: ['End'], x: ['Start', 'End'], y: ['Top', 'Bottom'], '': ['Top', 'Bottom', 'Start', 'End'] };
|
|
59
|
+
for (const name of remaining) {
|
|
60
|
+
const spacing = name.match(/^([mp])([tbsexy]?)-([0-5])$/);
|
|
61
|
+
if (!spacing)
|
|
62
|
+
continue;
|
|
63
|
+
for (const side of sides[spacing[2]])
|
|
64
|
+
props[`${spacing[1] === 'm' ? 'margin' : 'padding'}${side}`] = Number(spacing[3]);
|
|
65
|
+
remaining.delete(name);
|
|
66
|
+
}
|
|
67
|
+
return { ...props, cssClasses: [...remaining].join(' ') };
|
|
68
|
+
}
|
|
69
|
+
const columnClass = /^col(?:-(?:sm|md|lg|xl|xxl))?(?:-(?:auto|[1-9]|1[0-2]))?$/;
|
|
70
|
+
const semanticWrapper = (block) => block.type === 'Group' && block.props.element && block.props.element !== 'div';
|
|
71
|
+
function convertedGroup(block, type, parentId = block.props.parentId) {
|
|
72
|
+
const { element: _element, cssClasses: _classes, alignment, spacing, parentId: _parent, ...props } = block.props;
|
|
73
|
+
const grid = gridProperties(classesOf(block), type);
|
|
74
|
+
const classes = [grid.cssClasses, alignment ? `text-${String(alignment)}` : '', spacing ? (spacing === 'compact' ? 'p-1' : spacing === 'normal' ? 'p-3' : 'p-5') : ''].filter(Boolean).join(' ');
|
|
75
|
+
return { type, props: { ...grid, ...props, ...(parentId === undefined ? {} : { parentId }), ...(type === 'Row' ? { alignment: grid.alignment } : {}), cssClasses: classes } };
|
|
76
|
+
}
|
|
77
|
+
/** Pure conversion shared by the reference importer and saved-document migration. */
|
|
78
|
+
export function importBootstrapGrid(blocks) {
|
|
79
|
+
const rowBlocks = blocks.filter(block => block.type === 'Group' && classesOf(block).split(/\s+/).includes('row'));
|
|
80
|
+
if (!rowBlocks.length)
|
|
81
|
+
return blocks;
|
|
82
|
+
const usedIds = new Set(blocks.map(block => block.props.id));
|
|
83
|
+
const identity = (id, role) => {
|
|
84
|
+
const prefix = `${id.slice(0, 80)}-${role}`;
|
|
85
|
+
let candidate = prefix;
|
|
86
|
+
for (let suffix = 2; usedIds.has(candidate); suffix++)
|
|
87
|
+
candidate = `${prefix}-${suffix}`;
|
|
88
|
+
usedIds.add(candidate);
|
|
89
|
+
return candidate;
|
|
90
|
+
};
|
|
91
|
+
const rows = new Map(rowBlocks.map(block => [block.props.id, semanticWrapper(block) ? identity(block.props.id, 'row') : block.props.id]));
|
|
92
|
+
return blocks.flatMap((block) => {
|
|
93
|
+
const classes = classesOf(block);
|
|
94
|
+
const ownRow = rows.get(block.props.id);
|
|
95
|
+
if (ownRow) {
|
|
96
|
+
const grid = gridProperties(classes, 'Row');
|
|
97
|
+
const family = semanticWrapper(block)
|
|
98
|
+
? [{ ...block, props: { ...block.props, cssClasses: grid.cssClasses } },
|
|
99
|
+
{ type: 'Row', props: { ...grid, id: ownRow, parentId: block.props.id, cssClasses: '' } }]
|
|
100
|
+
: [convertedGroup(block, 'Row')];
|
|
101
|
+
const parentRow = typeof block.props.parentId === 'string' ? rows.get(block.props.parentId) : undefined;
|
|
102
|
+
const root = family[0];
|
|
103
|
+
if (!parentRow || !root)
|
|
104
|
+
return family;
|
|
105
|
+
const id = identity(block.props.id, 'column');
|
|
106
|
+
return [{ type: 'Column', props: { ...gridProperties('', 'Column'), id, parentId: parentRow } },
|
|
107
|
+
{ ...root, props: { ...root.props, parentId: id } }, ...family.slice(1)];
|
|
108
|
+
}
|
|
109
|
+
const parent = block.props.parentId;
|
|
110
|
+
const parentId = typeof parent === 'string' ? rows.get(parent) : undefined;
|
|
111
|
+
if (!parentId)
|
|
112
|
+
return [block];
|
|
113
|
+
const isColumn = classes.split(/\s+/).some(name => columnClass.test(name));
|
|
114
|
+
if (block.type === 'Group' && isColumn && !semanticWrapper(block))
|
|
115
|
+
return [convertedGroup(block, 'Column', parentId)];
|
|
116
|
+
// Keep semantic components and ordinary wrappers intact, inside a grid column.
|
|
117
|
+
const id = identity(block.props.id, 'column');
|
|
118
|
+
const grid = gridProperties(isColumn ? classes : '', 'Column');
|
|
119
|
+
return [{ type: 'Column', props: { ...grid, id, parentId, cssClasses: '' } },
|
|
120
|
+
{ ...block, props: { ...block.props, parentId: id, ...(isColumn ? { cssClasses: grid.cssClasses } : {}) } }];
|
|
121
|
+
});
|
|
122
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { contentBlockSchema } from './componentValidation.js';
|
|
2
|
+
import { reusableContentIssues } from './contentTreeValidation.js';
|
|
3
|
+
import { importBootstrapGrid } from './bootstrapGridImport.js';
|
|
4
|
+
/** Upgrade grid wrappers in place; never replace authored content from a template. */
|
|
5
|
+
export function migrateBootstrapGrid(blocks) {
|
|
6
|
+
const migrated = importBootstrapGrid(blocks);
|
|
7
|
+
if (migrated === blocks)
|
|
8
|
+
return blocks;
|
|
9
|
+
const originals = new Map(blocks.map(block => [block.props.id, block]));
|
|
10
|
+
const parsed = migrated.map(block => {
|
|
11
|
+
const original = originals.get(block.props.id);
|
|
12
|
+
if (original === block)
|
|
13
|
+
return original;
|
|
14
|
+
// Callout is a lesson-owned leaf: this conversion changes only its parent.
|
|
15
|
+
if (original?.type === 'Callout' && block.type === 'Callout') {
|
|
16
|
+
const parentId = block.props.parentId;
|
|
17
|
+
if (typeof parentId !== 'string' || !parentId || parentId.length > 100)
|
|
18
|
+
throw new Error('Invalid migrated callout parent.');
|
|
19
|
+
return { ...original, props: { ...original.props, parentId } };
|
|
20
|
+
}
|
|
21
|
+
return contentBlockSchema.parse(block);
|
|
22
|
+
});
|
|
23
|
+
const issues = reusableContentIssues(parsed);
|
|
24
|
+
if (issues.length)
|
|
25
|
+
throw new Error(`Invalid migrated Bootstrap grid: ${issues[0]?.message}`);
|
|
26
|
+
return parsed;
|
|
27
|
+
}
|