@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,117 @@
|
|
|
1
|
+
export const requiredParents = {
|
|
2
|
+
TabPane: ['TabContent'],
|
|
3
|
+
NavbarBrand: ['Navbar'], NavbarToggle: ['Navbar'], NavbarCollapse: ['Navbar'],
|
|
4
|
+
NavLink: ['Nav'], PaginationItem: ['Pagination'], InputGroupText: ['InputGroup'],
|
|
5
|
+
DropdownDivider: ['Dropdown'], DropdownHeader: ['Dropdown'],
|
|
6
|
+
AccordionItem: ['Accordion'],
|
|
7
|
+
Tab: ['Tabs'],
|
|
8
|
+
CarouselItem: ['Carousel'],
|
|
9
|
+
DropdownItem: ['Dropdown'],
|
|
10
|
+
BreadcrumbItem: ['Breadcrumb'],
|
|
11
|
+
ContentListItem: ['ContentList'],
|
|
12
|
+
DescriptionTerm: ['DescriptionList'],
|
|
13
|
+
DescriptionDetails: ['DescriptionList'],
|
|
14
|
+
Column: ['Row'],
|
|
15
|
+
TableCaption: ['Table'],
|
|
16
|
+
TableHead: ['Table'],
|
|
17
|
+
TableBody: ['Table'],
|
|
18
|
+
TableFoot: ['Table'],
|
|
19
|
+
TableRow: ['TableHead', 'TableBody', 'TableFoot'],
|
|
20
|
+
TableHeader: ['TableRow'],
|
|
21
|
+
TableCell: ['TableRow'],
|
|
22
|
+
ListGroupItem: ['ListGroup'],
|
|
23
|
+
CardHeader: ['Card'],
|
|
24
|
+
CardBody: ['Card'],
|
|
25
|
+
CardFooter: ['Card'],
|
|
26
|
+
CardImage: ['Card'],
|
|
27
|
+
CardImageOverlay: ['Card'],
|
|
28
|
+
CardTitle: ['Card', 'CardHeader', 'CardBody', 'CardFooter', 'CardImageOverlay'],
|
|
29
|
+
CardSubtitle: ['Card', 'CardHeader', 'CardBody', 'CardFooter', 'CardImageOverlay'],
|
|
30
|
+
CardText: ['Card', 'CardHeader', 'CardBody', 'CardFooter', 'CardImageOverlay'],
|
|
31
|
+
CardLink: [
|
|
32
|
+
'Card',
|
|
33
|
+
'CardHeader',
|
|
34
|
+
'CardBody',
|
|
35
|
+
'CardFooter',
|
|
36
|
+
'CardImageOverlay',
|
|
37
|
+
'TableHeader',
|
|
38
|
+
'TableCell',
|
|
39
|
+
],
|
|
40
|
+
Figcaption: ['Figure'],
|
|
41
|
+
Cite: ['Blockquote', 'Figcaption', 'TableCaption'],
|
|
42
|
+
};
|
|
43
|
+
export const structuralChildren = {
|
|
44
|
+
TabContent: ['TabPane'],
|
|
45
|
+
Navbar: ['NavbarBrand', 'NavbarToggle', 'NavbarCollapse'],
|
|
46
|
+
Nav: ['NavLink', 'Dropdown'], Pagination: ['PaginationItem'], ProgressGroup: ['Progress'],
|
|
47
|
+
Accordion: ['AccordionItem'],
|
|
48
|
+
Tabs: ['Tab'],
|
|
49
|
+
Carousel: ['CarouselItem'],
|
|
50
|
+
Dropdown: ['DropdownItem', 'DropdownDivider', 'DropdownHeader'],
|
|
51
|
+
Breadcrumb: ['BreadcrumbItem'],
|
|
52
|
+
ButtonGroup: ['Button', 'Dropdown', 'PracticeCheck'],
|
|
53
|
+
ContentList: ['ContentListItem'],
|
|
54
|
+
DescriptionList: ['DescriptionTerm', 'DescriptionDetails'],
|
|
55
|
+
Row: ['Column'],
|
|
56
|
+
Table: ['TableCaption', 'TableHead', 'TableBody', 'TableFoot'],
|
|
57
|
+
TableHead: ['TableRow'],
|
|
58
|
+
TableBody: ['TableRow'],
|
|
59
|
+
TableFoot: ['TableRow'],
|
|
60
|
+
TableRow: ['TableHeader', 'TableCell'],
|
|
61
|
+
ListGroup: ['ListGroupItem'],
|
|
62
|
+
CardGroup: ['Card'],
|
|
63
|
+
Card: [
|
|
64
|
+
'CardHeader',
|
|
65
|
+
'CardBody',
|
|
66
|
+
'CardFooter',
|
|
67
|
+
'CardImage',
|
|
68
|
+
'CardImageOverlay',
|
|
69
|
+
'CardTitle',
|
|
70
|
+
'CardSubtitle',
|
|
71
|
+
'CardText',
|
|
72
|
+
'CardLink',
|
|
73
|
+
'ListGroup',
|
|
74
|
+
],
|
|
75
|
+
Figure: ['Text', 'Image', 'Figcaption', 'Blockquote'],
|
|
76
|
+
Cite: ['Text'],
|
|
77
|
+
};
|
|
78
|
+
export const flowParents = new Set([
|
|
79
|
+
'Stack',
|
|
80
|
+
'Alert',
|
|
81
|
+
'ContentListItem',
|
|
82
|
+
'DescriptionDetails',
|
|
83
|
+
'DescriptionTerm',
|
|
84
|
+
'Group',
|
|
85
|
+
'Ratio',
|
|
86
|
+
'AccordionItem',
|
|
87
|
+
'Tab',
|
|
88
|
+
'Reveal',
|
|
89
|
+
'Tooltip',
|
|
90
|
+
'Popover',
|
|
91
|
+
'CarouselItem',
|
|
92
|
+
'Modal',
|
|
93
|
+
'Offcanvas',
|
|
94
|
+
'Toast',
|
|
95
|
+
'Container',
|
|
96
|
+
'Column',
|
|
97
|
+
'TabContainer',
|
|
98
|
+
'TabPane',
|
|
99
|
+
'NavbarCollapse',
|
|
100
|
+
'InputGroup',
|
|
101
|
+
'ListGroupItem',
|
|
102
|
+
'CardHeader',
|
|
103
|
+
'CardBody',
|
|
104
|
+
'CardFooter',
|
|
105
|
+
'CardImageOverlay',
|
|
106
|
+
'Blockquote',
|
|
107
|
+
'Figcaption',
|
|
108
|
+
'TableCaption',
|
|
109
|
+
'TableCell',
|
|
110
|
+
'TableHeader',
|
|
111
|
+
]);
|
|
112
|
+
export function canContainContentBlock(parent, child) {
|
|
113
|
+
const required = requiredParents[child];
|
|
114
|
+
if (required && (!parent || !required.includes(parent)))
|
|
115
|
+
return false;
|
|
116
|
+
return !parent || (structuralChildren[parent]?.includes(child) ?? flowParents.has(parent));
|
|
117
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { layoutParent } from './layout.js';
|
|
2
|
+
// Content selectors describe the published elements, excluding authoring wrappers,
|
|
3
|
+
// generated Bootstrap classes and editor IDs. An ancestor is already represented by its tree row.
|
|
4
|
+
const SELECTORS = {
|
|
5
|
+
FormLabel: 'label', FormControl: 'input', FormSelect: 'select', FormRange: 'input',
|
|
6
|
+
Navbar: 'nav', NavbarBrand: 'a', NavbarToggle: 'button', NavbarCollapse: 'div',
|
|
7
|
+
Nav: 'div', NavLink: 'a', Pagination: 'ul', PaginationItem: 'li', InputGroup: 'div', InputGroupText: 'span',
|
|
8
|
+
ProgressGroup: 'div', DropdownDivider: 'hr', DropdownHeader: 'div', TabContainer: 'div', TabContent: 'div', TabPane: 'div',
|
|
9
|
+
Heading: 'h2', Paragraph: 'div', Callout: 'aside', Image: 'figure', Row: 'div', Column: 'div',
|
|
10
|
+
Group: 'div', Ratio: 'div', Accordion: 'div', AccordionItem: 'div',
|
|
11
|
+
Tabs: 'div', Tab: 'div', Button: 'button', ButtonGroup: 'div', Reveal: 'div',
|
|
12
|
+
Tooltip: 'div', Popover: 'div', Carousel: 'div', CarouselItem: 'fieldset', Progress: 'div',
|
|
13
|
+
Modal: 'div', Offcanvas: 'div', Dropdown: 'div', DropdownItem: 'a', Toast: 'div',
|
|
14
|
+
PracticeInput: 'div', PracticeSelect: 'div', PracticeCheck: 'div', PracticeRange: 'div',
|
|
15
|
+
Breadcrumb: 'nav', BreadcrumbItem: 'li', Video: 'video', Audio: 'audio', Embed: 'iframe',
|
|
16
|
+
Stack: 'div', Divider: 'hr', Alert: 'div', ContentList: 'ul', ContentListItem: 'li',
|
|
17
|
+
DescriptionList: 'dl', DescriptionTerm: 'dt', DescriptionDetails: 'dd', Container: 'div', Text: 'p', Figure: 'figure',
|
|
18
|
+
Blockquote: 'blockquote', Figcaption: 'figcaption', Cite: 'cite',
|
|
19
|
+
Table: 'table', TableHead: 'thead', TableBody: 'tbody', TableFoot: 'tfoot', TableRow: 'tr', TableHeader: 'th', TableCell: 'td', TableCaption: 'caption',
|
|
20
|
+
CloseButton: 'button', Placeholder: 'div', PlaceholderButton: 'div', Spinner: 'div', Indicator: 'span', Badge: 'span', ListGroup: 'ul', ListGroupItem: 'li',
|
|
21
|
+
Card: 'div', CardHeader: 'div', CardBody: 'div', CardFooter: 'div',
|
|
22
|
+
CardTitle: 'h5', CardSubtitle: 'h6', CardText: 'p', CardLink: 'a', CardImage: 'img', CardImageOverlay: 'div', CardGroup: 'div',
|
|
23
|
+
};
|
|
24
|
+
function selector(block) {
|
|
25
|
+
switch (block.type) {
|
|
26
|
+
case 'FormControl': return block.props.type === 'textarea' ? 'textarea' : 'input';
|
|
27
|
+
case 'Heading': return `h${block.props.level ?? 2}`;
|
|
28
|
+
case 'Text': return block.props.element === 'lead' ? 'p' : block.props.element ?? 'p';
|
|
29
|
+
case 'CardTitle':
|
|
30
|
+
case 'CardSubtitle': return block.props.element ?? 'div';
|
|
31
|
+
case 'Group': return block.props.element ?? 'div';
|
|
32
|
+
case 'ContentList': return block.props.ordered ? 'ol' : 'ul';
|
|
33
|
+
case 'ListGroup': return block.props.numbered ? 'ol' : 'ul';
|
|
34
|
+
case 'Badge':
|
|
35
|
+
case 'Indicator': return block.props.element ?? 'span';
|
|
36
|
+
case 'Button': return block.props.action === 'link' && block.props.href ? 'a' : 'button';
|
|
37
|
+
default: return SELECTORS[block.type];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function segment(block, blocks) {
|
|
41
|
+
const own = selector(block);
|
|
42
|
+
// Only table rows/cells have a direct, schema-owned sibling element list.
|
|
43
|
+
// Other components can render internal wrappers; their selectors stay general.
|
|
44
|
+
if (!['TableRow', 'TableHeader', 'TableCell'].includes(block.type))
|
|
45
|
+
return own;
|
|
46
|
+
const siblings = blocks.filter(item => layoutParent(item) === layoutParent(block) && selector(item) === own);
|
|
47
|
+
return siblings.length > 1 ? `${own}:nth-of-type(${siblings.findIndex(item => item.props.id === block.props.id) + 1})` : own;
|
|
48
|
+
}
|
|
49
|
+
export function contentCssPath(block, blocks) {
|
|
50
|
+
const own = segment(block, blocks);
|
|
51
|
+
const path = [own];
|
|
52
|
+
const visited = new Set([block.props.id]);
|
|
53
|
+
let parent = layoutParent(block);
|
|
54
|
+
while (parent && !visited.has(parent)) {
|
|
55
|
+
visited.add(parent);
|
|
56
|
+
const owner = blocks.find(item => item.props.id === parent);
|
|
57
|
+
if (!owner)
|
|
58
|
+
break;
|
|
59
|
+
path.unshift(segment(owner, blocks));
|
|
60
|
+
parent = layoutParent(owner);
|
|
61
|
+
}
|
|
62
|
+
return { segment: own, path: path.join(' ') };
|
|
63
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type BlockIdentity = Readonly<{
|
|
2
|
+
props: Readonly<{
|
|
3
|
+
id: string;
|
|
4
|
+
}>;
|
|
5
|
+
}>;
|
|
6
|
+
export type ContentEditingCommand<Block extends BlockIdentity = BlockIdentity> = Readonly<{
|
|
7
|
+
kind: 'select' | 'delete' | 'duplicate' | 'expand' | 'collapse';
|
|
8
|
+
id: string;
|
|
9
|
+
}> | Readonly<{
|
|
10
|
+
kind: 'edit';
|
|
11
|
+
id: string;
|
|
12
|
+
block: Block;
|
|
13
|
+
}> | Readonly<{
|
|
14
|
+
kind: 'move';
|
|
15
|
+
id: string;
|
|
16
|
+
offset: -1 | 1;
|
|
17
|
+
}>;
|
|
18
|
+
export type ContentEditingKey = Readonly<{
|
|
19
|
+
key: string;
|
|
20
|
+
altKey: boolean;
|
|
21
|
+
ctrlKey: boolean;
|
|
22
|
+
metaKey: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
/** One component-navigation contract for outline and canvas, independent of a host document. */
|
|
25
|
+
export declare function contentEditingCommand<Block extends BlockIdentity>(blocks: readonly Block[], visible: readonly Block[], collapsed: ReadonlySet<string>, id: string, event: ContentEditingKey): ContentEditingCommand<Block> | undefined;
|
|
26
|
+
/** Native controls, rich text and dialogs own their editing keys. */
|
|
27
|
+
export declare function isContentEditingTarget(target: EventTarget | null): boolean;
|
|
28
|
+
export declare function contentHistoryCommand(event: ContentEditingKey & Readonly<{
|
|
29
|
+
shiftKey?: boolean;
|
|
30
|
+
}>, target: EventTarget | null): 'undo' | 'redo' | undefined;
|
|
31
|
+
/** Authored disclosure controls and inline editors own their pointer/keyboard events. */
|
|
32
|
+
export declare function isCanvasInteractionTarget(target: EventTarget | null): boolean;
|
|
33
|
+
/** Pointer selection may select authored menu items; their keyboard navigation stays native. */
|
|
34
|
+
export declare function isCanvasPointerInteractionTarget(target: EventTarget | null): boolean;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { layoutParent } from './layout.js';
|
|
2
|
+
/** One component-navigation contract for outline and canvas, independent of a host document. */
|
|
3
|
+
export function contentEditingCommand(blocks, visible, collapsed, id, event) {
|
|
4
|
+
if (event.altKey) {
|
|
5
|
+
if (event.key === 'ArrowUp' || event.key === 'ArrowDown')
|
|
6
|
+
return { kind: 'move', id, offset: event.key === 'ArrowUp' ? -1 : 1 };
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const block = visible.find(item => item.props.id === id);
|
|
10
|
+
if (!block)
|
|
11
|
+
return undefined;
|
|
12
|
+
if (event.ctrlKey || event.metaKey)
|
|
13
|
+
return event.key.toLowerCase() === 'd' ? { kind: 'duplicate', id } : undefined;
|
|
14
|
+
const index = visible.indexOf(block);
|
|
15
|
+
const hasChildren = blocks.some(child => layoutParent(child) === id);
|
|
16
|
+
if (event.key === 'ArrowLeft' && hasChildren && !collapsed.has(id))
|
|
17
|
+
return { kind: 'collapse', id };
|
|
18
|
+
if (event.key === 'ArrowRight' && hasChildren) {
|
|
19
|
+
if (collapsed.has(id))
|
|
20
|
+
return { kind: 'expand', id };
|
|
21
|
+
const child = visible.find(item => layoutParent(item) === id);
|
|
22
|
+
return child ? { kind: 'select', id: child.props.id } : undefined;
|
|
23
|
+
}
|
|
24
|
+
let adjacent;
|
|
25
|
+
switch (event.key) {
|
|
26
|
+
case 'ArrowDown':
|
|
27
|
+
adjacent = visible[index + 1];
|
|
28
|
+
break;
|
|
29
|
+
case 'ArrowUp':
|
|
30
|
+
adjacent = visible[index - 1];
|
|
31
|
+
break;
|
|
32
|
+
case 'Home':
|
|
33
|
+
adjacent = visible[0];
|
|
34
|
+
break;
|
|
35
|
+
case 'End':
|
|
36
|
+
adjacent = visible.at(-1);
|
|
37
|
+
break;
|
|
38
|
+
case 'ArrowLeft':
|
|
39
|
+
case 'Escape': return { kind: 'select', id: layoutParent(block) ?? '' };
|
|
40
|
+
case 'Enter':
|
|
41
|
+
case 'F2':
|
|
42
|
+
case 'ArrowRight': return { kind: 'edit', id, block };
|
|
43
|
+
case 'Delete':
|
|
44
|
+
case 'Backspace': return { kind: 'delete', id };
|
|
45
|
+
}
|
|
46
|
+
return adjacent ? { kind: 'select', id: adjacent.props.id } : undefined;
|
|
47
|
+
}
|
|
48
|
+
/** Native controls, rich text and dialogs own their editing keys. */
|
|
49
|
+
export function isContentEditingTarget(target) {
|
|
50
|
+
return target instanceof Element && Boolean(target.closest('input, textarea, select, [contenteditable=true], .content-inline-editor, [role=dialog]'));
|
|
51
|
+
}
|
|
52
|
+
export function contentHistoryCommand(event, target) {
|
|
53
|
+
if (!(event.ctrlKey || event.metaKey) || event.altKey || isContentEditingTarget(target))
|
|
54
|
+
return undefined;
|
|
55
|
+
const key = event.key.toLowerCase();
|
|
56
|
+
if (key !== 'z' && key !== 'y')
|
|
57
|
+
return undefined;
|
|
58
|
+
return key === 'y' || event.shiftKey ? 'redo' : 'undo';
|
|
59
|
+
}
|
|
60
|
+
/** Authored disclosure controls and inline editors own their pointer/keyboard events. */
|
|
61
|
+
export function isCanvasInteractionTarget(target) {
|
|
62
|
+
return target instanceof Element && Boolean(target.closest('[data-puck-overlay-portal], .dropdown-toggle, .dropdown-menu, .content-inline-editor, .content-empty-component'));
|
|
63
|
+
}
|
|
64
|
+
/** Pointer selection may select authored menu items; their keyboard navigation stays native. */
|
|
65
|
+
export function isCanvasPointerInteractionTarget(target) {
|
|
66
|
+
if (target instanceof Element && target.closest('.dropdown-item[data-block-id]:not(.disabled):not(:disabled)'))
|
|
67
|
+
return false;
|
|
68
|
+
return isCanvasInteractionTarget(target);
|
|
69
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ContentBlock } from './contentModel.js';
|
|
2
|
+
/** Insert a complete family in document order, including structural section ordering. */
|
|
3
|
+
export declare function insertContentFamily<Block extends ContentBlock>(blocks: readonly Block[], family: readonly Block[], parent: ContentBlock | undefined, type: string): Block[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { layoutParent, orderedSlideBlocks } from './layout.js';
|
|
2
|
+
const SECTION_ORDER = { TableCaption: 0, TableHead: 1, TableBody: 2, TableFoot: 3, CardHeader: 0, CardBody: 1, CardFooter: 2 };
|
|
3
|
+
/** Insert a complete family in document order, including structural section ordering. */
|
|
4
|
+
export function insertContentFamily(blocks, family, parent, type) {
|
|
5
|
+
const result = [...blocks];
|
|
6
|
+
const orderedSections = parent?.type === 'Table' || parent?.type === 'Card';
|
|
7
|
+
const rank = SECTION_ORDER[type];
|
|
8
|
+
const before = orderedSections && rank !== undefined
|
|
9
|
+
? result.findIndex(block => layoutParent(block) === parent.props.id && (SECTION_ORDER[block.type] ?? rank) > rank)
|
|
10
|
+
: -1;
|
|
11
|
+
result.splice(before < 0 ? result.length : before, 0, ...family);
|
|
12
|
+
// Preserve invalid identity collisions so the host validator rejects the edit.
|
|
13
|
+
if (new Set(result.map(block => block.props.id)).size !== result.length)
|
|
14
|
+
return result;
|
|
15
|
+
return orderedSlideBlocks(result);
|
|
16
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BootstrapBlock, InteractionBlock, SlideHeading, SlideParagraph, SlideCallout, SlideImage, SlideRow, SlideColumn } from './contracts/types.gen.js';
|
|
2
|
+
/** Component shapes are generated from the canonical model; hosts own document validation. */
|
|
3
|
+
export type ContentBlock = BootstrapBlock | InteractionBlock | SlideHeading | SlideParagraph | SlideCallout | SlideImage | SlideRow | SlideColumn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ContentBlock } from './contentModel.js';
|
|
2
|
+
export type ContentTreeIssue = Readonly<{
|
|
3
|
+
index: number;
|
|
4
|
+
property: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}>;
|
|
7
|
+
/** Common relationships, interactions and safety rules used by every authoring host. */
|
|
8
|
+
export declare function reusableContentIssues(content: readonly ContentBlock[]): ContentTreeIssue[];
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { requiredParents, structuralChildren, flowParents } from './contentContainment.js';
|
|
2
|
+
import { validInlineMarkup, validContentUrl } from './inlineMarkup.js';
|
|
3
|
+
import { layoutParent } from './layout.js';
|
|
4
|
+
import { parseSpacing } from './spacingShorthand.js';
|
|
5
|
+
const visibilityTargets = new Set(['Reveal', 'Modal', 'Offcanvas', 'Toast']);
|
|
6
|
+
const spacingProperties = [
|
|
7
|
+
'marginSm',
|
|
8
|
+
'marginMd',
|
|
9
|
+
'marginLg',
|
|
10
|
+
'marginXl',
|
|
11
|
+
'marginXxl',
|
|
12
|
+
'paddingSm',
|
|
13
|
+
'paddingMd',
|
|
14
|
+
'paddingLg',
|
|
15
|
+
'paddingXl',
|
|
16
|
+
'paddingXxl',
|
|
17
|
+
];
|
|
18
|
+
function validResponsiveSpacing(value) {
|
|
19
|
+
return parseSpacing(value, 'margin').success;
|
|
20
|
+
}
|
|
21
|
+
function validEmbedSource(value) {
|
|
22
|
+
if (!validContentUrl(value))
|
|
23
|
+
return false;
|
|
24
|
+
try {
|
|
25
|
+
const url = new URL(value);
|
|
26
|
+
return (url.protocol === 'https:' &&
|
|
27
|
+
!url.hash &&
|
|
28
|
+
((url.hostname === 'www.youtube-nocookie.com' && url.pathname.startsWith('/embed/')) ||
|
|
29
|
+
(url.hostname === 'player.vimeo.com' && url.pathname.startsWith('/video/'))));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function validateSlideButton(block, blocks, issue) {
|
|
36
|
+
const props = block.props;
|
|
37
|
+
const action = props.action ?? 'none';
|
|
38
|
+
if (action === 'link') {
|
|
39
|
+
if (!props.href || !validContentUrl(props.href, true))
|
|
40
|
+
issue('Link actions require a safe URL.', 'href');
|
|
41
|
+
}
|
|
42
|
+
else if (props.href != null || props.newWindow)
|
|
43
|
+
issue('Only link actions may use URLs or open a new window.', 'href');
|
|
44
|
+
const requiresTarget = ['toggle', 'show', 'hide', 'select-tab'].includes(action);
|
|
45
|
+
if (requiresTarget && !props.targetId)
|
|
46
|
+
issue('This action requires a target identity.', 'targetId');
|
|
47
|
+
if (!requiresTarget && props.targetId != null)
|
|
48
|
+
issue('This action cannot use a target identity.', 'targetId');
|
|
49
|
+
if (action !== 'select-tab' && props.targetKey != null)
|
|
50
|
+
issue('Only tab actions may use a target key.', 'targetKey');
|
|
51
|
+
const target = props.targetId ? blocks.get(props.targetId) : undefined;
|
|
52
|
+
if (['toggle', 'show', 'hide'].includes(action) &&
|
|
53
|
+
(!target || !visibilityTargets.has(target.type)))
|
|
54
|
+
issue('Visibility actions require a reveal, modal, offcanvas or toast target.', 'targetId');
|
|
55
|
+
if (action === 'select-tab')
|
|
56
|
+
validateTabAction(props, target, blocks, issue);
|
|
57
|
+
}
|
|
58
|
+
function validateTabAction(props, target, blocks, issue) {
|
|
59
|
+
if (target?.type !== 'Tabs')
|
|
60
|
+
issue('Tab actions require a tabs target.', 'targetId');
|
|
61
|
+
else if (!props.targetKey ||
|
|
62
|
+
!Array.from(blocks.values()).some((child) => child.type === 'Tab' &&
|
|
63
|
+
child.props.parentId === target.props.id &&
|
|
64
|
+
child.props.eventKey === props.targetKey &&
|
|
65
|
+
!child.props.disabled))
|
|
66
|
+
issue('Tab actions require an enabled direct tab key.', 'targetKey');
|
|
67
|
+
}
|
|
68
|
+
function validateInteractionBlock(block, blocks, issue) {
|
|
69
|
+
for (const property of spacingProperties) {
|
|
70
|
+
const value = block.props[property];
|
|
71
|
+
if (value != null && !validResponsiveSpacing(value))
|
|
72
|
+
issue('Responsive spacing requires one to four safe Bootstrap or length values.', property);
|
|
73
|
+
}
|
|
74
|
+
if (block.type === 'Button' || block.type === 'DropdownItem')
|
|
75
|
+
validateSlideButton(block, blocks, issue);
|
|
76
|
+
validateCompoundBlock(block, blocks, issue);
|
|
77
|
+
validateRangeBlock(block, issue);
|
|
78
|
+
validateOptionsBlock(block, issue);
|
|
79
|
+
validateMediaBlock(block, issue);
|
|
80
|
+
}
|
|
81
|
+
function validateCompoundBlock(block, blocks, issue) {
|
|
82
|
+
if (block.type === 'AccordionItem' || block.type === 'Tab' || block.type === 'CarouselItem') {
|
|
83
|
+
if (!block.props.eventKey)
|
|
84
|
+
issue('Interactive child keys cannot be empty.', 'eventKey');
|
|
85
|
+
}
|
|
86
|
+
if (block.type === 'Accordion' || block.type === 'Tabs' || block.type === 'Carousel') {
|
|
87
|
+
const keys = Array.from(blocks.values()).flatMap((child) => child.props.parentId === block.props.id && 'eventKey' in child.props
|
|
88
|
+
? [child.props.eventKey]
|
|
89
|
+
: []);
|
|
90
|
+
if (new Set(keys).size !== keys.length)
|
|
91
|
+
issue('Interactive child keys must be unique within their parent.', 'defaultActiveKey');
|
|
92
|
+
if (block.props.defaultActiveKey && !keys.includes(block.props.defaultActiveKey))
|
|
93
|
+
issue('The default active key must name a direct child.', 'defaultActiveKey');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function validateRangeBlock(block, issue) {
|
|
97
|
+
if (block.type === 'Progress' || block.type === 'PracticeRange' || block.type === 'FormRange') {
|
|
98
|
+
const min = block.props.min ?? 0;
|
|
99
|
+
const max = block.props.max ?? 100;
|
|
100
|
+
const value = block.type === 'Progress' ? (block.props.value ?? 0) : (block.props.defaultValue ?? 0);
|
|
101
|
+
if (max <= min || value < min || value > max)
|
|
102
|
+
issue('Value must fall between increasing minimum and maximum bounds.', block.type === 'Progress' ? 'value' : 'defaultValue');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function validateOptionsBlock(block, issue) {
|
|
106
|
+
if (block.type === 'PracticeSelect' || block.type === 'FormSelect') {
|
|
107
|
+
const values = (block.props.options ?? []).map((option) => option.value);
|
|
108
|
+
if (new Set(values).size !== values.length)
|
|
109
|
+
issue('Practice option values must be unique.', 'options');
|
|
110
|
+
if (block.props.defaultValue && !values.includes(block.props.defaultValue))
|
|
111
|
+
issue('The default selection must name an option.', 'defaultValue');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function validateMediaBlock(block, issue) {
|
|
115
|
+
if (block.type === 'Video' || block.type === 'Audio') {
|
|
116
|
+
const sources = {
|
|
117
|
+
src: block.props.src,
|
|
118
|
+
captionsSrc: block.props.captionsSrc,
|
|
119
|
+
...(block.type === 'Video' ? { poster: block.props.poster } : {}),
|
|
120
|
+
};
|
|
121
|
+
for (const [property, source] of Object.entries(sources))
|
|
122
|
+
if (source && (source.startsWith('#') || !validContentUrl(source)))
|
|
123
|
+
issue('Media requires a safe web URL or local path.', property);
|
|
124
|
+
}
|
|
125
|
+
if (block.type === 'Embed' && block.props.src && !validEmbedSource(block.props.src))
|
|
126
|
+
issue('Embeds require an approved HTTPS YouTube privacy or Vimeo player URL.', 'src');
|
|
127
|
+
if (block.type === 'BreadcrumbItem' &&
|
|
128
|
+
block.props.href &&
|
|
129
|
+
!validContentUrl(block.props.href, true))
|
|
130
|
+
issue('Breadcrumb links require a safe URL.', 'href');
|
|
131
|
+
}
|
|
132
|
+
function validateFigure(block, content, issue) {
|
|
133
|
+
const children = content.content.filter((item) => layoutParent(item) === block.props.id);
|
|
134
|
+
const captions = children.flatMap((item, index) => item.type === 'Figcaption' ? [index] : []);
|
|
135
|
+
if (captions.length > 1 ||
|
|
136
|
+
(captions.length === 1 &&
|
|
137
|
+
captions[0] !== 0 &&
|
|
138
|
+
captions[0] !== children.length - 1))
|
|
139
|
+
issue('Figures require at most one caption, before or after their images.');
|
|
140
|
+
}
|
|
141
|
+
function validateTable(block, content, issue) {
|
|
142
|
+
const children = content.content.filter((item) => layoutParent(item) === block.props.id);
|
|
143
|
+
const singleton = ['TableCaption', 'TableHead', 'TableFoot'];
|
|
144
|
+
if (singleton.some((type) => children.filter((item) => item.type === type).length > 1))
|
|
145
|
+
issue('Table captions, heads and feet must be unique.');
|
|
146
|
+
const ranks = {
|
|
147
|
+
TableCaption: 0,
|
|
148
|
+
TableHead: 1,
|
|
149
|
+
TableBody: 2,
|
|
150
|
+
TableFoot: 3,
|
|
151
|
+
};
|
|
152
|
+
if (children.some((item, index) => index > 0 &&
|
|
153
|
+
(ranks[item.type] ?? 0) <
|
|
154
|
+
(ranks[children[index - 1]?.type ?? ''] ?? 0)))
|
|
155
|
+
issue('Table sections must follow caption, head, body and foot order.');
|
|
156
|
+
}
|
|
157
|
+
function validateAncestors(block, parent, blocks, issue) {
|
|
158
|
+
const ancestors = new Set([block.props.id]);
|
|
159
|
+
let ancestor = parent;
|
|
160
|
+
let depth = 1;
|
|
161
|
+
while (ancestor) {
|
|
162
|
+
if (ancestors.has(ancestor.props.id)) {
|
|
163
|
+
issue('Component relationships cannot contain cycles.');
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
if (block.type === 'Table' && ancestor.type === 'TableCaption')
|
|
167
|
+
issue('Table captions cannot contain descendant tables.');
|
|
168
|
+
ancestors.add(ancestor.props.id);
|
|
169
|
+
if (++depth > 12) {
|
|
170
|
+
issue('Components cannot be nested more than 12 levels.');
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
const next = layoutParent(ancestor);
|
|
174
|
+
ancestor = next ? blocks.get(next) : undefined;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function validateBlockRelationships(block, parentId, parent, blocks, content, issue) {
|
|
178
|
+
const allowedParents = requiredParents[block.type];
|
|
179
|
+
if (parentId && !parent)
|
|
180
|
+
issue('The parent component does not exist.');
|
|
181
|
+
else if (parent && allowedParents && !allowedParents.includes(parent.type))
|
|
182
|
+
issue('This component cannot belong to the selected parent.');
|
|
183
|
+
else if (!parent && allowedParents)
|
|
184
|
+
issue('This component requires an owning parent.');
|
|
185
|
+
if (parent &&
|
|
186
|
+
!(structuralChildren[parent.type]?.includes(block.type) ??
|
|
187
|
+
flowParents.has(parent.type)))
|
|
188
|
+
issue('The selected parent cannot contain this component.');
|
|
189
|
+
validateAncestors(block, parent, blocks, issue);
|
|
190
|
+
if (parent?.type === 'Cite' &&
|
|
191
|
+
!('element' in block.props && block.props.element === 'span'))
|
|
192
|
+
issue('Citations contain inline span text only.');
|
|
193
|
+
if (block.type === 'Figure')
|
|
194
|
+
validateFigure(block, content, issue);
|
|
195
|
+
if (block.type === 'Table')
|
|
196
|
+
validateTable(block, content, issue);
|
|
197
|
+
}
|
|
198
|
+
/** Common relationships, interactions and safety rules used by every authoring host. */
|
|
199
|
+
export function reusableContentIssues(content) {
|
|
200
|
+
const issues = [];
|
|
201
|
+
const blocks = new Map(content.map(block => [block.props.id, block]));
|
|
202
|
+
for (const [index, block] of content.entries()) {
|
|
203
|
+
const issue = (message, property) => issues.push({ index, property, message });
|
|
204
|
+
validateInteractionBlock(block, blocks, issue);
|
|
205
|
+
if ('format' in block.props && block.props.format === 'html' && 'text' in block.props && !validInlineMarkup(block.props.text))
|
|
206
|
+
issue('Rich text must contain balanced, supported inline markup and safe links.', 'text');
|
|
207
|
+
const parentId = layoutParent(block);
|
|
208
|
+
validateBlockRelationships(block, parentId, parentId ? blocks.get(parentId) : undefined, blocks, { content }, message => issue(message, 'parentId'));
|
|
209
|
+
}
|
|
210
|
+
return issues;
|
|
211
|
+
}
|