emdash 0.8.0 → 0.9.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/dist/{adapters-BKSf3T9R.d.mts → adapters-DoNJiveC.d.mts} +1 -1
- package/dist/{adapters-BKSf3T9R.d.mts.map → adapters-DoNJiveC.d.mts.map} +1 -1
- package/dist/{apply-x0eMK1lX.mjs → apply-BzltprvY.mjs} +85 -135
- package/dist/apply-BzltprvY.mjs.map +1 -0
- package/dist/astro/index.d.mts +6 -6
- package/dist/astro/index.d.mts.map +1 -1
- package/dist/astro/index.mjs +110 -4
- package/dist/astro/index.mjs.map +1 -1
- package/dist/astro/middleware/auth.d.mts +6 -7
- package/dist/astro/middleware/auth.d.mts.map +1 -1
- package/dist/astro/middleware/auth.mjs +16 -59
- package/dist/astro/middleware/auth.mjs.map +1 -1
- package/dist/astro/middleware/redirect.d.mts.map +1 -1
- package/dist/astro/middleware/redirect.mjs +17 -12
- package/dist/astro/middleware/redirect.mjs.map +1 -1
- package/dist/astro/middleware/request-context.d.mts.map +1 -1
- package/dist/astro/middleware/request-context.mjs +9 -6
- package/dist/astro/middleware/request-context.mjs.map +1 -1
- package/dist/astro/middleware/setup.mjs +1 -1
- package/dist/astro/middleware.d.mts.map +1 -1
- package/dist/astro/middleware.mjs +72 -124
- package/dist/astro/middleware.mjs.map +1 -1
- package/dist/astro/types.d.mts +26 -10
- package/dist/astro/types.d.mts.map +1 -1
- package/dist/{base64-MBPo9ozB.mjs → base64-BRICGH2l.mjs} +1 -1
- package/dist/{base64-MBPo9ozB.mjs.map → base64-BRICGH2l.mjs.map} +1 -1
- package/dist/{byline-Chbr2GoP.mjs → byline-BSaNL1w7.mjs} +4 -4
- package/dist/{byline-Chbr2GoP.mjs.map → byline-BSaNL1w7.mjs.map} +1 -1
- package/dist/bylines-CvJ3PYz2.mjs +113 -0
- package/dist/bylines-CvJ3PYz2.mjs.map +1 -0
- package/dist/cache-C6N_hhN7.mjs +65 -0
- package/dist/cache-C6N_hhN7.mjs.map +1 -0
- package/dist/{chunks-HGz06Soa.mjs → chunks-NBQVDOci.mjs} +8 -2
- package/dist/{chunks-HGz06Soa.mjs.map → chunks-NBQVDOci.mjs.map} +1 -1
- package/dist/cli/index.mjs +224 -30
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/cf-access.d.mts +1 -1
- package/dist/client/index.d.mts +1 -1
- package/dist/client/index.mjs +3 -3
- package/dist/client/index.mjs.map +1 -1
- package/dist/{config-BXwuX8Bx.mjs → config-BI0V3ICQ.mjs} +1 -1
- package/dist/{config-BXwuX8Bx.mjs.map → config-BI0V3ICQ.mjs.map} +1 -1
- package/dist/{content-BcQPYxdV.mjs → content-8lOYF0pr.mjs} +32 -15
- package/dist/{content-BcQPYxdV.mjs.map → content-8lOYF0pr.mjs.map} +1 -1
- package/dist/db/index.d.mts +3 -3
- package/dist/db/index.mjs +2 -2
- package/dist/db/libsql.d.mts +1 -1
- package/dist/db/libsql.d.mts.map +1 -1
- package/dist/db/libsql.mjs +7 -2
- package/dist/db/libsql.mjs.map +1 -1
- package/dist/db/postgres.d.mts +1 -1
- package/dist/db/sqlite.d.mts +1 -1
- package/dist/db/sqlite.d.mts.map +1 -1
- package/dist/db/sqlite.mjs +8 -3
- package/dist/db/sqlite.mjs.map +1 -1
- package/dist/{db-errors-l1Qh2RPR.mjs → db-errors-WRezodiz.mjs} +1 -1
- package/dist/{db-errors-l1Qh2RPR.mjs.map → db-errors-WRezodiz.mjs.map} +1 -1
- package/dist/{default-DCVqE5ib.mjs → default-D8ksjWhO.mjs} +1 -1
- package/dist/{default-DCVqE5ib.mjs.map → default-D8ksjWhO.mjs.map} +1 -1
- package/dist/{dialect-helpers-DhTzaUxP.mjs → dialect-helpers-BKCvISIQ.mjs} +19 -2
- package/dist/dialect-helpers-BKCvISIQ.mjs.map +1 -0
- package/dist/{error-zG5T1UGA.mjs → error-D_-tqP-I.mjs} +1 -1
- package/dist/{error-zG5T1UGA.mjs.map → error-D_-tqP-I.mjs.map} +1 -1
- package/dist/{index-DIb-CzNx.d.mts → index-BFRaVcD6.d.mts} +94 -34
- package/dist/index-BFRaVcD6.d.mts.map +1 -0
- package/dist/index.d.mts +11 -11
- package/dist/index.mjs +29 -27
- package/dist/{load-CyEoextb.mjs → load-DDqMMvZL.mjs} +2 -2
- package/dist/{load-CyEoextb.mjs.map → load-DDqMMvZL.mjs.map} +1 -1
- package/dist/{loader-CndGj8kM.mjs → loader-CKLbBnhK.mjs} +27 -7
- package/dist/loader-CKLbBnhK.mjs.map +1 -0
- package/dist/{manifest-schema-DH9xhc6t.mjs → manifest-schema-DqWNC3lM.mjs} +33 -3
- package/dist/manifest-schema-DqWNC3lM.mjs.map +1 -0
- package/dist/media/index.d.mts +1 -1
- package/dist/media/index.mjs +1 -1
- package/dist/media/local-runtime.d.mts +7 -7
- package/dist/media/local-runtime.mjs +3 -3
- package/dist/{media-D8FbNsl0.mjs → media-BW32b4gi.mjs} +2 -2
- package/dist/{media-D8FbNsl0.mjs.map → media-BW32b4gi.mjs.map} +1 -1
- package/dist/{mode-BnAOqItE.mjs → mode-ier8jbBk.mjs} +1 -1
- package/dist/{mode-BnAOqItE.mjs.map → mode-ier8jbBk.mjs.map} +1 -1
- package/dist/options-BVp3UsTS.mjs +117 -0
- package/dist/options-BVp3UsTS.mjs.map +1 -0
- package/dist/page/index.d.mts +2 -2
- package/dist/{placeholder-D29tWZ7o.d.mts → placeholder-BE4o_2dc.d.mts} +1 -1
- package/dist/{placeholder-D29tWZ7o.d.mts.map → placeholder-BE4o_2dc.d.mts.map} +1 -1
- package/dist/{placeholder-C-fk5hYI.mjs → placeholder-CIJejMlK.mjs} +1 -1
- package/dist/{placeholder-C-fk5hYI.mjs.map → placeholder-CIJejMlK.mjs.map} +1 -1
- package/dist/plugins/adapt-sandbox-entry.d.mts +5 -5
- package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -1
- package/dist/plugins/adapt-sandbox-entry.mjs +6 -5
- package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -1
- package/dist/public-url-DByxYjUw.mjs +51 -0
- package/dist/public-url-DByxYjUw.mjs.map +1 -0
- package/dist/{query-fqEdLFms.mjs → query-Cg9ZKRQ0.mjs} +114 -16
- package/dist/query-Cg9ZKRQ0.mjs.map +1 -0
- package/dist/{redirect-D_pshWdf.mjs → redirect-BhUBKRc1.mjs} +11 -6
- package/dist/redirect-BhUBKRc1.mjs.map +1 -0
- package/dist/{registry-C3Mr0ODu.mjs → registry-Dw70ChxB.mjs} +38 -4
- package/dist/registry-Dw70ChxB.mjs.map +1 -0
- package/dist/{request-cache-Ci7f5pBb.mjs → request-cache-B-bmkipQ.mjs} +1 -1
- package/dist/{request-cache-Ci7f5pBb.mjs.map → request-cache-B-bmkipQ.mjs.map} +1 -1
- package/dist/runner-Bnoj7vjK.d.mts +44 -0
- package/dist/runner-Bnoj7vjK.d.mts.map +1 -0
- package/dist/{runner-tQ7BJ4T7.mjs → runner-C7ADox5q.mjs} +185 -55
- package/dist/{runner-tQ7BJ4T7.mjs.map → runner-C7ADox5q.mjs.map} +1 -1
- package/dist/runtime.d.mts +6 -6
- package/dist/runtime.mjs +4 -4
- package/dist/{search-BoZYFuUk.mjs → search-dOGEccMa.mjs} +129 -83
- package/dist/search-dOGEccMa.mjs.map +1 -0
- package/dist/secrets-CW3reAnU.mjs +314 -0
- package/dist/secrets-CW3reAnU.mjs.map +1 -0
- package/dist/seed/index.d.mts +2 -2
- package/dist/seed/index.mjs +15 -14
- package/dist/seo/index.d.mts +1 -1
- package/dist/storage/local.d.mts +1 -1
- package/dist/storage/local.mjs +1 -1
- package/dist/storage/s3.d.mts +1 -1
- package/dist/storage/s3.mjs +1 -1
- package/dist/{taxonomies-B4IAshV8.mjs → taxonomies-ZlRtD6AG.mjs} +14 -7
- package/dist/taxonomies-ZlRtD6AG.mjs.map +1 -0
- package/dist/{tokens-D9vnZqYS.mjs → tokens-D7zMmWi2.mjs} +2 -2
- package/dist/{tokens-D9vnZqYS.mjs.map → tokens-D7zMmWi2.mjs.map} +1 -1
- package/dist/{transport-C9ugt2Nr.mjs → transport-BeMCmin1.mjs} +6 -5
- package/dist/{transport-C9ugt2Nr.mjs.map → transport-BeMCmin1.mjs.map} +1 -1
- package/dist/{transport-CUnEL3Vs.d.mts → transport-DNEfeMaU.d.mts} +1 -1
- package/dist/{transport-CUnEL3Vs.d.mts.map → transport-DNEfeMaU.d.mts.map} +1 -1
- package/dist/types-4fVtCIm0.mjs +68 -0
- package/dist/types-4fVtCIm0.mjs.map +1 -0
- package/dist/{types-BmPPSUEx.d.mts → types-BSyXeCFW.d.mts} +24 -2
- package/dist/{types-BmPPSUEx.d.mts.map → types-BSyXeCFW.d.mts.map} +1 -1
- package/dist/{types-i36XcA_X.d.mts → types-BuBIptGk.d.mts} +65 -134
- package/dist/types-BuBIptGk.d.mts.map +1 -0
- package/dist/{types-CgqmmMJB.mjs → types-CDbKp7ND.mjs} +1 -1
- package/dist/{types-CgqmmMJB.mjs.map → types-CDbKp7ND.mjs.map} +1 -1
- package/dist/{types-Bm1dn-q3.mjs → types-CIOg5AR8.mjs} +1 -1
- package/dist/{types-Bm1dn-q3.mjs.map → types-CIOg5AR8.mjs.map} +1 -1
- package/dist/{types-BrA0xf5I.d.mts → types-CJsYGpco.d.mts} +1 -1
- package/dist/{types-BrA0xf5I.d.mts.map → types-CJsYGpco.d.mts.map} +1 -1
- package/dist/{types-BIgulNsW.mjs → types-CRxNbK-Z.mjs} +2 -2
- package/dist/{types-BIgulNsW.mjs.map → types-CRxNbK-Z.mjs.map} +1 -1
- package/dist/{types-CS8FIX7L.d.mts → types-CrtWgIvl.d.mts} +1 -1
- package/dist/{types-CS8FIX7L.d.mts.map → types-CrtWgIvl.d.mts.map} +1 -1
- package/dist/{types-DIMwPFub.d.mts → types-M78DQ1lx.d.mts} +1 -1
- package/dist/{types-DIMwPFub.d.mts.map → types-M78DQ1lx.d.mts.map} +1 -1
- package/dist/{validate-CxVsLehf.mjs → validate-Baqf0slj.mjs} +3 -3
- package/dist/{validate-CxVsLehf.mjs.map → validate-Baqf0slj.mjs.map} +1 -1
- package/dist/{validate-DHxmpFJt.d.mts → validate-BfQh_C_y.d.mts} +4 -4
- package/dist/{validate-DHxmpFJt.d.mts.map → validate-BfQh_C_y.d.mts.map} +1 -1
- package/dist/{validation-C-ZpN2GI.mjs → validation-BfEI7tNe.mjs} +6 -6
- package/dist/{validation-C-ZpN2GI.mjs.map → validation-BfEI7tNe.mjs.map} +1 -1
- package/dist/version-DoxrVdYf.mjs +7 -0
- package/dist/{version-Bbq8TCrz.mjs.map → version-DoxrVdYf.mjs.map} +1 -1
- package/dist/{zod-generator-CpwccCIv.mjs → zod-generator-CC0xNe_K.mjs} +4 -4
- package/dist/zod-generator-CC0xNe_K.mjs.map +1 -0
- package/locals.d.ts +1 -6
- package/package.json +9 -8
- package/src/api/handlers/comments.ts +6 -4
- package/src/api/handlers/content.ts +29 -1
- package/src/api/handlers/device-flow.ts +5 -0
- package/src/api/handlers/marketplace.ts +11 -4
- package/src/api/handlers/oauth-authorization.ts +72 -33
- package/src/api/handlers/revision.ts +23 -14
- package/src/api/handlers/taxonomies.ts +3 -6
- package/src/api/public-url.ts +48 -2
- package/src/api/schemas/comments.ts +2 -2
- package/src/api/schemas/content.ts +17 -0
- package/src/api/schemas/sections.ts +3 -3
- package/src/api/schemas/users.ts +1 -1
- package/src/api/types.ts +5 -1
- package/src/astro/integration/index.ts +17 -0
- package/src/astro/integration/runtime.ts +30 -0
- package/src/astro/integration/virtual-modules.ts +32 -2
- package/src/astro/integration/vite-config.ts +6 -1
- package/src/astro/middleware/auth.ts +13 -6
- package/src/astro/middleware/redirect.ts +29 -16
- package/src/astro/middleware/request-context.ts +15 -5
- package/src/astro/middleware.ts +23 -9
- package/src/astro/routes/api/auth/invite/complete.ts +6 -1
- package/src/astro/routes/api/auth/passkey/register/verify.ts +6 -1
- package/src/astro/routes/api/auth/passkey/verify.ts +6 -1
- package/src/astro/routes/api/auth/signup/complete.ts +6 -1
- package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +2 -2
- package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +4 -2
- package/src/astro/routes/api/content/[collection]/[id]/preview-url.ts +34 -12
- package/src/astro/routes/api/content/[collection]/[id]/publish.ts +32 -2
- package/src/astro/routes/api/content/[collection]/[id]/restore.ts +4 -2
- package/src/astro/routes/api/content/[collection]/[id]/revisions.ts +3 -2
- package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +8 -4
- package/src/astro/routes/api/content/[collection]/[id].ts +12 -0
- package/src/astro/routes/api/import/wordpress/execute.ts +3 -1
- package/src/astro/routes/api/import/wordpress/prepare.ts +7 -8
- package/src/astro/routes/api/import/wordpress-plugin/execute.ts +3 -1
- package/src/astro/routes/api/manifest.ts +62 -45
- package/src/astro/routes/api/media/[id]/confirm.ts +10 -1
- package/src/astro/routes/api/media/providers/[providerId]/index.ts +12 -3
- package/src/astro/routes/api/openapi.json.ts +27 -10
- package/src/astro/routes/api/redirects/404s/index.ts +10 -4
- package/src/astro/routes/api/redirects/404s/summary.ts +4 -2
- package/src/astro/routes/api/redirects/[id].ts +10 -4
- package/src/astro/routes/api/redirects/index.ts +7 -3
- package/src/astro/routes/api/revisions/[revisionId]/index.ts +1 -1
- package/src/astro/routes/api/schema/collections/[slug]/fields/[fieldSlug].ts +0 -2
- package/src/astro/routes/api/schema/collections/[slug]/fields/index.ts +0 -1
- package/src/astro/routes/api/schema/collections/[slug]/fields/reorder.ts +0 -1
- package/src/astro/routes/api/schema/collections/[slug]/index.ts +2 -2
- package/src/astro/routes/api/schema/collections/index.ts +1 -1
- package/src/astro/routes/api/search/index.ts +10 -2
- package/src/astro/routes/api/sections/[slug].ts +10 -4
- package/src/astro/routes/api/sections/index.ts +7 -3
- package/src/astro/routes/api/setup/admin-verify.ts +6 -1
- package/src/astro/routes/api/snapshot.ts +44 -18
- package/src/astro/routes/api/taxonomies/index.ts +0 -1
- package/src/astro/routes/api/themes/preview.ts +11 -5
- package/src/astro/types.ts +23 -3
- package/src/auth/allowed-origins.ts +168 -0
- package/src/auth/passkey-config.ts +35 -13
- package/src/bylines/index.ts +37 -88
- package/src/cli/commands/auth.ts +28 -6
- package/src/cli/commands/bundle-utils.ts +11 -2
- package/src/cli/commands/bundle.ts +28 -8
- package/src/cli/commands/content.ts +13 -0
- package/src/cli/commands/login.ts +8 -1
- package/src/cli/commands/publish.ts +24 -0
- package/src/cli/commands/secrets.ts +183 -0
- package/src/cli/credentials.ts +1 -1
- package/src/cli/index.ts +5 -1
- package/src/client/index.ts +4 -4
- package/src/client/transport.ts +17 -7
- package/src/components/Break.astro +2 -2
- package/src/components/EmDashHead.astro +18 -13
- package/src/components/Embed.astro +1 -1
- package/src/components/Gallery.astro +1 -1
- package/src/components/Image.astro +1 -1
- package/src/components/InlinePortableTextEditor.tsx +104 -18
- package/src/config/secrets.ts +528 -0
- package/src/database/dialect-helpers.ts +50 -0
- package/src/database/migrations/034_published_at_index.ts +1 -1
- package/src/database/migrations/035_bounded_404_log.ts +56 -39
- package/src/database/migrations/runner.ts +156 -23
- package/src/database/repositories/content.ts +36 -12
- package/src/database/repositories/redirect.ts +14 -3
- package/src/database/repositories/taxonomy.ts +26 -0
- package/src/db/libsql.ts +1 -3
- package/src/db/sqlite.ts +2 -5
- package/src/emdash-runtime.ts +84 -159
- package/src/index.ts +9 -0
- package/src/loader.ts +24 -1
- package/src/mcp/server.ts +103 -36
- package/src/page/site-identity.ts +58 -0
- package/src/plugins/adapt-sandbox-entry.ts +22 -10
- package/src/plugins/context.ts +13 -10
- package/src/plugins/define-plugin.ts +40 -12
- package/src/plugins/hooks.ts +23 -19
- package/src/plugins/index.ts +9 -0
- package/src/plugins/manifest-schema.ts +37 -2
- package/src/plugins/types.ts +151 -11
- package/src/preview/urls.ts +23 -3
- package/src/query.ts +148 -5
- package/src/redirects/cache.ts +38 -18
- package/src/schema/registry.ts +56 -0
- package/src/schema/zod-generator.ts +27 -5
- package/src/seed/apply.ts +2 -0
- package/src/settings/index.ts +80 -6
- package/src/settings/types.ts +23 -1
- package/src/taxonomies/index.ts +11 -1
- package/dist/apply-x0eMK1lX.mjs.map +0 -1
- package/dist/bylines-CRNsVG88.mjs +0 -157
- package/dist/bylines-CRNsVG88.mjs.map +0 -1
- package/dist/cache-BkKBuIvS.mjs +0 -56
- package/dist/cache-BkKBuIvS.mjs.map +0 -1
- package/dist/chunk-ClPoSABd.mjs +0 -21
- package/dist/dialect-helpers-DhTzaUxP.mjs.map +0 -1
- package/dist/index-DIb-CzNx.d.mts.map +0 -1
- package/dist/loader-CndGj8kM.mjs.map +0 -1
- package/dist/manifest-schema-DH9xhc6t.mjs.map +0 -1
- package/dist/query-fqEdLFms.mjs.map +0 -1
- package/dist/redirect-D_pshWdf.mjs.map +0 -1
- package/dist/registry-C3Mr0ODu.mjs.map +0 -1
- package/dist/runner-OURCaApa.d.mts +0 -34
- package/dist/runner-OURCaApa.d.mts.map +0 -1
- package/dist/search-BoZYFuUk.mjs.map +0 -1
- package/dist/taxonomies-B4IAshV8.mjs.map +0 -1
- package/dist/types-i36XcA_X.d.mts.map +0 -1
- package/dist/version-Bbq8TCrz.mjs +0 -7
- package/dist/zod-generator-CpwccCIv.mjs.map +0 -1
|
@@ -21,6 +21,7 @@ import { createGzipDecoder, unpackTar } from "modern-tar";
|
|
|
21
21
|
import pc from "picocolors";
|
|
22
22
|
|
|
23
23
|
import { pluginManifestSchema } from "../../plugins/manifest-schema.js";
|
|
24
|
+
import { CAPABILITY_RENAMES, isDeprecatedCapability } from "../../plugins/types.js";
|
|
24
25
|
import {
|
|
25
26
|
getMarketplaceCredential,
|
|
26
27
|
saveMarketplaceCredential,
|
|
@@ -440,6 +441,29 @@ export const publishCommand = defineCommand({
|
|
|
440
441
|
}
|
|
441
442
|
console.log();
|
|
442
443
|
|
|
444
|
+
// ── Step 2.5: Hard-fail on deprecated capability names ──
|
|
445
|
+
//
|
|
446
|
+
// Refusing to publish manifests that use deprecated capability names
|
|
447
|
+
// keeps the marketplace clean while the deprecation window is open.
|
|
448
|
+
// The fix is mechanical and entirely in the author's hands — they
|
|
449
|
+
// rename, re-bundle, and republish. Better to refuse 5 publishes
|
|
450
|
+
// than ship 500 deprecated manifests. We check before authentication
|
|
451
|
+
// so authors don't burn a device-flow login on a doomed publish.
|
|
452
|
+
const deprecatedCaps = manifest.capabilities.filter(isDeprecatedCapability);
|
|
453
|
+
if (deprecatedCaps.length > 0) {
|
|
454
|
+
consola.error(
|
|
455
|
+
"Plugin declares deprecated capability names. Rename them and re-bundle before publishing:",
|
|
456
|
+
);
|
|
457
|
+
for (const cap of deprecatedCaps) {
|
|
458
|
+
const replacement = CAPABILITY_RENAMES[cap];
|
|
459
|
+
consola.error(` ${cap} → ${replacement}`);
|
|
460
|
+
}
|
|
461
|
+
consola.error(
|
|
462
|
+
"See https://emdashcms.com/docs/plugins/overview#capabilities for the full rename table.",
|
|
463
|
+
);
|
|
464
|
+
process.exit(1);
|
|
465
|
+
}
|
|
466
|
+
|
|
443
467
|
// ── Step 3: Authenticate ──
|
|
444
468
|
//
|
|
445
469
|
// Priority: EMDASH_MARKETPLACE_TOKEN env var > stored credential > interactive device flow.
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secrets CLI commands
|
|
3
|
+
*
|
|
4
|
+
* Pure (no-DB) commands for working with EmDash secrets:
|
|
5
|
+
*
|
|
6
|
+
* - `emdash secrets generate` — emits a fresh `EMDASH_ENCRYPTION_KEY`.
|
|
7
|
+
* Optionally writes it to `.dev.vars` (Workers) or `.env` (Node).
|
|
8
|
+
* - `emdash secrets fingerprint <key>` — prints the kid for a key,
|
|
9
|
+
* useful in CI for verifying what's been deployed without exposing
|
|
10
|
+
* the raw value.
|
|
11
|
+
*
|
|
12
|
+
* DB-touching commands (`status`, `migrate`, `rotate`) live elsewhere:
|
|
13
|
+
* the CLI process can't open the production D1/Postgres binding from
|
|
14
|
+
* the operator's machine, so those operations ship as admin HTTP
|
|
15
|
+
* endpoints in a later PR. A thin `--site <url>` wrapper for those
|
|
16
|
+
* endpoints can land alongside.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
20
|
+
import { resolve } from "node:path";
|
|
21
|
+
|
|
22
|
+
import { defineCommand } from "citty";
|
|
23
|
+
import { consola } from "consola";
|
|
24
|
+
import pc from "picocolors";
|
|
25
|
+
|
|
26
|
+
import { EmDashSecretsError, fingerprintKey, generateEncryptionKey } from "../../config/secrets.js";
|
|
27
|
+
|
|
28
|
+
const KEY_VAR_NAME = "EMDASH_ENCRYPTION_KEY";
|
|
29
|
+
/** Matches a populated entry — `KEY=<at least one char>`. */
|
|
30
|
+
const POPULATED_KEY_LINE_PATTERN = /^EMDASH_ENCRYPTION_KEY=.+$/m;
|
|
31
|
+
/**
|
|
32
|
+
* Matches any line starting `KEY=` including `KEY=` with empty value.
|
|
33
|
+
* Used for in-place replacement when the entry exists but has no value.
|
|
34
|
+
*/
|
|
35
|
+
const ANY_KEY_LINE_PATTERN = /^EMDASH_ENCRYPTION_KEY=.*$/m;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Append (or replace) `EMDASH_ENCRYPTION_KEY` in a dotenv-style file.
|
|
39
|
+
*
|
|
40
|
+
* Idempotent: if the entry exists with a populated value, leaves it alone
|
|
41
|
+
* (returns `"skipped"`) unless `force` is set. An entry with an empty
|
|
42
|
+
* value (`EMDASH_ENCRYPTION_KEY=`) is treated as "not set" and gets
|
|
43
|
+
* replaced — placeholder lines aren't a reason to refuse.
|
|
44
|
+
*
|
|
45
|
+
* Always ends the resulting file with a trailing newline. Doesn't touch
|
|
46
|
+
* other variables.
|
|
47
|
+
*
|
|
48
|
+
* Exported for tests.
|
|
49
|
+
*/
|
|
50
|
+
export function writeEncryptionKeyToFile(
|
|
51
|
+
targetPath: string,
|
|
52
|
+
value: string,
|
|
53
|
+
force: boolean,
|
|
54
|
+
): "wrote" | "skipped" {
|
|
55
|
+
const exists = existsSync(targetPath);
|
|
56
|
+
const existing = exists ? readFileSync(targetPath, "utf-8") : "";
|
|
57
|
+
|
|
58
|
+
const hasPopulatedKey = POPULATED_KEY_LINE_PATTERN.test(existing);
|
|
59
|
+
if (hasPopulatedKey && !force) {
|
|
60
|
+
return "skipped";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const newLine = `${KEY_VAR_NAME}=${value}`;
|
|
64
|
+
let next: string;
|
|
65
|
+
if (ANY_KEY_LINE_PATTERN.test(existing)) {
|
|
66
|
+
// In-place replace handles both populated-and-forced and empty-value
|
|
67
|
+
// cases. Then ensure trailing newline.
|
|
68
|
+
next = existing.replace(ANY_KEY_LINE_PATTERN, newLine);
|
|
69
|
+
if (!next.endsWith("\n")) next += "\n";
|
|
70
|
+
} else {
|
|
71
|
+
// Append. Insert a separating newline only if the file has content
|
|
72
|
+
// not already ending in one.
|
|
73
|
+
const sep = existing.length === 0 ? "" : existing.endsWith("\n") ? "" : "\n";
|
|
74
|
+
next = `${existing}${sep}${newLine}\n`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
writeFileSync(targetPath, next);
|
|
78
|
+
return "wrote";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const generateCommand = defineCommand({
|
|
82
|
+
meta: {
|
|
83
|
+
name: "generate",
|
|
84
|
+
description: "Generate a new EmDash encryption key",
|
|
85
|
+
},
|
|
86
|
+
args: {
|
|
87
|
+
write: {
|
|
88
|
+
type: "string",
|
|
89
|
+
description:
|
|
90
|
+
"Optional path to write the key to (e.g. .dev.vars or .env). " +
|
|
91
|
+
"Won't overwrite an existing entry without --force.",
|
|
92
|
+
},
|
|
93
|
+
force: {
|
|
94
|
+
type: "boolean",
|
|
95
|
+
description: "When used with --write, overwrite an existing entry",
|
|
96
|
+
default: false,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
run({ args }) {
|
|
100
|
+
const value = generateEncryptionKey();
|
|
101
|
+
|
|
102
|
+
if (args.write) {
|
|
103
|
+
const targetPath = resolve(process.cwd(), args.write);
|
|
104
|
+
const result = writeEncryptionKeyToFile(targetPath, value, args.force);
|
|
105
|
+
if (result === "skipped") {
|
|
106
|
+
// Idempotent no-op: entry already populated. Exit 0 so chained
|
|
107
|
+
// scripts (`emdash secrets generate --write && pnpm dev`) don't
|
|
108
|
+
// break. Pass --force to replace, with full awareness that
|
|
109
|
+
// existing encrypted secrets become unreadable.
|
|
110
|
+
consola.info(
|
|
111
|
+
`${KEY_VAR_NAME} already set in ${pc.cyan(args.write)}; leaving it alone. ` +
|
|
112
|
+
`Pass ${pc.bold("--force")} to replace it.`,
|
|
113
|
+
);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
consola.log("");
|
|
117
|
+
consola.log(`${pc.bold("Wrote")} ${pc.cyan(KEY_VAR_NAME)} to ${pc.cyan(args.write)}`);
|
|
118
|
+
consola.log("");
|
|
119
|
+
consola.log(
|
|
120
|
+
pc.yellow(
|
|
121
|
+
"Keep this file out of version control. Losing the key means losing every secret encrypted with it.",
|
|
122
|
+
),
|
|
123
|
+
);
|
|
124
|
+
consola.log("");
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Print the key to stdout (one line, no decoration) so it can be
|
|
129
|
+
// piped into env files or secret-management tools without scraping.
|
|
130
|
+
// Explanatory text goes to stderr so it doesn't pollute the pipe.
|
|
131
|
+
process.stdout.write(`${value}\n`);
|
|
132
|
+
const guidance = [
|
|
133
|
+
"",
|
|
134
|
+
pc.bold("EmDash encryption key generated."),
|
|
135
|
+
"",
|
|
136
|
+
`Set ${pc.cyan(KEY_VAR_NAME)} in your environment.`,
|
|
137
|
+
"For Cloudflare deployments, push it to your Worker's secrets.",
|
|
138
|
+
"For Node deployments, add it to your process environment or .env file.",
|
|
139
|
+
"",
|
|
140
|
+
pc.yellow("Keep this value secret. Losing it means losing every secret encrypted with it."),
|
|
141
|
+
"",
|
|
142
|
+
].join("\n");
|
|
143
|
+
process.stderr.write(`${guidance}\n`);
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const fingerprintCommand = defineCommand({
|
|
148
|
+
meta: {
|
|
149
|
+
name: "fingerprint",
|
|
150
|
+
description: "Print the kid (8-char fingerprint) for an encryption key",
|
|
151
|
+
},
|
|
152
|
+
args: {
|
|
153
|
+
key: {
|
|
154
|
+
type: "positional",
|
|
155
|
+
description: "The full key value (with the emdash_enc_v1_ prefix)",
|
|
156
|
+
required: true,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
async run({ args }) {
|
|
160
|
+
try {
|
|
161
|
+
const kid = await fingerprintKey(args.key);
|
|
162
|
+
// Newline-only on stdout so it pipes cleanly into env/CI logs
|
|
163
|
+
// without leaking the raw key.
|
|
164
|
+
process.stdout.write(`${kid}\n`);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
consola.error(
|
|
167
|
+
error instanceof EmDashSecretsError ? error.message : "Failed to fingerprint key",
|
|
168
|
+
);
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
export const secretsCommand = defineCommand({
|
|
175
|
+
meta: {
|
|
176
|
+
name: "secrets",
|
|
177
|
+
description: "Manage EmDash secrets (generate, inspect)",
|
|
178
|
+
},
|
|
179
|
+
subCommands: {
|
|
180
|
+
generate: generateCommand,
|
|
181
|
+
fingerprint: fingerprintCommand,
|
|
182
|
+
},
|
|
183
|
+
});
|
package/src/cli/credentials.ts
CHANGED
|
@@ -130,7 +130,7 @@ function readStore(): CredentialStore {
|
|
|
130
130
|
|
|
131
131
|
function writeStore(store: CredentialStore): void {
|
|
132
132
|
const dir = getConfigDir();
|
|
133
|
-
mkdirSync(dir, { recursive: true });
|
|
133
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
134
134
|
|
|
135
135
|
const path = getCredentialPath();
|
|
136
136
|
writeFileSync(path, JSON.stringify(store, null, "\t"), {
|
package/src/cli/index.ts
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* - dev: Run dev server with local D1
|
|
12
12
|
* - seed: Apply a seed file to the database
|
|
13
13
|
* - export-seed: Export database schema and content as a seed file
|
|
14
|
-
* -
|
|
14
|
+
* - secrets: Generate and inspect EmDash secrets (encryption keys, etc.)
|
|
15
|
+
* - auth: [DEPRECATED] Generate auth secret (use `secrets` instead)
|
|
15
16
|
* - login/logout/whoami: Session management
|
|
16
17
|
* - content: Create, read, update, delete content
|
|
17
18
|
* - schema: Manage collections and fields
|
|
@@ -36,6 +37,7 @@ import { menuCommand } from "./commands/menu.js";
|
|
|
36
37
|
import { pluginCommand } from "./commands/plugin.js";
|
|
37
38
|
import { schemaCommand } from "./commands/schema.js";
|
|
38
39
|
import { searchCommand } from "./commands/search-cmd.js";
|
|
40
|
+
import { secretsCommand } from "./commands/secrets.js";
|
|
39
41
|
import { seedCommand } from "./commands/seed.js";
|
|
40
42
|
import { taxonomyCommand } from "./commands/taxonomy.js";
|
|
41
43
|
import { typesCommand } from "./commands/types.js";
|
|
@@ -53,6 +55,8 @@ const main = defineCommand({
|
|
|
53
55
|
doctor: doctorCommand,
|
|
54
56
|
seed: seedCommand,
|
|
55
57
|
"export-seed": exportSeedCommand,
|
|
58
|
+
secrets: secretsCommand,
|
|
59
|
+
// Deprecated alias kept for backwards compat; will be removed in a future minor.
|
|
56
60
|
auth: authCommand,
|
|
57
61
|
login: loginCommand,
|
|
58
62
|
logout: logoutCommand,
|
package/src/client/index.ts
CHANGED
|
@@ -723,8 +723,8 @@ export class EmDashClient {
|
|
|
723
723
|
|
|
724
724
|
/** List taxonomies */
|
|
725
725
|
async taxonomies(): Promise<Taxonomy[]> {
|
|
726
|
-
const data = await this.request<{
|
|
727
|
-
return data.
|
|
726
|
+
const data = await this.request<{ taxonomies: Taxonomy[] }>("GET", "/taxonomies");
|
|
727
|
+
return data.taxonomies;
|
|
728
728
|
}
|
|
729
729
|
|
|
730
730
|
/** List terms in a taxonomy */
|
|
@@ -757,8 +757,8 @@ export class EmDashClient {
|
|
|
757
757
|
|
|
758
758
|
/** List menus */
|
|
759
759
|
async menus(): Promise<Menu[]> {
|
|
760
|
-
|
|
761
|
-
return
|
|
760
|
+
// Handler returns a bare array, not { items: [...] }
|
|
761
|
+
return this.request<Menu[]>("GET", "/menus");
|
|
762
762
|
}
|
|
763
763
|
|
|
764
764
|
/** Get a menu with its items */
|
package/src/client/transport.ts
CHANGED
|
@@ -155,24 +155,34 @@ export function refreshInterceptor(options: {
|
|
|
155
155
|
|
|
156
156
|
if (!res.ok) return null;
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
interface TokenFields {
|
|
159
159
|
access_token: string;
|
|
160
160
|
refresh_token?: string;
|
|
161
161
|
expires_in?: number;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const json = (await res.json()) as Record<string, unknown>;
|
|
165
|
+
|
|
166
|
+
// The token endpoint wraps the response in { data: ... } via apiSuccess.
|
|
167
|
+
// Handle both wrapped and bare shapes for robustness.
|
|
168
|
+
const tokenData: TokenFields =
|
|
169
|
+
json.data && typeof json.data === "object" && "access_token" in json.data
|
|
170
|
+
? (json.data as TokenFields)
|
|
171
|
+
: (json as unknown as TokenFields);
|
|
172
|
+
|
|
173
|
+
const expiresAt = tokenData.expires_in
|
|
174
|
+
? new Date(Date.now() + tokenData.expires_in * 1000).toISOString()
|
|
165
175
|
: new Date(Date.now() + 3600_000).toISOString();
|
|
166
176
|
|
|
167
177
|
if (options.onTokenRefreshed) {
|
|
168
178
|
options.onTokenRefreshed(
|
|
169
|
-
|
|
170
|
-
|
|
179
|
+
tokenData.access_token,
|
|
180
|
+
tokenData.refresh_token ?? options.refreshToken,
|
|
171
181
|
expiresAt,
|
|
172
182
|
);
|
|
173
183
|
}
|
|
174
184
|
|
|
175
|
-
return
|
|
185
|
+
return tokenData.access_token;
|
|
176
186
|
}
|
|
177
187
|
|
|
178
188
|
return async (request, next) => {
|
|
@@ -32,11 +32,11 @@ const style = node?.style || "line";
|
|
|
32
32
|
}
|
|
33
33
|
.emdash-break-line {
|
|
34
34
|
border: none;
|
|
35
|
-
border-top: 1px solid #e0e0e0;
|
|
35
|
+
border-top: 1px solid var(--emdash-break-color, var(--color-border, #e0e0e0));
|
|
36
36
|
}
|
|
37
37
|
.emdash-break-dots {
|
|
38
38
|
text-align: center;
|
|
39
|
-
color: #999;
|
|
39
|
+
color: var(--emdash-break-dots-color, var(--color-muted, #999));
|
|
40
40
|
letter-spacing: 0.5em;
|
|
41
41
|
}
|
|
42
42
|
.emdash-break-space {
|
|
@@ -20,8 +20,9 @@ import {
|
|
|
20
20
|
generateBaseSeoContributions,
|
|
21
21
|
generateSiteSeoContributions,
|
|
22
22
|
} from "../page/seo-contributions.js";
|
|
23
|
+
import { renderSiteIdentity } from "../page/site-identity.js";
|
|
23
24
|
import { getPageRuntime } from "../page/index.js";
|
|
24
|
-
import {
|
|
25
|
+
import { getSiteSettings } from "../settings/index.js";
|
|
25
26
|
|
|
26
27
|
interface Props {
|
|
27
28
|
page: PublicPageContext;
|
|
@@ -34,29 +35,32 @@ const runtime = getPageRuntime(Astro.locals as Record<string, unknown>);
|
|
|
34
35
|
const baseContributions: PageMetadataContribution[] = generateBaseSeoContributions(page);
|
|
35
36
|
|
|
36
37
|
let metadataHtml = "";
|
|
38
|
+
let siteIdentityHtml = "";
|
|
37
39
|
let fragmentsHtml = "";
|
|
38
40
|
|
|
39
41
|
if (runtime) {
|
|
40
|
-
// Run independent async loads in parallel: site
|
|
41
|
-
//
|
|
42
|
-
// contributions
|
|
43
|
-
//
|
|
44
|
-
//
|
|
42
|
+
// Run independent async loads in parallel: site settings (SEO meta
|
|
43
|
+
// tags + favicon) and plugin page-metadata contributions. Plugin
|
|
44
|
+
// contributions come BEFORE site/base in the contribution array,
|
|
45
|
+
// so resolvePageMetadata's first-wins dedup lets plugins override
|
|
46
|
+
// defaults.
|
|
45
47
|
//
|
|
46
|
-
// `
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
// `getSiteSettings()` is request-cached and worker-cached, so when
|
|
49
|
+
// a parent template has already called it (the standard pattern in
|
|
50
|
+
// `Base.astro`), this is free. Otherwise it's a single batched
|
|
51
|
+
// query that supersedes any per-key fetch this component would
|
|
52
|
+
// otherwise have done.
|
|
53
|
+
const [siteSettings, pluginContributions, fragments] = await Promise.all([
|
|
54
|
+
getSiteSettings(),
|
|
52
55
|
runtime.collectPageMetadata(page),
|
|
53
56
|
runtime.collectPageFragments(page),
|
|
54
57
|
]);
|
|
55
58
|
|
|
56
|
-
const siteContributions = generateSiteSeoContributions(
|
|
59
|
+
const siteContributions = generateSiteSeoContributions(siteSettings.seo);
|
|
57
60
|
const allContributions = [...pluginContributions, ...siteContributions, ...baseContributions];
|
|
58
61
|
const resolved = resolvePageMetadata(allContributions);
|
|
59
62
|
metadataHtml = renderPageMetadata(resolved);
|
|
63
|
+
siteIdentityHtml = renderSiteIdentity({ favicon: siteSettings.favicon });
|
|
60
64
|
fragmentsHtml = renderFragments(fragments, "head");
|
|
61
65
|
} else {
|
|
62
66
|
// No runtime (EmDash not initialized) — still render base SEO
|
|
@@ -66,4 +70,5 @@ if (runtime) {
|
|
|
66
70
|
---
|
|
67
71
|
|
|
68
72
|
<Fragment set:html={metadataHtml} />
|
|
73
|
+
<Fragment set:html={siteIdentityHtml} />
|
|
69
74
|
<Fragment set:html={fragmentsHtml} />
|
|
@@ -176,7 +176,7 @@ const imgStyle = placeholderStyle ? `${baseStyle} ${placeholderStyle}` : baseSty
|
|
|
176
176
|
}
|
|
177
177
|
.emdash-image figcaption {
|
|
178
178
|
font-size: 0.875rem;
|
|
179
|
-
color: #666;
|
|
179
|
+
color: var(--emdash-caption-color, var(--color-muted, #666));
|
|
180
180
|
margin-top: 0.5rem;
|
|
181
181
|
text-align: center;
|
|
182
182
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { autoUpdate, flip, offset, shift, useFloating } from "@floating-ui/react";
|
|
13
|
-
import { Extension, type JSONContent, type Range } from "@tiptap/core";
|
|
13
|
+
import { Extension, Node, mergeAttributes, type JSONContent, type Range } from "@tiptap/core";
|
|
14
14
|
import Focus from "@tiptap/extension-focus";
|
|
15
15
|
import Image from "@tiptap/extension-image";
|
|
16
16
|
import Link from "@tiptap/extension-link";
|
|
@@ -202,12 +202,18 @@ function convertPMNode(node: PMNode): PTBlock | PTBlock[] | null {
|
|
|
202
202
|
}
|
|
203
203
|
case "horizontalRule":
|
|
204
204
|
return { _type: "break", _key: k(), style: "lineBreak" };
|
|
205
|
-
case "pluginBlock":
|
|
205
|
+
case "pluginBlock": {
|
|
206
|
+
// Spread the captured data back out so the block round-trips losslessly.
|
|
207
|
+
// `data` holds every field except _type / _key / id (which live on
|
|
208
|
+
// dedicated attrs).
|
|
209
|
+
const { blockType, id, data } = node.attrs ?? {};
|
|
206
210
|
return {
|
|
207
|
-
|
|
211
|
+
...(data && typeof data === "object" ? data : {}),
|
|
212
|
+
_type: typeof blockType === "string" ? blockType : "embed",
|
|
208
213
|
_key: k(),
|
|
209
|
-
id:
|
|
214
|
+
id: typeof id === "string" ? id : "",
|
|
210
215
|
};
|
|
216
|
+
}
|
|
211
217
|
default:
|
|
212
218
|
return null;
|
|
213
219
|
}
|
|
@@ -412,21 +418,23 @@ function convertPTBlock(block: PTBlock): JSONContent | null {
|
|
|
412
418
|
},
|
|
413
419
|
};
|
|
414
420
|
}
|
|
415
|
-
// Unknown block types — treat as plugin blocks
|
|
416
|
-
|
|
417
|
-
if
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
// Truly unknown — render as code-marked text
|
|
421
|
+
// Unknown block types — treat as plugin blocks. Capture every field other
|
|
422
|
+
// than the well-known ones into `data` so the block round-trips losslessly,
|
|
423
|
+
// even if no plugin currently registers this type. Matches the admin
|
|
424
|
+
// editor's behaviour at PortableTextEditor.tsx:572-588.
|
|
425
|
+
const { _type, _key, id, url, ...rest } = block as { _type: string; _key: string } & Record<
|
|
426
|
+
string,
|
|
427
|
+
unknown
|
|
428
|
+
>;
|
|
429
|
+
// Filter out _-prefixed keys to prevent accumulation across edit cycles.
|
|
430
|
+
const data = Object.fromEntries(Object.entries(rest).filter(([key]) => !key.startsWith("_")));
|
|
427
431
|
return {
|
|
428
|
-
type: "
|
|
429
|
-
|
|
432
|
+
type: "pluginBlock",
|
|
433
|
+
attrs: {
|
|
434
|
+
blockType: typeof _type === "string" ? _type : "embed",
|
|
435
|
+
id: typeof id === "string" ? id : typeof url === "string" ? url : "",
|
|
436
|
+
data,
|
|
437
|
+
},
|
|
430
438
|
};
|
|
431
439
|
}
|
|
432
440
|
|
|
@@ -762,6 +770,61 @@ const initialSlashMenuState: SlashMenuState = {
|
|
|
762
770
|
range: null,
|
|
763
771
|
};
|
|
764
772
|
|
|
773
|
+
/**
|
|
774
|
+
* Minimal `pluginBlock` TipTap node for the inline (visual-editing) editor.
|
|
775
|
+
*
|
|
776
|
+
* Plugin-contributed Portable Text block types (e.g. `marketing.hero`) are
|
|
777
|
+
* editable in the admin via a Block Kit modal. The visual-editing surface
|
|
778
|
+
* deliberately does NOT offer that UX — it would need to fetch the manifest,
|
|
779
|
+
* mount the modal, and round-trip through plugin-block plumbing that lives in
|
|
780
|
+
* `@emdash-cms/admin`. Instead, the inline editor renders these blocks as a
|
|
781
|
+
* read-only placeholder so editors can see they exist and edit the surrounding
|
|
782
|
+
* content without losing the block's data.
|
|
783
|
+
*
|
|
784
|
+
* The full block payload is preserved on `data` and round-tripped losslessly
|
|
785
|
+
* through PT ↔ PM conversion (see convertPTBlock/convertPMNode). Without this
|
|
786
|
+
* extension, ProseMirror's schema would silently filter unknown nodes on load
|
|
787
|
+
* and the next save would persist the block's disappearance.
|
|
788
|
+
*/
|
|
789
|
+
const PluginBlockNode = Node.create({
|
|
790
|
+
name: "pluginBlock",
|
|
791
|
+
group: "block",
|
|
792
|
+
atom: true,
|
|
793
|
+
selectable: true,
|
|
794
|
+
draggable: true,
|
|
795
|
+
|
|
796
|
+
addAttributes() {
|
|
797
|
+
// All three attributes are stored on the ProseMirror node but not
|
|
798
|
+
// rendered as DOM attributes — they're metadata for the round-trip,
|
|
799
|
+
// not styling or behaviour the placeholder DOM needs to expose.
|
|
800
|
+
const noDom = { rendered: false, parseHTML: () => null };
|
|
801
|
+
return {
|
|
802
|
+
blockType: { default: "", ...noDom },
|
|
803
|
+
id: { default: "", ...noDom },
|
|
804
|
+
data: { default: {}, ...noDom },
|
|
805
|
+
};
|
|
806
|
+
},
|
|
807
|
+
|
|
808
|
+
parseHTML() {
|
|
809
|
+
return [{ tag: 'div[data-emdash-plugin-block="true"]' }];
|
|
810
|
+
},
|
|
811
|
+
|
|
812
|
+
renderHTML({ HTMLAttributes, node }) {
|
|
813
|
+
const blockType = typeof node.attrs.blockType === "string" ? node.attrs.blockType : "";
|
|
814
|
+
const label = blockType || "Block";
|
|
815
|
+
return [
|
|
816
|
+
"div",
|
|
817
|
+
mergeAttributes(HTMLAttributes, {
|
|
818
|
+
"data-emdash-plugin-block": "true",
|
|
819
|
+
"data-block-type": blockType,
|
|
820
|
+
class: "emdash-plugin-block-placeholder",
|
|
821
|
+
contenteditable: "false",
|
|
822
|
+
}),
|
|
823
|
+
`Plugin block: ${label} (edit in admin)`,
|
|
824
|
+
];
|
|
825
|
+
},
|
|
826
|
+
});
|
|
827
|
+
|
|
765
828
|
function createSlashCommandsExtension(options: {
|
|
766
829
|
filterCommands: (query: string) => SlashCommandItem[];
|
|
767
830
|
onStateChange: React.Dispatch<React.SetStateAction<SlashMenuState>>;
|
|
@@ -1734,6 +1797,7 @@ export function InlinePortableTextEditor({
|
|
|
1734
1797
|
mode: "all",
|
|
1735
1798
|
}),
|
|
1736
1799
|
Typography,
|
|
1800
|
+
PluginBlockNode,
|
|
1737
1801
|
slashCommandsExtension,
|
|
1738
1802
|
],
|
|
1739
1803
|
content: initialContent,
|
|
@@ -1932,7 +1996,29 @@ export function InlinePortableTextEditor({
|
|
|
1932
1996
|
.emdash-inline-editor:focus {
|
|
1933
1997
|
outline: none;
|
|
1934
1998
|
}
|
|
1999
|
+
.emdash-plugin-block-placeholder {
|
|
2000
|
+
margin: 0.75rem 0;
|
|
2001
|
+
padding: 0.625rem 0.875rem;
|
|
2002
|
+
border: 1px dashed #d1d5db;
|
|
2003
|
+
border-radius: 0.5rem;
|
|
2004
|
+
background: #f9fafb;
|
|
2005
|
+
color: #4b5563;
|
|
2006
|
+
font-size: 0.875rem;
|
|
2007
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
2008
|
+
user-select: none;
|
|
2009
|
+
}
|
|
2010
|
+
@media (prefers-color-scheme: dark) {
|
|
2011
|
+
.emdash-plugin-block-placeholder {
|
|
2012
|
+
border-color: #374151;
|
|
2013
|
+
background: #111827;
|
|
2014
|
+
color: #9ca3af;
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
1935
2017
|
`}</style>
|
|
1936
2018
|
</div>
|
|
1937
2019
|
);
|
|
1938
2020
|
}
|
|
2021
|
+
|
|
2022
|
+
// Test-only exports for unit tests of the conversion functions.
|
|
2023
|
+
export { pmToPortableText as _pmToPortableText };
|
|
2024
|
+
export { portableTextToPM as _portableTextToPM };
|