@kardalum/plugin-sdk 0.0.0-stage → 0.15.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/CHANGELOG.md +108 -0
- package/LICENSE +202 -0
- package/README.md +70 -2
- package/dist/admin-section-registry.d.ts +34 -0
- package/dist/admin-section-registry.js +49 -0
- package/dist/built-in-serializers.d.ts +3 -0
- package/dist/built-in-serializers.js +18 -0
- package/dist/built-in-settings-schemas.d.ts +14 -0
- package/dist/built-in-settings-schemas.js +225 -0
- package/dist/built-in-value-schemas.d.ts +4 -0
- package/dist/built-in-value-schemas.js +47 -0
- package/dist/built-ins.d.ts +1 -0
- package/dist/built-ins.js +257 -0
- package/dist/capabilities.d.ts +99 -0
- package/dist/capabilities.js +363 -0
- package/dist/data-type-plugin.d.ts +28 -0
- package/dist/data-type-plugin.js +1 -0
- package/dist/datatype-validation.d.ts +26 -0
- package/dist/datatype-validation.js +110 -0
- package/dist/datatypes-entry.d.ts +4 -0
- package/dist/datatypes-entry.js +18 -0
- package/dist/define-plugin.d.ts +25 -0
- package/dist/define-plugin.js +51 -0
- package/dist/entitlement-entry.d.ts +5 -0
- package/dist/entitlement-entry.js +24 -0
- package/dist/entitlement-gate.d.ts +36 -0
- package/dist/entitlement-gate.js +201 -0
- package/dist/entitlement-types.d.ts +39 -0
- package/dist/entitlement-types.js +1 -0
- package/dist/entitlement.d.ts +57 -0
- package/dist/entitlement.js +170 -0
- package/dist/host-entry.d.ts +1 -0
- package/dist/host-entry.js +11 -0
- package/dist/icon-name.d.ts +1 -0
- package/dist/icon-name.js +1 -0
- package/dist/icons.d.ts +2 -0
- package/dist/icons.js +10 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +93 -0
- package/dist/license-verdict-keys.d.ts +18 -0
- package/dist/license-verdict-keys.js +22 -0
- package/dist/local-host.d.ts +3 -0
- package/dist/local-host.js +38 -0
- package/dist/manifest-entry.d.ts +8 -0
- package/dist/manifest-entry.js +13 -0
- package/dist/manifest-schema.d.ts +408 -0
- package/dist/manifest-schema.js +774 -0
- package/dist/manifest.d.ts +546 -0
- package/dist/manifest.js +86 -0
- package/dist/media/media-picker.d.ts +39 -0
- package/dist/media/media-picker.js +438 -0
- package/dist/media/upload-error.d.ts +12 -0
- package/dist/media/upload-error.js +30 -0
- package/dist/plugin-context.d.ts +75 -0
- package/dist/plugin-context.js +70 -0
- package/dist/plugin-screen-context.d.ts +40 -0
- package/dist/plugin-screen-context.js +16 -0
- package/dist/register-built-ins.d.ts +1 -0
- package/dist/register-built-ins.js +41 -0
- package/dist/registry.d.ts +4 -0
- package/dist/registry.js +17 -0
- package/dist/rendition-eligibility.d.ts +24 -0
- package/dist/rendition-eligibility.js +40 -0
- package/dist/richtext/block-panel.d.ts +27 -0
- package/dist/richtext/block-panel.js +232 -0
- package/dist/richtext/extensions.d.ts +19 -0
- package/dist/richtext/extensions.js +56 -0
- package/dist/richtext/insert-menu.d.ts +24 -0
- package/dist/richtext/insert-menu.js +142 -0
- package/dist/richtext/kardalum-block.d.ts +33 -0
- package/dist/richtext/kardalum-block.js +282 -0
- package/dist/richtext/style-listbox.d.ts +10 -0
- package/dist/richtext/style-listbox.js +69 -0
- package/dist/richtext/text-style-class.d.ts +18 -0
- package/dist/richtext/text-style-class.js +36 -0
- package/dist/simple-storage-value-provider.d.ts +9 -0
- package/dist/simple-storage-value-provider.js +96 -0
- package/dist/structured-storage-types.d.ts +61 -0
- package/dist/structured-storage-types.js +11 -0
- package/dist/tailwind.d.ts +1 -0
- package/dist/tailwind.js +5 -0
- package/dist/tokens/system-dark.css +75 -0
- package/dist/tokens/tokens.css +239 -0
- package/dist/tokens/tokens.json +212 -0
- package/dist/tokens.d.ts +1 -0
- package/dist/tokens.js +11 -0
- package/dist/ui-entry.d.ts +5 -0
- package/dist/ui-entry.js +42 -0
- package/dist/views/content-list-preview.d.ts +1 -0
- package/dist/views/content-list-preview.js +14 -0
- package/dist/views/content-list-settings-view.d.ts +1 -0
- package/dist/views/content-list-settings-view.js +97 -0
- package/dist/views/content-list-view.d.ts +19 -0
- package/dist/views/content-list-view.js +248 -0
- package/dist/views/crop-view.d.ts +55 -0
- package/dist/views/crop-view.js +161 -0
- package/dist/views/date-range-view.d.ts +6 -0
- package/dist/views/date-range-view.js +55 -0
- package/dist/views/file-upload-view.d.ts +43 -0
- package/dist/views/file-upload-view.js +104 -0
- package/dist/views/html-code-editor.d.ts +10 -0
- package/dist/views/html-code-editor.js +101 -0
- package/dist/views/html-view.d.ts +3 -0
- package/dist/views/html-view.js +53 -0
- package/dist/views/image-view.d.ts +3 -0
- package/dist/views/image-view.js +387 -0
- package/dist/views/rich-text-view.d.ts +2 -0
- package/dist/views/rich-text-view.js +429 -0
- package/node_modules/@kardalum/api-schemas/LICENSE +202 -0
- package/node_modules/@kardalum/api-schemas/README.md +56 -0
- package/node_modules/@kardalum/api-schemas/dist/action.schema.d.ts +30 -0
- package/node_modules/@kardalum/api-schemas/dist/action.schema.js +88 -0
- package/node_modules/@kardalum/api-schemas/dist/api-error.schema.d.ts +5 -0
- package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +6 -0
- package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.d.ts +75 -0
- package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.js +36 -0
- package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.d.ts +89 -0
- package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +60 -0
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +24 -0
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +47 -0
- package/node_modules/@kardalum/api-schemas/dist/auth.schema.d.ts +38 -0
- package/node_modules/@kardalum/api-schemas/dist/auth.schema.js +38 -0
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +537 -0
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +353 -0
- package/node_modules/@kardalum/api-schemas/dist/content-list.schema.d.ts +158 -0
- package/node_modules/@kardalum/api-schemas/dist/content-list.schema.js +139 -0
- package/node_modules/@kardalum/api-schemas/dist/content-path.d.ts +125 -0
- package/node_modules/@kardalum/api-schemas/dist/content-path.js +256 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.d.ts +20 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +23 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.d.ts +151 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +82 -0
- package/node_modules/@kardalum/api-schemas/dist/content-version.schema.d.ts +18 -0
- package/node_modules/@kardalum/api-schemas/dist/content-version.schema.js +22 -0
- package/node_modules/@kardalum/api-schemas/dist/content.schema.d.ts +17 -0
- package/node_modules/@kardalum/api-schemas/dist/content.schema.js +20 -0
- package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +302 -0
- package/node_modules/@kardalum/api-schemas/dist/core-actions.js +97 -0
- package/node_modules/@kardalum/api-schemas/dist/culture-direction.d.ts +1 -0
- package/node_modules/@kardalum/api-schemas/dist/culture-direction.js +9 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +36 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.js +32 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.d.ts +9 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.js +32 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +296 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +138 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type.schema.d.ts +121 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type.schema.js +147 -0
- package/node_modules/@kardalum/api-schemas/dist/health.schema.d.ts +6 -0
- package/node_modules/@kardalum/api-schemas/dist/health.schema.js +5 -0
- package/node_modules/@kardalum/api-schemas/dist/html-entities.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/html-entities.js +250 -0
- package/node_modules/@kardalum/api-schemas/dist/index.d.ts +102 -0
- package/node_modules/@kardalum/api-schemas/dist/index.js +58 -0
- package/node_modules/@kardalum/api-schemas/dist/licensing.schema.d.ts +15 -0
- package/node_modules/@kardalum/api-schemas/dist/licensing.schema.js +14 -0
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +381 -0
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +197 -0
- package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +167 -0
- package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +214 -0
- package/node_modules/@kardalum/api-schemas/dist/media-reference-api.schema.d.ts +77 -0
- package/node_modules/@kardalum/api-schemas/dist/media-reference-api.schema.js +53 -0
- package/node_modules/@kardalum/api-schemas/dist/media-reference-use.d.ts +75 -0
- package/node_modules/@kardalum/api-schemas/dist/media-reference-use.js +117 -0
- package/node_modules/@kardalum/api-schemas/dist/media-reference.d.ts +27 -0
- package/node_modules/@kardalum/api-schemas/dist/media-reference.js +279 -0
- package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.d.ts +74 -0
- package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.js +157 -0
- package/node_modules/@kardalum/api-schemas/dist/media.schema.d.ts +80 -0
- package/node_modules/@kardalum/api-schemas/dist/media.schema.js +156 -0
- package/node_modules/@kardalum/api-schemas/dist/nav.schema.d.ts +23 -0
- package/node_modules/@kardalum/api-schemas/dist/nav.schema.js +55 -0
- package/node_modules/@kardalum/api-schemas/dist/node-access.schema.d.ts +846 -0
- package/node_modules/@kardalum/api-schemas/dist/node-access.schema.js +356 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.d.ts +20 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.js +27 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +169 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +80 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.d.ts +65 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.js +889 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +89 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +134 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.d.ts +31 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.js +38 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +369 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +393 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +22 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +87 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.d.ts +31 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +25 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.d.ts +15 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.js +24 -0
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +306 -0
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +328 -0
- package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +79 -0
- package/node_modules/@kardalum/api-schemas/dist/render-editing.js +50 -0
- package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.d.ts +9 -0
- package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.js +13 -0
- package/node_modules/@kardalum/api-schemas/dist/reserved-slugs.d.ts +2 -0
- package/node_modules/@kardalum/api-schemas/dist/reserved-slugs.js +16 -0
- package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +90 -0
- package/node_modules/@kardalum/api-schemas/dist/role.schema.js +69 -0
- package/node_modules/@kardalum/api-schemas/dist/sample-content-outcome.schema.d.ts +17 -0
- package/node_modules/@kardalum/api-schemas/dist/sample-content-outcome.schema.js +27 -0
- package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +108 -0
- package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +93 -0
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +243 -0
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +296 -0
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +43 -0
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +25 -0
- package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +30 -0
- package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.js +19 -0
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +112 -0
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +74 -0
- package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +41 -0
- package/node_modules/@kardalum/api-schemas/dist/template.schema.js +39 -0
- package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.d.ts +21 -0
- package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.js +14 -0
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +89 -0
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +68 -0
- package/node_modules/@kardalum/api-schemas/package.json +35 -0
- package/node_modules/@kardalum/design-tokens/LICENSE +202 -0
- package/node_modules/@kardalum/design-tokens/README.md +29 -0
- package/node_modules/@kardalum/design-tokens/dist/build-css.d.ts +32 -0
- package/node_modules/@kardalum/design-tokens/dist/build-css.js +88 -0
- package/node_modules/@kardalum/design-tokens/dist/generate.d.ts +1 -0
- package/node_modules/@kardalum/design-tokens/dist/generate.js +18 -0
- package/node_modules/@kardalum/design-tokens/dist/index.d.ts +6 -0
- package/node_modules/@kardalum/design-tokens/dist/index.js +4 -0
- package/node_modules/@kardalum/design-tokens/dist/system-dark.css +75 -0
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +33 -0
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.js +54 -0
- package/node_modules/@kardalum/design-tokens/dist/theme-css.d.ts +12 -0
- package/node_modules/@kardalum/design-tokens/dist/theme-css.js +42 -0
- package/node_modules/@kardalum/design-tokens/dist/theme-types.d.ts +43 -0
- package/node_modules/@kardalum/design-tokens/dist/theme-types.js +1 -0
- package/node_modules/@kardalum/design-tokens/dist/themes/dark.d.ts +13 -0
- package/node_modules/@kardalum/design-tokens/dist/themes/dark.js +120 -0
- package/node_modules/@kardalum/design-tokens/dist/themes/index.d.ts +5 -0
- package/node_modules/@kardalum/design-tokens/dist/themes/index.js +4 -0
- package/node_modules/@kardalum/design-tokens/dist/themes/light.d.ts +9 -0
- package/node_modules/@kardalum/design-tokens/dist/themes/light.js +13 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.css +239 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.d.ts +25 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.js +276 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.json +212 -0
- package/node_modules/@kardalum/design-tokens/dist/types.d.ts +91 -0
- package/node_modules/@kardalum/design-tokens/dist/types.js +5 -0
- package/node_modules/@kardalum/design-tokens/package.json +42 -0
- package/node_modules/@kardalum/plugin-package/LICENSE +202 -0
- package/node_modules/@kardalum/plugin-package/README.md +71 -0
- package/node_modules/@kardalum/plugin-package/dist/docs-contract.d.ts +50 -0
- package/node_modules/@kardalum/plugin-package/dist/docs-contract.js +659 -0
- package/node_modules/@kardalum/plugin-package/dist/envelope.d.ts +19 -0
- package/node_modules/@kardalum/plugin-package/dist/envelope.js +104 -0
- package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +37 -0
- package/node_modules/@kardalum/plugin-package/dist/extract.js +199 -0
- package/node_modules/@kardalum/plugin-package/dist/hash.d.ts +17 -0
- package/node_modules/@kardalum/plugin-package/dist/hash.js +69 -0
- package/node_modules/@kardalum/plugin-package/dist/index.d.ts +11 -0
- package/node_modules/@kardalum/plugin-package/dist/index.js +7 -0
- package/node_modules/@kardalum/plugin-package/dist/license-verdict.d.ts +185 -0
- package/node_modules/@kardalum/plugin-package/dist/license-verdict.js +236 -0
- package/node_modules/@kardalum/plugin-package/dist/package-contract.d.ts +50 -0
- package/node_modules/@kardalum/plugin-package/dist/package-contract.js +115 -0
- package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +1 -0
- package/node_modules/@kardalum/plugin-package/dist/sample-content.js +17 -0
- package/node_modules/@kardalum/plugin-package/dist/types.d.ts +45 -0
- package/node_modules/@kardalum/plugin-package/dist/types.js +1 -0
- package/node_modules/@kardalum/plugin-package/package.json +49 -0
- package/node_modules/@kardalum/ui/LICENSE +202 -0
- package/node_modules/@kardalum/ui/README.md +35 -0
- package/node_modules/@kardalum/ui/dist/components/alert-dialog.d.ts +14 -0
- package/node_modules/@kardalum/ui/dist/components/alert-dialog.js +38 -0
- package/node_modules/@kardalum/ui/dist/components/badge.d.ts +9 -0
- package/node_modules/@kardalum/ui/dist/components/badge.js +30 -0
- package/node_modules/@kardalum/ui/dist/components/button.d.ts +11 -0
- package/node_modules/@kardalum/ui/dist/components/button.js +37 -0
- package/node_modules/@kardalum/ui/dist/components/checkbox.d.ts +5 -0
- package/node_modules/@kardalum/ui/dist/components/checkbox.js +7 -0
- package/node_modules/@kardalum/ui/dist/components/dialog.d.ts +17 -0
- package/node_modules/@kardalum/ui/dist/components/dialog.js +48 -0
- package/node_modules/@kardalum/ui/dist/components/dropdown-menu.d.ts +18 -0
- package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +53 -0
- package/node_modules/@kardalum/ui/dist/components/empty-state.d.ts +30 -0
- package/node_modules/@kardalum/ui/dist/components/empty-state.js +9 -0
- package/node_modules/@kardalum/ui/dist/components/input.d.ts +4 -0
- package/node_modules/@kardalum/ui/dist/components/input.js +6 -0
- package/node_modules/@kardalum/ui/dist/components/panel.d.ts +5 -0
- package/node_modules/@kardalum/ui/dist/components/panel.js +6 -0
- package/node_modules/@kardalum/ui/dist/components/property-field.d.ts +19 -0
- package/node_modules/@kardalum/ui/dist/components/property-field.js +86 -0
- package/node_modules/@kardalum/ui/dist/components/sheet.d.ts +17 -0
- package/node_modules/@kardalum/ui/dist/components/sheet.js +55 -0
- package/node_modules/@kardalum/ui/dist/components/skeleton.d.ts +3 -0
- package/node_modules/@kardalum/ui/dist/components/skeleton.js +9 -0
- package/node_modules/@kardalum/ui/dist/components/switch.d.ts +5 -0
- package/node_modules/@kardalum/ui/dist/components/switch.js +7 -0
- package/node_modules/@kardalum/ui/dist/components/tab-strip.d.ts +34 -0
- package/node_modules/@kardalum/ui/dist/components/tab-strip.js +72 -0
- package/node_modules/@kardalum/ui/dist/components/toast.d.ts +18 -0
- package/node_modules/@kardalum/ui/dist/components/toast.js +42 -0
- package/node_modules/@kardalum/ui/dist/components/toaster.d.ts +12 -0
- package/node_modules/@kardalum/ui/dist/components/toaster.js +11 -0
- package/node_modules/@kardalum/ui/dist/components/use-toast.d.ts +17 -0
- package/node_modules/@kardalum/ui/dist/components/use-toast.js +62 -0
- package/node_modules/@kardalum/ui/dist/index.d.ts +18 -0
- package/node_modules/@kardalum/ui/dist/index.js +18 -0
- package/node_modules/@kardalum/ui/dist/lib/cn.d.ts +2 -0
- package/node_modules/@kardalum/ui/dist/lib/cn.js +5 -0
- package/node_modules/@kardalum/ui/package.json +63 -0
- package/package.json +146 -4
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { cn } from "@kardalum/ui";
|
|
4
|
+
import { usePluginApi } from "../plugin-context.js";
|
|
5
|
+
// The value a freshly inserted block's params start with, before the user
|
|
6
|
+
// has touched anything in the param panel (S197 Task 3 brief, "Inserting a
|
|
7
|
+
// block": defaults: text/textarea "", number 0, boolean false, image
|
|
8
|
+
// null, choice first option).
|
|
9
|
+
export function defaultBlockParams(params) {
|
|
10
|
+
const defaults = {};
|
|
11
|
+
for (const param of params) {
|
|
12
|
+
switch (param.type) {
|
|
13
|
+
case "text":
|
|
14
|
+
case "textarea":
|
|
15
|
+
defaults[param.key] = "";
|
|
16
|
+
break;
|
|
17
|
+
case "number":
|
|
18
|
+
defaults[param.key] = 0;
|
|
19
|
+
break;
|
|
20
|
+
case "boolean":
|
|
21
|
+
defaults[param.key] = false;
|
|
22
|
+
break;
|
|
23
|
+
case "image":
|
|
24
|
+
defaults[param.key] = null;
|
|
25
|
+
break;
|
|
26
|
+
case "choice":
|
|
27
|
+
defaults[param.key] = param.options?.[0] ?? "";
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return defaults;
|
|
32
|
+
}
|
|
33
|
+
// GET /api/render/blocks (S197 Task 6 ships this endpoint — until then
|
|
34
|
+
// every call 404s, and this hook surfaces that as `error`, same as
|
|
35
|
+
// MediaPicker's own fetch-failure handling, rather than swallowing it into
|
|
36
|
+
// a silent empty list). Shared between the insert menu (BlockInsertMenu,
|
|
37
|
+
// below) and the param panel (block-panel.tsx needs the same declared
|
|
38
|
+
// param specs + labels to render fields for a block already in the
|
|
39
|
+
// document) — one fetch shape, not forked per consumer.
|
|
40
|
+
export function useBlockListings() {
|
|
41
|
+
const fetchApi = usePluginApi();
|
|
42
|
+
const [listings, setListings] = useState([]);
|
|
43
|
+
const [loading, setLoading] = useState(true);
|
|
44
|
+
const [error, setError] = useState(null);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
let cancelled = false;
|
|
47
|
+
setLoading(true);
|
|
48
|
+
setError(null);
|
|
49
|
+
fetchApi("/api/render/blocks")
|
|
50
|
+
.then(async (response) => {
|
|
51
|
+
if (!response.ok)
|
|
52
|
+
throw new Error(`Failed to load blocks (${response.status})`);
|
|
53
|
+
const body = await response.json();
|
|
54
|
+
if (!cancelled)
|
|
55
|
+
setListings(Array.isArray(body) ? body : []);
|
|
56
|
+
})
|
|
57
|
+
.catch((err) => {
|
|
58
|
+
if (!cancelled)
|
|
59
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
60
|
+
})
|
|
61
|
+
.finally(() => {
|
|
62
|
+
if (!cancelled)
|
|
63
|
+
setLoading(false);
|
|
64
|
+
});
|
|
65
|
+
return () => {
|
|
66
|
+
cancelled = true;
|
|
67
|
+
};
|
|
68
|
+
}, [fetchApi]);
|
|
69
|
+
return { listings, loading, error };
|
|
70
|
+
}
|
|
71
|
+
// The toolbar's "◫ Block ▾" popover body (S197 mockup screen 2, "Blocks —
|
|
72
|
+
// from your templates" section): an ARIA listbox, same single-select
|
|
73
|
+
// pattern as StyleListbox (rich-text-view.tsx): roving tabindex,
|
|
74
|
+
// Arrow/Home/End move focus, Enter/Space commits, Escape closes.
|
|
75
|
+
//
|
|
76
|
+
// Screen 2's mockup also shows Image/Quote/Table rows above the blocks
|
|
77
|
+
// list, but those are already reachable from this editor's own toolbar
|
|
78
|
+
// (the "🖼 Image" button, the "❝" blockquote button) or out of scope (no
|
|
79
|
+
// Table extension exists yet) — this menu covers only what "◫ Block ▾" is
|
|
80
|
+
// for: inserting a template-declared block.
|
|
81
|
+
export function BlockInsertMenu({ onInsert, onClose }) {
|
|
82
|
+
const { listings, loading, error } = useBlockListings();
|
|
83
|
+
const [activeIndex, setActiveIndex] = useState(0);
|
|
84
|
+
const optionRefs = useRef([]);
|
|
85
|
+
if (loading) {
|
|
86
|
+
return (_jsx("div", { role: "listbox", "aria-label": "Blocks", className: "min-w-64 p-2 text-xs text-text-secondary", children: "Loading\u2026" }));
|
|
87
|
+
}
|
|
88
|
+
if (error) {
|
|
89
|
+
return (_jsx("div", { role: "listbox", "aria-label": "Blocks", className: "min-w-64 p-2 text-xs text-danger-600", children: error }));
|
|
90
|
+
}
|
|
91
|
+
if (listings.length === 0) {
|
|
92
|
+
return (_jsx("div", { role: "listbox", "aria-label": "Blocks", className: "min-w-64 p-2 text-xs text-text-secondary", children: "No blocks declared by your templates yet." }));
|
|
93
|
+
}
|
|
94
|
+
function focusIndex(index) {
|
|
95
|
+
setActiveIndex(index);
|
|
96
|
+
optionRefs.current[index]?.focus();
|
|
97
|
+
}
|
|
98
|
+
function commit(index) {
|
|
99
|
+
const listing = listings[index];
|
|
100
|
+
if (!listing)
|
|
101
|
+
return;
|
|
102
|
+
onInsert(listing);
|
|
103
|
+
onClose();
|
|
104
|
+
}
|
|
105
|
+
function handleKeyDown(event) {
|
|
106
|
+
switch (event.key) {
|
|
107
|
+
case "ArrowDown":
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
focusIndex((activeIndex + 1) % listings.length);
|
|
110
|
+
return;
|
|
111
|
+
case "ArrowUp":
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
focusIndex((activeIndex - 1 + listings.length) % listings.length);
|
|
114
|
+
return;
|
|
115
|
+
case "Home":
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
focusIndex(0);
|
|
118
|
+
return;
|
|
119
|
+
case "End":
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
focusIndex(listings.length - 1);
|
|
122
|
+
return;
|
|
123
|
+
case "Enter":
|
|
124
|
+
case " ":
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
commit(activeIndex);
|
|
127
|
+
return;
|
|
128
|
+
case "Escape":
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
onClose();
|
|
131
|
+
return;
|
|
132
|
+
default:
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return (_jsxs("div", { role: "listbox", "aria-label": "Blocks", onKeyDown: handleKeyDown, className: "min-w-64 p-1", children: [_jsx("div", { className: "px-2 py-1 text-xs font-semibold text-text-tertiary", children: "Blocks: from your templates" }), listings.map((listing, index) => {
|
|
137
|
+
const selected = index === activeIndex;
|
|
138
|
+
return (_jsxs("div", { ref: (el) => {
|
|
139
|
+
optionRefs.current[index] = el;
|
|
140
|
+
}, role: "option", "aria-selected": selected, tabIndex: selected ? 0 : -1, onFocus: () => setActiveIndex(index), onClick: () => commit(index), className: cn("flex cursor-pointer items-start gap-2 rounded-sm px-2 py-1.5 text-sm outline-none", "focus-visible:ring-2 focus-visible:ring-primary-600", selected ? "bg-primary-100" : "text-text-primary hover:bg-background-hover"), children: [_jsx("span", { "aria-hidden": "true", className: "mt-0.5 text-text-secondary", children: "\u25EB" }), _jsxs("span", { className: "flex flex-col", children: [_jsx("span", { className: "font-medium text-text-primary", children: listing.name }), _jsxs("span", { className: "text-xs text-text-secondary", children: [listing.alias, ".liquid", listing.params.length > 0 ? ` · ${listing.params.map((param) => param.key).join(", ")}` : ""] })] })] }, listing.alias));
|
|
141
|
+
})] }));
|
|
142
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Node, type Editor } from "@tiptap/core";
|
|
2
|
+
export interface KardalumBlockOptions {
|
|
3
|
+
HTMLAttributes: Record<string, unknown>;
|
|
4
|
+
}
|
|
5
|
+
export interface KardalumBlockAttributes {
|
|
6
|
+
partial: string;
|
|
7
|
+
params: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
declare module "@tiptap/core" {
|
|
10
|
+
interface Commands<ReturnType> {
|
|
11
|
+
kardalumBlock: {
|
|
12
|
+
/** Insert a block node referencing a template partial + its params. */
|
|
13
|
+
insertKardalumBlock: (attrs: KardalumBlockAttributes) => ReturnType;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export declare const KardalumBlock: Node<KardalumBlockOptions, any>;
|
|
18
|
+
export interface SelectedKardalumBlock {
|
|
19
|
+
pos: number;
|
|
20
|
+
partial: string;
|
|
21
|
+
params: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
export declare function selectedKardalumBlock(editor: Editor): SelectedKardalumBlock | null;
|
|
24
|
+
export interface KardalumBlockLocation {
|
|
25
|
+
pos: number;
|
|
26
|
+
partial: string;
|
|
27
|
+
params: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export declare function findKardalumBlocks(editor: Editor): KardalumBlockLocation[];
|
|
30
|
+
export declare function setBlockHtml(editor: Editor, pos: number, html: string): void;
|
|
31
|
+
export declare function moveSelectionPastBlock(editor: Editor, pos: number): void;
|
|
32
|
+
export declare function unavailableBlockHtml(reason: string): string;
|
|
33
|
+
export declare const KardalumBlockOnPage: Node<KardalumBlockOptions, any>;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { Node, mergeAttributes } from "@tiptap/core";
|
|
2
|
+
import { NodeSelection, Selection } from "@tiptap/pm/state";
|
|
3
|
+
export const KardalumBlock = Node.create({
|
|
4
|
+
name: "kardalumBlock",
|
|
5
|
+
group: "block",
|
|
6
|
+
atom: true,
|
|
7
|
+
selectable: true,
|
|
8
|
+
draggable: false,
|
|
9
|
+
addOptions() {
|
|
10
|
+
return { HTMLAttributes: {} };
|
|
11
|
+
},
|
|
12
|
+
addAttributes() {
|
|
13
|
+
return {
|
|
14
|
+
partial: {
|
|
15
|
+
default: "",
|
|
16
|
+
// The shell attribute is `data-kardalum-block`, not a bare `partial`
|
|
17
|
+
// — parse/render both go through that one attribute so the two
|
|
18
|
+
// never drift apart.
|
|
19
|
+
parseHTML: (element) => element.getAttribute("data-kardalum-block") ?? "",
|
|
20
|
+
renderHTML: () => ({}),
|
|
21
|
+
},
|
|
22
|
+
params: {
|
|
23
|
+
default: {},
|
|
24
|
+
parseHTML: (element) => {
|
|
25
|
+
const raw = element.getAttribute("data-params");
|
|
26
|
+
if (!raw)
|
|
27
|
+
return {};
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(raw);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
renderHTML: (attributes) => ({ "data-params": JSON.stringify(attributes.params ?? {}) }),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
parseHTML() {
|
|
40
|
+
return [{ tag: "div[data-kardalum-block]" }];
|
|
41
|
+
},
|
|
42
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
43
|
+
// No content hole: this is an atom/leaf node (no `content` expression),
|
|
44
|
+
// and ProseMirror's DOMSerializer rejects a `0` hole on a leaf spec.
|
|
45
|
+
return [
|
|
46
|
+
"div",
|
|
47
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
|
|
48
|
+
"data-kardalum-block": node.attrs.partial,
|
|
49
|
+
}),
|
|
50
|
+
];
|
|
51
|
+
},
|
|
52
|
+
addCommands() {
|
|
53
|
+
return {
|
|
54
|
+
insertKardalumBlock: (attrs) => ({ commands }) => commands.insertContent({ type: this.name, attrs }),
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
addNodeView() {
|
|
58
|
+
return ({ node, view, getPos }) => {
|
|
59
|
+
// Reassigned in `update` below so the preview button always reads
|
|
60
|
+
// the block's CURRENT params (the param panel writes them back via
|
|
61
|
+
// updateAttributes — this closure must not keep serving the params
|
|
62
|
+
// it was constructed with).
|
|
63
|
+
let currentNode = node;
|
|
64
|
+
const dom = document.createElement("div");
|
|
65
|
+
dom.setAttribute("data-kardalum-block", node.attrs.partial);
|
|
66
|
+
// No contentDOM: this is a leaf/atom view. contentEditable=false stops
|
|
67
|
+
// the browser from placing a caret or accepting stray keystrokes
|
|
68
|
+
// inside the chip's own markup.
|
|
69
|
+
dom.contentEditable = "false";
|
|
70
|
+
dom.className =
|
|
71
|
+
"flex items-center gap-2 rounded-md border border-dashed border-border-default bg-background-subtle " +
|
|
72
|
+
"px-3 py-2 my-3 text-xs text-text-secondary";
|
|
73
|
+
// A click anywhere on the chip (other than "preview", which stops
|
|
74
|
+
// its own mousedown below) drops a NodeSelection here explicitly —
|
|
75
|
+
// dispatched straight from the position this view already knows via
|
|
76
|
+
// getPos(), rather than counting on ProseMirror's own coordinate-based
|
|
77
|
+
// click-to-select for a leaf. The form-view mount (rich-text-view.tsx)
|
|
78
|
+
// renders its param panel directly off that selection.
|
|
79
|
+
dom.addEventListener("mousedown", () => {
|
|
80
|
+
const pos = typeof getPos === "function" ? getPos() : undefined;
|
|
81
|
+
if (typeof pos !== "number")
|
|
82
|
+
return;
|
|
83
|
+
view.dispatch(view.state.tr.setSelection(NodeSelection.create(view.state.doc, pos)));
|
|
84
|
+
});
|
|
85
|
+
const icon = document.createElement("span");
|
|
86
|
+
icon.textContent = "◫";
|
|
87
|
+
icon.setAttribute("aria-hidden", "true");
|
|
88
|
+
const label = document.createElement("b");
|
|
89
|
+
label.className = "font-semibold text-text-primary";
|
|
90
|
+
label.textContent = node.attrs.partial || "Block";
|
|
91
|
+
const preview = document.createElement("button");
|
|
92
|
+
preview.type = "button";
|
|
93
|
+
preview.className = "ms-auto text-primary-700 hover:underline";
|
|
94
|
+
preview.textContent = "preview ⤢";
|
|
95
|
+
// mousedown (not just click) must stop here, BEFORE ProseMirror's own
|
|
96
|
+
// mousedown listener on the editable root sees it (bubble phase,
|
|
97
|
+
// target-first) — otherwise clicking "preview" would also drop a
|
|
98
|
+
// NodeSelection on this block and pop the param panel at the same
|
|
99
|
+
// time, when the mockup treats preview and "open settings" as two
|
|
100
|
+
// separate affordances.
|
|
101
|
+
preview.addEventListener("mousedown", (event) => event.stopPropagation());
|
|
102
|
+
preview.addEventListener("click", (event) => {
|
|
103
|
+
event.stopPropagation();
|
|
104
|
+
// Plain DOM APIs only (this view has no React tree of its own —
|
|
105
|
+
// see the file-level doc comment) — a bubbling CustomEvent is how
|
|
106
|
+
// the mount that DOES have React (rich-text-view.tsx's fetchApi,
|
|
107
|
+
// its popover state) hears about the request. Any mount can listen
|
|
108
|
+
// for "kardalum:preview-block" the same way, vanilla or not.
|
|
109
|
+
dom.dispatchEvent(new CustomEvent("kardalum:preview-block", {
|
|
110
|
+
bubbles: true,
|
|
111
|
+
detail: {
|
|
112
|
+
partial: currentNode.attrs.partial,
|
|
113
|
+
params: currentNode.attrs.params ?? {},
|
|
114
|
+
anchor: preview,
|
|
115
|
+
},
|
|
116
|
+
}));
|
|
117
|
+
});
|
|
118
|
+
dom.append(icon, label, preview);
|
|
119
|
+
return {
|
|
120
|
+
dom,
|
|
121
|
+
update: (updatedNode) => {
|
|
122
|
+
if (updatedNode.type.name !== node.type.name)
|
|
123
|
+
return false;
|
|
124
|
+
currentNode = updatedNode;
|
|
125
|
+
dom.setAttribute("data-kardalum-block", updatedNode.attrs.partial);
|
|
126
|
+
label.textContent = updatedNode.attrs.partial || "Block";
|
|
127
|
+
return true;
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
export function selectedKardalumBlock(editor) {
|
|
134
|
+
const { selection } = editor.state;
|
|
135
|
+
if (!(selection instanceof NodeSelection) || selection.node.type.name !== "kardalumBlock")
|
|
136
|
+
return null;
|
|
137
|
+
return {
|
|
138
|
+
pos: selection.from,
|
|
139
|
+
partial: selection.node.attrs.partial ?? "",
|
|
140
|
+
params: selection.node.attrs.params ?? {},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export function findKardalumBlocks(editor) {
|
|
144
|
+
const found = [];
|
|
145
|
+
editor.state.doc.descendants((node, pos) => {
|
|
146
|
+
if (node.type.name === "kardalumBlock") {
|
|
147
|
+
found.push({
|
|
148
|
+
pos,
|
|
149
|
+
partial: node.attrs.partial ?? "",
|
|
150
|
+
params: node.attrs.params ?? {},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
});
|
|
155
|
+
return found;
|
|
156
|
+
}
|
|
157
|
+
// Patches a single on-page block's rendered content WITHOUT touching node
|
|
158
|
+
// attrs — html is never stored in content (S197 spec §8), this only updates
|
|
159
|
+
// the NodeView's own DOM. A no-op if `pos` doesn't currently resolve to a
|
|
160
|
+
// mounted on-page NodeView (the block may have been removed or the editor
|
|
161
|
+
// destroyed between when the caller read `pos`/started its fetch and this
|
|
162
|
+
// call landing — a real race an async fetch can hit, not defensive-for-its-
|
|
163
|
+
// own-sake).
|
|
164
|
+
export function setBlockHtml(editor, pos, html) {
|
|
165
|
+
if (editor.isDestroyed)
|
|
166
|
+
return;
|
|
167
|
+
let dom;
|
|
168
|
+
try {
|
|
169
|
+
dom = editor.view.nodeDOM(pos);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const handle = dom?.__kardalumSetBlockHtml;
|
|
175
|
+
if (typeof handle === "function")
|
|
176
|
+
handle(html);
|
|
177
|
+
}
|
|
178
|
+
function escapeHtml(value) {
|
|
179
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
180
|
+
}
|
|
181
|
+
// Moves the selection to just past a block at `pos` (Task 12's on-page
|
|
182
|
+
// panel Done/Remove/Escape actions — mirrors block-panel.tsx's own
|
|
183
|
+
// moveSelectionPastBlock exactly, centralized here so BOTH mounts share one
|
|
184
|
+
// implementation). Selection.near, not a direct setTextSelection: when the
|
|
185
|
+
// block is the document's only content, the position just past it doesn't
|
|
186
|
+
// resolve into any inline content at all, and TipTap's setTextSelection
|
|
187
|
+
// constructs an unreliable TextSelection there regardless (ProseMirror
|
|
188
|
+
// warns) — Selection.near finds the nearest position that's actually valid.
|
|
189
|
+
export function moveSelectionPastBlock(editor, pos) {
|
|
190
|
+
if (editor.isDestroyed)
|
|
191
|
+
return;
|
|
192
|
+
const size = editor.state.doc.nodeAt(pos)?.nodeSize ?? 1;
|
|
193
|
+
const next = Math.min(pos + size, editor.state.doc.content.size);
|
|
194
|
+
editor
|
|
195
|
+
.chain()
|
|
196
|
+
.focus()
|
|
197
|
+
.command(({ tr, dispatch }) => {
|
|
198
|
+
if (dispatch)
|
|
199
|
+
tr.setSelection(Selection.near(tr.doc.resolve(next)));
|
|
200
|
+
return true;
|
|
201
|
+
})
|
|
202
|
+
.run();
|
|
203
|
+
}
|
|
204
|
+
// The on-page warning state (spec: a block whose params/partial fail server-
|
|
205
|
+
// side validation renders as an HTML comment on the public page and "the
|
|
206
|
+
// admin editor shows the same state as a warning chip") — fed into
|
|
207
|
+
// setBlockHtml the same way a successful render's HTML is, so the NodeView
|
|
208
|
+
// itself needs no separate notion of "unavailable," only "here is the
|
|
209
|
+
// content to show."
|
|
210
|
+
export function unavailableBlockHtml(reason) {
|
|
211
|
+
return `<div class="kardalum-block-unavailable" role="alert">Block unavailable: ${escapeHtml(reason)}</div>`;
|
|
212
|
+
}
|
|
213
|
+
// The on-page render mode (S197 Task 12): extends the form-view chip's node
|
|
214
|
+
// definition unchanged (same name/attrs/parseHTML/renderHTML — a document
|
|
215
|
+
// authored in one mount round-trips through the other with no data loss,
|
|
216
|
+
// per the brief's "ONE source of truth for the node schema"), overriding
|
|
217
|
+
// only addNodeView. Where the chip shows an icon + partial name + a preview
|
|
218
|
+
// affordance (there is no page here to render INTO), this NodeView shows the
|
|
219
|
+
// block's actual fetched HTML directly in the page — initially empty until
|
|
220
|
+
// the caller (apps/admin-ui's BlockOverlay) fetches it and calls
|
|
221
|
+
// setBlockHtml. Selecting it (click-to-open-panel, same mousedown-dispatched
|
|
222
|
+
// NodeSelection idiom as the chip) is surfaced visually via the NodeView
|
|
223
|
+
// lifecycle's own selectNode/deselectNode hooks (ProseMirror calls these
|
|
224
|
+
// automatically for a selectable atom — the chip doesn't need them since it
|
|
225
|
+
// has no visual "selected" state of its own beyond the panel opening).
|
|
226
|
+
export const KardalumBlockOnPage = KardalumBlock.extend({
|
|
227
|
+
name: "kardalumBlock",
|
|
228
|
+
addNodeView() {
|
|
229
|
+
return ({ node, view, getPos }) => {
|
|
230
|
+
const dom = document.createElement("div");
|
|
231
|
+
dom.setAttribute("data-kardalum-block", node.attrs.partial);
|
|
232
|
+
dom.className = "kardalum-block-onpage";
|
|
233
|
+
// No contentDOM: this is a leaf/atom view, same as the chip.
|
|
234
|
+
// contentEditable=false stops the browser from placing a caret or
|
|
235
|
+
// accepting stray keystrokes inside the block's own rendered markup.
|
|
236
|
+
dom.contentEditable = "false";
|
|
237
|
+
const content = document.createElement("div");
|
|
238
|
+
content.className = "kardalum-block-onpage-content";
|
|
239
|
+
dom.appendChild(content);
|
|
240
|
+
dom.__kardalumSetBlockHtml = (html) => {
|
|
241
|
+
content.innerHTML = html;
|
|
242
|
+
};
|
|
243
|
+
// Blocks are atomic in edit mode (this file's own top comment: "a
|
|
244
|
+
// block's internals are the template's, not the editor's, to edit") —
|
|
245
|
+
// a click anywhere on the rendered HTML (including a real <a>/<button>
|
|
246
|
+
// the template itself emits) opens the settings panel instead of
|
|
247
|
+
// acting like a normal page. `click` is captured (not just mousedown)
|
|
248
|
+
// specifically to preventDefault a real link's navigation, which
|
|
249
|
+
// mousedown alone can't stop.
|
|
250
|
+
dom.addEventListener("click", (event) => {
|
|
251
|
+
event.preventDefault();
|
|
252
|
+
event.stopPropagation();
|
|
253
|
+
});
|
|
254
|
+
dom.addEventListener("mousedown", () => {
|
|
255
|
+
const pos = typeof getPos === "function" ? getPos() : undefined;
|
|
256
|
+
if (typeof pos !== "number")
|
|
257
|
+
return;
|
|
258
|
+
view.dispatch(view.state.tr.setSelection(NodeSelection.create(view.state.doc, pos)));
|
|
259
|
+
});
|
|
260
|
+
return {
|
|
261
|
+
dom,
|
|
262
|
+
// ProseMirror calls these automatically for a selectable atom node
|
|
263
|
+
// whenever its own NodeSelection is set/cleared — the mockup's
|
|
264
|
+
// dashed (hover) vs solid (active/selected) outline is driven by
|
|
265
|
+
// this class from CSS (edit-mode.css), not by re-deriving selection
|
|
266
|
+
// state by hand on every transaction.
|
|
267
|
+
selectNode() {
|
|
268
|
+
dom.classList.add("kardalum-block-onpage-active");
|
|
269
|
+
},
|
|
270
|
+
deselectNode() {
|
|
271
|
+
dom.classList.remove("kardalum-block-onpage-active");
|
|
272
|
+
},
|
|
273
|
+
update: (updatedNode) => {
|
|
274
|
+
if (updatedNode.type.name !== node.type.name)
|
|
275
|
+
return false;
|
|
276
|
+
dom.setAttribute("data-kardalum-block", updatedNode.attrs.partial);
|
|
277
|
+
return true;
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RichtextTextStyle } from "./extensions.js";
|
|
2
|
+
export interface StyleListboxProps {
|
|
3
|
+
styles: RichtextTextStyle[];
|
|
4
|
+
loading: boolean;
|
|
5
|
+
activeStyleKey: string | null;
|
|
6
|
+
onSelect: (styleKey: string) => void;
|
|
7
|
+
onClear: () => void;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function StyleListbox({ styles, loading, activeStyleKey, onSelect, onClear, onClose }: StyleListboxProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useRef, useState } from "react";
|
|
3
|
+
import { cn } from "@kardalum/ui";
|
|
4
|
+
// The Aa Style dropdown's popover body: a proper ARIA listbox (role
|
|
5
|
+
// listbox/option), not a menu — it's a single-select "pick one" widget,
|
|
6
|
+
// same pattern as IconPickerDialog's grid (roving tabindex, Arrow/Home/End,
|
|
7
|
+
// Enter/Space commits).
|
|
8
|
+
export function StyleListbox({ styles, loading, activeStyleKey, onSelect, onClear, onClose }) {
|
|
9
|
+
const options = useMemo(() => [...styles.map((style) => ({ kind: "style", style })), { kind: "clear" }], [styles]);
|
|
10
|
+
const [activeIndex, setActiveIndex] = useState(0);
|
|
11
|
+
const optionRefs = useRef([]);
|
|
12
|
+
if (loading) {
|
|
13
|
+
return (_jsx("div", { role: "listbox", "aria-label": "Text styles", className: "min-w-40 p-2 text-xs text-text-secondary", children: "Loading\u2026" }));
|
|
14
|
+
}
|
|
15
|
+
if (styles.length === 0) {
|
|
16
|
+
return (_jsx("div", { role: "listbox", "aria-label": "Text styles", className: "min-w-40 p-2 text-xs text-text-secondary", children: "No theme styles declared" }));
|
|
17
|
+
}
|
|
18
|
+
function focusIndex(index) {
|
|
19
|
+
setActiveIndex(index);
|
|
20
|
+
optionRefs.current[index]?.focus();
|
|
21
|
+
}
|
|
22
|
+
function commit(index) {
|
|
23
|
+
const option = options[index];
|
|
24
|
+
if (!option)
|
|
25
|
+
return;
|
|
26
|
+
if (option.kind === "clear")
|
|
27
|
+
onClear();
|
|
28
|
+
else
|
|
29
|
+
onSelect(option.style.key);
|
|
30
|
+
onClose();
|
|
31
|
+
}
|
|
32
|
+
function handleKeyDown(event) {
|
|
33
|
+
switch (event.key) {
|
|
34
|
+
case "ArrowDown":
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
focusIndex((activeIndex + 1) % options.length);
|
|
37
|
+
return;
|
|
38
|
+
case "ArrowUp":
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
focusIndex((activeIndex - 1 + options.length) % options.length);
|
|
41
|
+
return;
|
|
42
|
+
case "Home":
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
focusIndex(0);
|
|
45
|
+
return;
|
|
46
|
+
case "End":
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
focusIndex(options.length - 1);
|
|
49
|
+
return;
|
|
50
|
+
case "Enter":
|
|
51
|
+
case " ":
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
commit(activeIndex);
|
|
54
|
+
return;
|
|
55
|
+
case "Escape":
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
onClose();
|
|
58
|
+
return;
|
|
59
|
+
default:
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return (_jsx("div", { role: "listbox", "aria-label": "Text styles", onKeyDown: handleKeyDown, className: "min-w-40 p-1", children: options.map((option, index) => {
|
|
64
|
+
const selected = option.kind === "style" && option.style.key === activeStyleKey;
|
|
65
|
+
return (_jsx("div", { ref: (el) => {
|
|
66
|
+
optionRefs.current[index] = el;
|
|
67
|
+
}, role: "option", "aria-selected": selected, tabIndex: index === activeIndex ? 0 : -1, onFocus: () => setActiveIndex(index), onClick: () => commit(index), className: cn("cursor-pointer rounded-sm px-2 py-1.5 text-sm outline-none", "focus-visible:ring-2 focus-visible:ring-primary-600", selected ? "bg-primary-100 text-primary-800" : "text-text-primary hover:bg-background-hover", option.kind === "clear" && "mt-1 border-t border-border-default pt-1.5 text-text-secondary"), children: option.kind === "style" ? option.style.label : "Clear style" }, option.kind === "style" ? option.style.key : "__clear__"));
|
|
68
|
+
}) }));
|
|
69
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Mark } from "@tiptap/core";
|
|
2
|
+
export interface TextStyleClassOptions {
|
|
3
|
+
HTMLAttributes: Record<string, unknown>;
|
|
4
|
+
}
|
|
5
|
+
export interface TextStyleClassAttributes {
|
|
6
|
+
styleKey: string;
|
|
7
|
+
}
|
|
8
|
+
declare module "@tiptap/core" {
|
|
9
|
+
interface Commands<ReturnType> {
|
|
10
|
+
textStyleClass: {
|
|
11
|
+
/** Apply the named style `rt-<styleKey>` to the current selection. */
|
|
12
|
+
setTextStyle: (styleKey: string) => ReturnType;
|
|
13
|
+
/** Remove any named style from the current selection. */
|
|
14
|
+
unsetTextStyle: () => ReturnType;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export declare const TextStyleClass: Mark<TextStyleClassOptions, any>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Mark, mergeAttributes } from "@tiptap/core";
|
|
2
|
+
const STYLE_KEY_PATTERN = /(?:^|\s)rt-(\S+)/;
|
|
3
|
+
export const TextStyleClass = Mark.create({
|
|
4
|
+
name: "textStyleClass",
|
|
5
|
+
addOptions() {
|
|
6
|
+
return { HTMLAttributes: {} };
|
|
7
|
+
},
|
|
8
|
+
addAttributes() {
|
|
9
|
+
return {
|
|
10
|
+
styleKey: {
|
|
11
|
+
default: null,
|
|
12
|
+
// The class carries the value — nothing to read from a bare
|
|
13
|
+
// attribute, and nothing to render as one (see renderHTML below,
|
|
14
|
+
// which builds the class directly from mark.attrs.styleKey).
|
|
15
|
+
parseHTML: (element) => STYLE_KEY_PATTERN.exec(element.getAttribute("class") ?? "")?.[1] ?? null,
|
|
16
|
+
renderHTML: () => ({}),
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
parseHTML() {
|
|
21
|
+
return [{ tag: 'span[class^="rt-"]' }];
|
|
22
|
+
},
|
|
23
|
+
renderHTML({ mark, HTMLAttributes }) {
|
|
24
|
+
return [
|
|
25
|
+
"span",
|
|
26
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { class: `rt-${mark.attrs.styleKey}` }),
|
|
27
|
+
0,
|
|
28
|
+
];
|
|
29
|
+
},
|
|
30
|
+
addCommands() {
|
|
31
|
+
return {
|
|
32
|
+
setTextStyle: (styleKey) => ({ commands }) => commands.setMark(this.name, { styleKey }),
|
|
33
|
+
unsetTextStyle: () => ({ commands }) => commands.unsetMark(this.name),
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
interface SimpleStorageValueProviderProps {
|
|
3
|
+
contentId: string;
|
|
4
|
+
fieldId: string;
|
|
5
|
+
pluginId: string;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare function SimpleStorageValueProvider({ contentId, fieldId, pluginId, children, }: SimpleStorageValueProviderProps): import("react").JSX.Element;
|
|
9
|
+
export {};
|