@perkyzz/emvb 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +57 -2
- package/package.json +72 -4
- package/src/admin/access/RequireEditor.tsx +39 -0
- package/src/admin/access/role.ts +36 -0
- package/src/admin/access/sidebar-shim.ts +108 -0
- package/src/admin/api.ts +48 -0
- package/src/admin/content-api.ts +147 -0
- package/src/admin/editor/Editor.tsx +457 -0
- package/src/admin/editor/EditorOverlay.tsx +54 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +20 -0
- package/src/admin/editor/TopBar.tsx +179 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +355 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +50 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +185 -0
- package/src/admin/editor/canvas/canvas-events.ts +232 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +35 -0
- package/src/admin/editor/canvas/vnode-react.tsx +49 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +125 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +101 -0
- package/src/admin/editor/dnd/new-element.ts +32 -0
- package/src/admin/editor/editor-css.ts +539 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/panels/AddPanel.tsx +142 -0
- package/src/admin/editor/panels/ClassesSection.tsx +334 -0
- package/src/admin/editor/panels/ColorControl.tsx +230 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +629 -0
- package/src/admin/editor/panels/LayersPanel.tsx +336 -0
- package/src/admin/editor/panels/LeftPanel.tsx +77 -0
- package/src/admin/editor/panels/PageSettings.tsx +126 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +101 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +392 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +197 -0
- package/src/admin/editor/panels/VariableSection.tsx +492 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +320 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +349 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +201 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +347 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +83 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +150 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +97 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +109 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +181 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +124 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +218 -0
- package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +480 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +167 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +51 -0
- package/src/admin/editor/panels/settings/length-units.ts +83 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +291 -0
- package/src/admin/editor/panels/site-list.tsx +206 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +212 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +142 -0
- package/src/admin/editor/useEditorData.ts +167 -0
- package/src/admin/editor/useEditorShortcuts.ts +148 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +122 -0
- package/src/admin/editor/useSave.ts +185 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/index.tsx +20 -0
- package/src/admin/media-api.ts +68 -0
- package/src/admin/pages/CreateDialog.tsx +150 -0
- package/src/admin/pages/EditorPage.tsx +57 -0
- package/src/admin/pages/NewPageDialog.tsx +83 -0
- package/src/admin/pages/NewThemePartDialog.tsx +61 -0
- package/src/admin/pages/PageList.tsx +71 -0
- package/src/admin/pages/PagesPage.tsx +25 -0
- package/src/admin/pages/SetupShell.tsx +90 -0
- package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
- package/src/admin/pages/ThemePartList.tsx +202 -0
- package/src/admin/pages/list-kit.tsx +75 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +100 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +186 -0
- package/src/admin/ui.ts +231 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +37 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +104 -0
- package/src/astro/index.ts +15 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +246 -0
- package/src/astro/render.ts +74 -0
- package/src/astro/resolve-theme.ts +371 -0
- package/src/astro/resolve.ts +65 -0
- package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
- package/src/astro/tabs/index.ts +1 -0
- package/src/astro/tabs/runtime.ts +111 -0
- package/src/astro/theme-context.ts +81 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +360 -0
- package/src/core/clipboard.ts +422 -0
- package/src/core/css/generate.ts +219 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +138 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +33 -0
- package/src/core/design/variables.ts +319 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +173 -0
- package/src/core/elements/form-elements.ts +204 -0
- package/src/core/elements/index.ts +742 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +34 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +316 -0
- package/src/core/limits.ts +7 -0
- package/src/core/migrate/index.ts +76 -0
- package/src/core/render/context.ts +14 -0
- package/src/core/render/dynamic-post.ts +147 -0
- package/src/core/render/extras.ts +79 -0
- package/src/core/render/form.ts +137 -0
- package/src/core/render/index.ts +274 -0
- package/src/core/render/loop.ts +36 -0
- package/src/core/render/section.ts +33 -0
- package/src/core/render/tabs.ts +72 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +591 -0
- package/src/core/sanitize/embed-url.ts +103 -0
- package/src/core/sanitize/escape.ts +10 -0
- package/src/core/sanitize/href.ts +6 -0
- package/src/core/sanitize/media-url.ts +7 -0
- package/src/core/sanitize/svg.ts +293 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +33 -0
- package/src/core/schema/design.ts +88 -0
- package/src/core/schema/layout.ts +817 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +257 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +16 -0
- package/src/core/theme/conditions.ts +321 -0
- package/src/core/theme/dynamic.ts +133 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +79 -0
- package/src/core/theme/popup-markup.ts +39 -0
- package/src/core/theme/popup-rules.ts +61 -0
- package/src/core/theme/triggers.ts +104 -0
- package/src/core/tree-ops.ts +139 -0
- package/src/core/validate.ts +185 -0
- package/src/index.ts +18 -0
- package/src/server/design-routes.ts +125 -0
- package/src/server/hooks.ts +98 -0
- package/src/server/plugin.ts +39 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
export * from "./limits.ts";
|
|
2
|
+
export {
|
|
3
|
+
LAYOUT_SCHEMA_VERSION,
|
|
4
|
+
Layout,
|
|
5
|
+
type LayoutNode,
|
|
6
|
+
type UnknownNode,
|
|
7
|
+
ContainerNode,
|
|
8
|
+
DivBlockNode,
|
|
9
|
+
FlexboxNode,
|
|
10
|
+
SvgNode,
|
|
11
|
+
TabPanelNode,
|
|
12
|
+
HeadingNode,
|
|
13
|
+
SpacerNode,
|
|
14
|
+
DividerNode,
|
|
15
|
+
TextNode,
|
|
16
|
+
LabelNode,
|
|
17
|
+
LinkNode,
|
|
18
|
+
ButtonNode,
|
|
19
|
+
ListNode,
|
|
20
|
+
ImageNode,
|
|
21
|
+
IconNode,
|
|
22
|
+
VideoNode,
|
|
23
|
+
NodeId,
|
|
24
|
+
CONTAINER_TAGS,
|
|
25
|
+
TEXT_TAGS,
|
|
26
|
+
KNOWN_ELEMENT_TYPES,
|
|
27
|
+
isContainerNode,
|
|
28
|
+
isDivBlockNode,
|
|
29
|
+
isFlexboxNode,
|
|
30
|
+
isLayoutParentNode,
|
|
31
|
+
isTabsNode,
|
|
32
|
+
isTabPanelNode,
|
|
33
|
+
isFormNode,
|
|
34
|
+
isLoopNode,
|
|
35
|
+
isSectionNode,
|
|
36
|
+
isParentNode,
|
|
37
|
+
isFormFieldType,
|
|
38
|
+
FORM_FIELD_TYPES,
|
|
39
|
+
isHeadingNode,
|
|
40
|
+
isUnknownNode,
|
|
41
|
+
FormNode,
|
|
42
|
+
LoopNode,
|
|
43
|
+
SectionNode,
|
|
44
|
+
TextInputNode,
|
|
45
|
+
TextareaNode,
|
|
46
|
+
SelectNode,
|
|
47
|
+
CheckboxNode,
|
|
48
|
+
RadioNode,
|
|
49
|
+
SubmitNode,
|
|
50
|
+
PostTitleNode,
|
|
51
|
+
PostExcerptNode,
|
|
52
|
+
PostContentNode,
|
|
53
|
+
PostImageNode,
|
|
54
|
+
PostLinkNode,
|
|
55
|
+
} from "./schema/layout.ts";
|
|
56
|
+
export {
|
|
57
|
+
type FieldKind,
|
|
58
|
+
type FieldOption,
|
|
59
|
+
type FieldDescriptor,
|
|
60
|
+
type ElementDescriptor,
|
|
61
|
+
} from "./schema/descriptors.ts";
|
|
62
|
+
export {
|
|
63
|
+
ELEMENTS,
|
|
64
|
+
ELEMENT_DESCRIPTORS,
|
|
65
|
+
defaultElement,
|
|
66
|
+
type ElementType,
|
|
67
|
+
} from "./elements/index.ts";
|
|
68
|
+
export {
|
|
69
|
+
commitPlainText,
|
|
70
|
+
isMultilineText,
|
|
71
|
+
isPlainTextNode,
|
|
72
|
+
plainTextOf,
|
|
73
|
+
withPlainText,
|
|
74
|
+
} from "./elements/plain-text.ts";
|
|
75
|
+
export {
|
|
76
|
+
StyleProps,
|
|
77
|
+
StyleStates,
|
|
78
|
+
DeviceStyles,
|
|
79
|
+
HiddenOn,
|
|
80
|
+
ColorValue,
|
|
81
|
+
Length,
|
|
82
|
+
LengthValue,
|
|
83
|
+
VariableRef,
|
|
84
|
+
} from "./schema/style.ts";
|
|
85
|
+
export { STYLE_STATES, type StyleStateName } from "./schema/state-names.ts";
|
|
86
|
+
export {
|
|
87
|
+
upgradeLayout,
|
|
88
|
+
isNewerThanSupported,
|
|
89
|
+
LAYOUT_MIGRATIONS,
|
|
90
|
+
DESIGN_MIGRATIONS,
|
|
91
|
+
type Migration,
|
|
92
|
+
type UpgradeResult,
|
|
93
|
+
} from "./migrate/index.ts";
|
|
94
|
+
export {
|
|
95
|
+
validateLayout,
|
|
96
|
+
validateDesign,
|
|
97
|
+
summarizeIssues,
|
|
98
|
+
byteLength,
|
|
99
|
+
type LayoutIssue,
|
|
100
|
+
type LayoutValidation,
|
|
101
|
+
type DesignValidation,
|
|
102
|
+
} from "./validate.ts";
|
|
103
|
+
export {
|
|
104
|
+
DESIGN_SCHEMA_VERSION,
|
|
105
|
+
DEFAULT_STYLE_TAGS,
|
|
106
|
+
DesignSystem,
|
|
107
|
+
ColorVariable,
|
|
108
|
+
emptyDesign,
|
|
109
|
+
FontVariable,
|
|
110
|
+
LengthVariable,
|
|
111
|
+
type DefaultStyleTag,
|
|
112
|
+
} from "./schema/design.ts";
|
|
113
|
+
export {
|
|
114
|
+
findVariableUsages,
|
|
115
|
+
findVariableUsagesInDesign,
|
|
116
|
+
clearVariableRefs,
|
|
117
|
+
removeVariable,
|
|
118
|
+
renameVariable,
|
|
119
|
+
duplicateVariable,
|
|
120
|
+
deleteVariable,
|
|
121
|
+
refMatchesKind,
|
|
122
|
+
type VariableKind,
|
|
123
|
+
type VariableUsage,
|
|
124
|
+
} from "./design/variables.ts";
|
|
125
|
+
export { classStylesInListOrder, resolveCascade } from "./design/cascade.ts";
|
|
126
|
+
export {
|
|
127
|
+
findMissingRequiredFields,
|
|
128
|
+
layoutHasForm,
|
|
129
|
+
type MissingRequiredField,
|
|
130
|
+
} from "./forms/binding.ts";
|
|
131
|
+
export {
|
|
132
|
+
fieldsOf,
|
|
133
|
+
fieldByName,
|
|
134
|
+
type PublicFormDefinition,
|
|
135
|
+
type PublicFormField,
|
|
136
|
+
type FormDefinitions,
|
|
137
|
+
} from "./forms/definition.ts";
|
|
138
|
+
export { FORMS_SUBMIT_PATH } from "./render/index.ts";
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
moveClassId,
|
|
142
|
+
addClassId,
|
|
143
|
+
removeClassId,
|
|
144
|
+
findClassUsages,
|
|
145
|
+
clearClassRefs,
|
|
146
|
+
duplicateClass,
|
|
147
|
+
moveDesignClass,
|
|
148
|
+
renameClass,
|
|
149
|
+
patchClassStyle,
|
|
150
|
+
replaceClassId,
|
|
151
|
+
} from "./design/classes.ts";
|
|
152
|
+
export { hasStateStyles, patchClassState, patchStates } from "./design/states.ts";
|
|
153
|
+
export { designFromJson, designToJson, type DesignImport } from "./design/transfer.ts";
|
|
154
|
+
export {
|
|
155
|
+
patchClassDevices,
|
|
156
|
+
patchDeviceStyle,
|
|
157
|
+
toggleHidden,
|
|
158
|
+
type ResponsiveDevice,
|
|
159
|
+
} from "./design/devices.ts";
|
|
160
|
+
export {
|
|
161
|
+
renderPage,
|
|
162
|
+
type RenderMode,
|
|
163
|
+
type RenderResult,
|
|
164
|
+
type RenderWarning,
|
|
165
|
+
} from "./render/index.ts";
|
|
166
|
+
export { serialize, isAllowedTag, isAllowedAttr, type VNode } from "./render/vnode.ts";
|
|
167
|
+
export { escapeAttr, escapeText } from "./sanitize/escape.ts";
|
|
168
|
+
export { sanitizeHref } from "./sanitize/href.ts";
|
|
169
|
+
export { isSafeFontStack } from "./sanitize/css.ts";
|
|
170
|
+
export { sanitizeMediaUrl } from "./sanitize/media-url.ts";
|
|
171
|
+
export { sanitizeSvgMarkup, isSafeSvgMarkup } from "./sanitize/svg.ts";
|
|
172
|
+
export { resolveEmbedUrl, type EmbedTarget } from "./sanitize/embed-url.ts";
|
|
173
|
+
export { summarizeLayout, type LayoutSummary } from "./stats.ts";
|
|
174
|
+
export {
|
|
175
|
+
findNode,
|
|
176
|
+
updateNode,
|
|
177
|
+
removeNode,
|
|
178
|
+
insertNode,
|
|
179
|
+
nodeIdAtPath,
|
|
180
|
+
newNodeId,
|
|
181
|
+
starterLayout,
|
|
182
|
+
slugify,
|
|
183
|
+
type Removed,
|
|
184
|
+
} from "./tree-ops.ts";
|
|
185
|
+
export {
|
|
186
|
+
REASONS,
|
|
187
|
+
addNode,
|
|
188
|
+
canDrop,
|
|
189
|
+
duplicateNode,
|
|
190
|
+
firstChild,
|
|
191
|
+
insertionPoint,
|
|
192
|
+
moveDown,
|
|
193
|
+
moveIn,
|
|
194
|
+
moveNode,
|
|
195
|
+
moveOut,
|
|
196
|
+
moveUp,
|
|
197
|
+
nextInOrder,
|
|
198
|
+
parentOf,
|
|
199
|
+
previousInOrder,
|
|
200
|
+
selectionAfterDelete,
|
|
201
|
+
subtreeSize,
|
|
202
|
+
withFreshIds,
|
|
203
|
+
layoutFromPageTemplate,
|
|
204
|
+
type Allowed,
|
|
205
|
+
type Arranged,
|
|
206
|
+
type DragSource,
|
|
207
|
+
type Place,
|
|
208
|
+
type Refusal,
|
|
209
|
+
} from "./arrange.ts";
|
|
210
|
+
export {
|
|
211
|
+
BUNDLED_ICONS,
|
|
212
|
+
BUNDLED_ICON_IDS,
|
|
213
|
+
getBundledIcon,
|
|
214
|
+
type BundledIcon,
|
|
215
|
+
type IconPrimitive,
|
|
216
|
+
} from "./icons/catalog.ts";
|
|
217
|
+
|
|
218
|
+
export {
|
|
219
|
+
CONDITIONS_SCHEMA_VERSION,
|
|
220
|
+
MAX_CONDITION_RULES,
|
|
221
|
+
defaultConditions,
|
|
222
|
+
defaultConditionsFor,
|
|
223
|
+
validateConditions,
|
|
224
|
+
matchesConditions,
|
|
225
|
+
conditionSpecificity,
|
|
226
|
+
conditionsSpecificity,
|
|
227
|
+
themePartLocationApplies,
|
|
228
|
+
contentPartTypeForContext,
|
|
229
|
+
pickThemePartWinner,
|
|
230
|
+
listMatchingThemeParts,
|
|
231
|
+
type ConditionRule,
|
|
232
|
+
type ConditionsDoc,
|
|
233
|
+
type ConditionsValidation,
|
|
234
|
+
type ThemeRequestContext,
|
|
235
|
+
type ThemePartCandidate,
|
|
236
|
+
} from "./theme/conditions.ts";
|
|
237
|
+
|
|
238
|
+
export {
|
|
239
|
+
THEME_PART_TYPES,
|
|
240
|
+
CONTENT_THEME_PART_TYPES,
|
|
241
|
+
ITEM_THEME_PART_TYPES,
|
|
242
|
+
OVERLAY_THEME_PART_TYPES,
|
|
243
|
+
THEME_PART_TYPE_LABELS,
|
|
244
|
+
isThemePartType,
|
|
245
|
+
parseThemePartType,
|
|
246
|
+
isContentThemePartType,
|
|
247
|
+
isItemThemePartType,
|
|
248
|
+
isOverlayThemePartType,
|
|
249
|
+
type ThemePartType,
|
|
250
|
+
type ContentThemePartType,
|
|
251
|
+
type ItemThemePartType,
|
|
252
|
+
type OverlayThemePartType,
|
|
253
|
+
} from "./theme/part-types.ts";
|
|
254
|
+
|
|
255
|
+
export {
|
|
256
|
+
TRIGGERS_SCHEMA_VERSION,
|
|
257
|
+
MAX_POPUP_TRIGGERS,
|
|
258
|
+
defaultTriggers,
|
|
259
|
+
validateTriggers,
|
|
260
|
+
isSafeClickSelector,
|
|
261
|
+
type PopupOpenTrigger,
|
|
262
|
+
type PopupAdvancedRules,
|
|
263
|
+
type TriggersDoc,
|
|
264
|
+
type TriggersValidation,
|
|
265
|
+
} from "./theme/triggers.ts";
|
|
266
|
+
|
|
267
|
+
export {
|
|
268
|
+
TRIGGER_LIMITS,
|
|
269
|
+
clampScrollPercent,
|
|
270
|
+
deviceForWidth,
|
|
271
|
+
POPUP_DEVICES,
|
|
272
|
+
DEVICE_MEDIA,
|
|
273
|
+
DEVICE_PREVIEW_PX,
|
|
274
|
+
matchesPopupDevices,
|
|
275
|
+
withinShowTimes,
|
|
276
|
+
type PopupDevice,
|
|
277
|
+
} from "./theme/popup-rules.ts";
|
|
278
|
+
|
|
279
|
+
export { POPUP_CHROME_CSS, wrapPopupMarkup, type PopupPublicConfig } from "./theme/popup-markup.ts";
|
|
280
|
+
|
|
281
|
+
export {
|
|
282
|
+
SAMPLE_POST,
|
|
283
|
+
portableTextToVNodes,
|
|
284
|
+
collectLoopItemPartIds,
|
|
285
|
+
collectSectionPartIds,
|
|
286
|
+
resolvePostForRender,
|
|
287
|
+
resolvePostsForLoop,
|
|
288
|
+
type ThemePostFields,
|
|
289
|
+
type ThemeDynamicData,
|
|
290
|
+
} from "./theme/dynamic.ts";
|
|
291
|
+
|
|
292
|
+
export { layoutHasTabs } from "./tabs/presence.ts";
|
|
293
|
+
export {
|
|
294
|
+
CLIPBOARD_FORMAT,
|
|
295
|
+
CLIPBOARD_VERSION,
|
|
296
|
+
CLIP_REASONS,
|
|
297
|
+
applyStyle,
|
|
298
|
+
clipStyle,
|
|
299
|
+
droppedNotice,
|
|
300
|
+
elementClip,
|
|
301
|
+
encodeClip,
|
|
302
|
+
pasteNode,
|
|
303
|
+
pastePlace,
|
|
304
|
+
peekClipKind,
|
|
305
|
+
prepareElement,
|
|
306
|
+
prepareStyle,
|
|
307
|
+
readClip,
|
|
308
|
+
styleClip,
|
|
309
|
+
styleOf,
|
|
310
|
+
type Clip,
|
|
311
|
+
type ClipEnvelope,
|
|
312
|
+
type CopiedStyle,
|
|
313
|
+
type Dropped,
|
|
314
|
+
type PasteMode,
|
|
315
|
+
type ReadClip,
|
|
316
|
+
} from "./clipboard.ts";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Server-enforced budgets (N-005). Real D1 caps rows at 2 MB but local D1 doesn't (K12, S0-8). */
|
|
2
|
+
export const MAX_LAYOUT_BYTES = 512 * 1024;
|
|
3
|
+
/** Plugin storage compare-and-set fails above 1 MiB (S0-9); the design doc budget stays well below. */
|
|
4
|
+
export const MAX_DESIGN_BYTES = 256 * 1024;
|
|
5
|
+
export const MAX_DEPTH = 24;
|
|
6
|
+
export const MAX_NODES = 2000;
|
|
7
|
+
export const MAX_TEXT_LENGTH = 2000;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { LAYOUT_SCHEMA_VERSION } from "../schema/layout.ts";
|
|
2
|
+
|
|
3
|
+
export type Migration = (doc: Record<string, unknown>) => Record<string, unknown>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* v1 → v2 (D-031) marks the W-088 style keys as possible, v2 → v3 (D-032) the W-089
|
|
7
|
+
* `states` and `transition`, v3 → v4 (D-034) background images, gradients and overlays,
|
|
8
|
+
* v4 → v5 (D-036) per-device styles, v5 → v6 (D-038) synced sections,
|
|
9
|
+
* v6 → v7 (D-039) CSS Grid, v7 → v8 (D-041) entrance animations, and v8 → v9
|
|
10
|
+
* (D-042) attributes, accordion, richer entrances, post date and author, background video,
|
|
11
|
+
* a link on a box, and tag defaults. Every older value is valid in the newer version.
|
|
12
|
+
*/
|
|
13
|
+
const unchanged: Migration = (doc) => doc;
|
|
14
|
+
|
|
15
|
+
/** `LAYOUT_MIGRATIONS[n]` upgrades a version-n layout to version n + 1. Migrations must be pure. */
|
|
16
|
+
export const LAYOUT_MIGRATIONS: Readonly<Record<number, Migration>> = {
|
|
17
|
+
1: unchanged,
|
|
18
|
+
2: unchanged,
|
|
19
|
+
3: unchanged,
|
|
20
|
+
4: unchanged,
|
|
21
|
+
5: unchanged,
|
|
22
|
+
6: unchanged,
|
|
23
|
+
7: unchanged,
|
|
24
|
+
8: unchanged,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** `DESIGN_MIGRATIONS[n]` upgrades a version-n design document to version n + 1. */
|
|
28
|
+
export const DESIGN_MIGRATIONS: Readonly<Record<number, Migration>> = {
|
|
29
|
+
1: unchanged,
|
|
30
|
+
2: unchanged,
|
|
31
|
+
3: unchanged,
|
|
32
|
+
4: unchanged,
|
|
33
|
+
5: unchanged,
|
|
34
|
+
6: unchanged,
|
|
35
|
+
7: unchanged,
|
|
36
|
+
8: unchanged,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type UpgradeResult =
|
|
40
|
+
| { ok: true; doc: Record<string, unknown>; from: number }
|
|
41
|
+
| {
|
|
42
|
+
ok: false;
|
|
43
|
+
reason: "not-an-object" | "missing-version" | "newer-version" | "no-migration";
|
|
44
|
+
version?: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function versionOf(doc: unknown): number | undefined {
|
|
48
|
+
if (typeof doc !== "object" || doc === null) return undefined;
|
|
49
|
+
const v = (doc as { schemaVersion?: unknown }).schemaVersion;
|
|
50
|
+
return typeof v === "number" && Number.isInteger(v) && v >= 0 ? v : undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function isNewerThanSupported(doc: unknown, current = LAYOUT_SCHEMA_VERSION): boolean {
|
|
54
|
+
const v = versionOf(doc);
|
|
55
|
+
return v !== undefined && v > current;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Runs the migration chain up to `current`. Never mutates the input. */
|
|
59
|
+
export function upgradeLayout(
|
|
60
|
+
doc: unknown,
|
|
61
|
+
migrations: Readonly<Record<number, Migration>> = LAYOUT_MIGRATIONS,
|
|
62
|
+
current = LAYOUT_SCHEMA_VERSION,
|
|
63
|
+
): UpgradeResult {
|
|
64
|
+
if (typeof doc !== "object" || doc === null || Array.isArray(doc))
|
|
65
|
+
return { ok: false, reason: "not-an-object" };
|
|
66
|
+
const from = versionOf(doc);
|
|
67
|
+
if (from === undefined) return { ok: false, reason: "missing-version" };
|
|
68
|
+
if (from > current) return { ok: false, reason: "newer-version", version: from };
|
|
69
|
+
let result = structuredClone(doc) as Record<string, unknown>;
|
|
70
|
+
for (let v = from; v < current; v++) {
|
|
71
|
+
const step = migrations[v];
|
|
72
|
+
if (!step) return { ok: false, reason: "no-migration", version: v };
|
|
73
|
+
result = { ...step(result), schemaVersion: v + 1 };
|
|
74
|
+
}
|
|
75
|
+
return { ok: true, doc: result, from };
|
|
76
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FormDefinitions } from "../forms/definition.ts";
|
|
2
|
+
import type { LayoutNode } from "../schema/layout.ts";
|
|
3
|
+
import type { ThemeDynamicData } from "../theme/dynamic.ts";
|
|
4
|
+
import type { VNode } from "./vnode.ts";
|
|
5
|
+
|
|
6
|
+
export type RenderMode = "public" | "editor";
|
|
7
|
+
|
|
8
|
+
/** What the per-element renderers share with the page walk. */
|
|
9
|
+
export type RenderContext = {
|
|
10
|
+
mode: RenderMode;
|
|
11
|
+
definitions: FormDefinitions;
|
|
12
|
+
/** Renders child nodes against the given dynamic data, dropping those that render nothing. */
|
|
13
|
+
children: (nodes: LayoutNode[], dynamic: ThemeDynamicData | undefined) => VNode[];
|
|
14
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { LayoutNode } from "../schema/layout.ts";
|
|
2
|
+
import { sanitizeHref } from "../sanitize/href.ts";
|
|
3
|
+
import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
|
|
4
|
+
import { portableTextToVNodes, type ThemePostFields } from "../theme/dynamic.ts";
|
|
5
|
+
import type { RenderMode } from "./context.ts";
|
|
6
|
+
import type { VNode } from "./vnode.ts";
|
|
7
|
+
|
|
8
|
+
type Attrs = Record<string, string>;
|
|
9
|
+
|
|
10
|
+
type PostField = {
|
|
11
|
+
/** Shown in the editor when there is no post, or the post lacks this field; public pages show nothing. */
|
|
12
|
+
placeholder: (attrs: Attrs) => VNode;
|
|
13
|
+
/** Whether the post has this field; the placeholder stands in when it doesn't. */
|
|
14
|
+
has?: (post: ThemePostFields) => boolean;
|
|
15
|
+
/** The field's markup, or nothing when the post's value is empty or unsafe. */
|
|
16
|
+
render: (node: LayoutNode, attrs: Attrs, post: ThemePostFields) => VNode | undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"] as const;
|
|
20
|
+
|
|
21
|
+
const props = <T>(node: LayoutNode) => node.props as T;
|
|
22
|
+
|
|
23
|
+
const POST_FIELDS = new Map<string, PostField>([
|
|
24
|
+
[
|
|
25
|
+
"post-title",
|
|
26
|
+
{
|
|
27
|
+
placeholder: (attrs) => ({ tag: "h1", attrs, children: ["Post Title"] }),
|
|
28
|
+
render: (node, attrs, post) => {
|
|
29
|
+
const level = props<{ level?: number }>(node).level ?? 1;
|
|
30
|
+
const tag = HEADING_TAGS[Math.min(6, Math.max(1, level)) - 1] ?? "h1";
|
|
31
|
+
return { tag, attrs, children: [post.title] };
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
"post-excerpt",
|
|
37
|
+
{
|
|
38
|
+
placeholder: (attrs) => ({ tag: "p", attrs, children: ["Post excerpt…"] }),
|
|
39
|
+
render: (_node, attrs, post) =>
|
|
40
|
+
post.excerpt ? { tag: "p", attrs, children: [post.excerpt] } : undefined,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
"post-content",
|
|
45
|
+
{
|
|
46
|
+
placeholder: (attrs) => ({
|
|
47
|
+
tag: "div",
|
|
48
|
+
attrs,
|
|
49
|
+
children: [{ tag: "p", attrs: {}, children: ["Post content…"] }],
|
|
50
|
+
}),
|
|
51
|
+
render: (_node, attrs, post) => {
|
|
52
|
+
const blocks = portableTextToVNodes(post.content);
|
|
53
|
+
return blocks.length > 0 ? { tag: "div", attrs, children: blocks } : undefined;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
"post-image",
|
|
59
|
+
{
|
|
60
|
+
placeholder: (attrs) => ({
|
|
61
|
+
tag: "div",
|
|
62
|
+
attrs: { ...attrs, class: `${attrs.class ?? ""} emvb-post-image-missing`.trim() },
|
|
63
|
+
children: ["Featured image"],
|
|
64
|
+
}),
|
|
65
|
+
has: (post) => !!post.featuredImageUrl,
|
|
66
|
+
render: (node, attrs, post) => {
|
|
67
|
+
const src = sanitizeMediaUrl(post.featuredImageUrl ?? "");
|
|
68
|
+
if (!src) return undefined;
|
|
69
|
+
const alt = props<{ decorative?: boolean }>(node).decorative
|
|
70
|
+
? ""
|
|
71
|
+
: post.featuredImageAlt?.trim() || post.title || "Featured image";
|
|
72
|
+
return { tag: "img", attrs: { ...attrs, src, alt }, children: [] };
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
"post-link",
|
|
78
|
+
{
|
|
79
|
+
placeholder: (attrs) => ({
|
|
80
|
+
tag: "a",
|
|
81
|
+
attrs: { ...attrs, href: "#" },
|
|
82
|
+
children: ["Post link"],
|
|
83
|
+
}),
|
|
84
|
+
render: (node, attrs, post) => {
|
|
85
|
+
const href = sanitizeHref(post.permalink);
|
|
86
|
+
if (!href) return undefined;
|
|
87
|
+
const { text, newTab } = props<{ text?: string; newTab?: boolean }>(node);
|
|
88
|
+
const linkAttrs: Attrs = { ...attrs, href };
|
|
89
|
+
if (newTab) {
|
|
90
|
+
linkAttrs.target = "_blank";
|
|
91
|
+
linkAttrs.rel = "noopener noreferrer";
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
tag: "a",
|
|
95
|
+
attrs: linkAttrs,
|
|
96
|
+
children: [text?.trim() || post.title || post.permalink],
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
"post-date",
|
|
103
|
+
{
|
|
104
|
+
placeholder: (attrs) => ({ tag: "time", attrs, children: ["Post date"] }),
|
|
105
|
+
has: (post) => !!post.publishedAt?.trim(),
|
|
106
|
+
render: (_node, attrs, post) => {
|
|
107
|
+
const raw = post.publishedAt?.trim();
|
|
108
|
+
if (!raw) return undefined;
|
|
109
|
+
const parsed = Date.parse(raw);
|
|
110
|
+
const text = Number.isNaN(parsed)
|
|
111
|
+
? raw.slice(0, 80)
|
|
112
|
+
: new Intl.DateTimeFormat("en", { dateStyle: "medium", timeZone: "UTC" }).format(
|
|
113
|
+
new Date(parsed),
|
|
114
|
+
);
|
|
115
|
+
return { tag: "time", attrs: { ...attrs, datetime: raw.slice(0, 80) }, children: [text] };
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
[
|
|
120
|
+
"post-author",
|
|
121
|
+
{
|
|
122
|
+
placeholder: (attrs) => ({ tag: "span", attrs, children: ["Author"] }),
|
|
123
|
+
has: (post) => !!post.authorName?.trim(),
|
|
124
|
+
render: (_node, attrs, post) => {
|
|
125
|
+
const name = post.authorName?.trim();
|
|
126
|
+
return name ? { tag: "span", attrs, children: [name.slice(0, 200)] } : undefined;
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
]);
|
|
131
|
+
|
|
132
|
+
export const isDynamicPostNode = (node: LayoutNode) => POST_FIELDS.has(node.type);
|
|
133
|
+
|
|
134
|
+
/** A post field element: the post's value publicly, a placeholder in the editor when there is no post. */
|
|
135
|
+
export function renderDynamicPost(
|
|
136
|
+
node: LayoutNode,
|
|
137
|
+
attrs: Attrs,
|
|
138
|
+
post: ThemePostFields | undefined,
|
|
139
|
+
mode: RenderMode,
|
|
140
|
+
): VNode | undefined {
|
|
141
|
+
const field = POST_FIELDS.get(node.type);
|
|
142
|
+
if (!field) return undefined;
|
|
143
|
+
if (!post || field.has?.(post) === false) {
|
|
144
|
+
return mode === "editor" ? field.placeholder(attrs) : undefined;
|
|
145
|
+
}
|
|
146
|
+
return field.render(node, attrs, post);
|
|
147
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { LayoutNode } from "../schema/layout.ts";
|
|
2
|
+
import { sanitizeHref } from "../sanitize/href.ts";
|
|
3
|
+
import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
|
|
4
|
+
import type { VNode } from "./vnode.ts";
|
|
5
|
+
|
|
6
|
+
const ATTR_NAME = /^(?:data|aria)-[a-z][a-z0-9-]{0,40}$/;
|
|
7
|
+
const BOX = new Set(["container", "div-block", "flexbox", "grid"]);
|
|
8
|
+
|
|
9
|
+
/** `data-*` and `aria-*` from Advanced. `data-emvb-*` stays reserved for the editor. */
|
|
10
|
+
export function customAttributes(node: LayoutNode): Record<string, string> {
|
|
11
|
+
const list = node.attributes;
|
|
12
|
+
if (!list) return {};
|
|
13
|
+
const attrs: Record<string, string> = {};
|
|
14
|
+
const seen = new Set<string>();
|
|
15
|
+
for (const item of list) {
|
|
16
|
+
if (!ATTR_NAME.test(item.name) || item.name.startsWith("data-emvb")) continue;
|
|
17
|
+
if (seen.has(item.name) || item.value.length > 200) continue;
|
|
18
|
+
if ([...item.value].some((char) => char.charCodeAt(0) < 32)) continue;
|
|
19
|
+
seen.add(item.name);
|
|
20
|
+
attrs[item.name] = item.value;
|
|
21
|
+
}
|
|
22
|
+
return attrs;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function childrenOf(node: LayoutNode): LayoutNode[] {
|
|
26
|
+
return "children" in node && Array.isArray(node.children) ? node.children : [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A link, a button, or a box that is already a link. */
|
|
30
|
+
function containsInteractive(node: LayoutNode): boolean {
|
|
31
|
+
if (node.type === "link" || node.type === "post-link" || node.type === "button") return true;
|
|
32
|
+
if (BOX.has(node.type)) {
|
|
33
|
+
const href = (node.props as { href?: unknown }).href;
|
|
34
|
+
if (typeof href === "string" && href.trim()) return true;
|
|
35
|
+
}
|
|
36
|
+
return childrenOf(node).some(containsInteractive);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A div box becomes the link. A landmark tag stays a landmark. A link already inside the box
|
|
41
|
+
* keeps the box from becoming a link, so the page never nests anchors.
|
|
42
|
+
*/
|
|
43
|
+
export function applyBoxLink(node: LayoutNode, vnode: VNode): VNode {
|
|
44
|
+
if (!BOX.has(node.type) || vnode.tag !== "div") return vnode;
|
|
45
|
+
const { href, newTab } = node.props as { href?: string; newTab?: boolean };
|
|
46
|
+
if (!href?.trim()) return vnode;
|
|
47
|
+
if (childrenOf(node).some(containsInteractive)) return vnode;
|
|
48
|
+
const safe = sanitizeHref(href);
|
|
49
|
+
if (!safe) return vnode;
|
|
50
|
+
const attrs: Record<string, string> = { ...vnode.attrs, href: safe };
|
|
51
|
+
if (newTab) {
|
|
52
|
+
attrs.target = "_blank";
|
|
53
|
+
attrs.rel = "noopener noreferrer";
|
|
54
|
+
}
|
|
55
|
+
return { ...vnode, tag: "a", attrs };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function safeBackgroundVideo(url: string | undefined): string | undefined {
|
|
59
|
+
if (!url || /[()\\\s"'`]/.test(url)) return undefined;
|
|
60
|
+
return sanitizeMediaUrl(url) === url ? url : undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A muted, looping video behind the element's children. */
|
|
64
|
+
export function applyBackgroundVideo(vnode: VNode, src: string | undefined): VNode {
|
|
65
|
+
if (!src) return vnode;
|
|
66
|
+
const className = `${vnode.attrs.class ?? ""} emvb-has-bg-video`.trim();
|
|
67
|
+
return {
|
|
68
|
+
...vnode,
|
|
69
|
+
attrs: { ...vnode.attrs, class: className },
|
|
70
|
+
children: [
|
|
71
|
+
{
|
|
72
|
+
tag: "video",
|
|
73
|
+
attrs: { class: "emvb-bg-video", src, muted: "", loop: "", playsinline: "", autoplay: "" },
|
|
74
|
+
children: [],
|
|
75
|
+
},
|
|
76
|
+
...vnode.children,
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
}
|