@rimelight/cms 0.0.2 → 0.0.4

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.
Files changed (124) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bylines-Csggkl-g.d.mts +405 -0
  3. package/dist/index.d.mts +724 -0
  4. package/dist/index.mjs +2382 -0
  5. package/dist/integration.d.mts +33 -0
  6. package/dist/integration.mjs +161 -0
  7. package/dist/schema/index.d.mts +2063 -0
  8. package/dist/schema/index.mjs +176 -0
  9. package/dist/schema/sqlite.d.mts +2132 -0
  10. package/dist/schema/sqlite.mjs +137 -0
  11. package/dist/storage/index.d.mts +59 -0
  12. package/dist/storage/index.mjs +133 -0
  13. package/package.json +36 -18
  14. package/src/admin/api/media-file.ts +39 -0
  15. package/src/admin/api/media.ts +224 -0
  16. package/src/admin/layouts/CMSDashboardLayout.astro +191 -0
  17. package/src/admin/layouts/DefaultParentLayout.astro +50 -0
  18. package/src/admin/pages/assets.astro +424 -0
  19. package/src/admin/pages/byline-schema.astro +62 -0
  20. package/src/admin/pages/bylines.astro +16 -0
  21. package/src/admin/pages/categories.astro +21 -0
  22. package/src/admin/pages/content-types.astro +55 -0
  23. package/src/admin/pages/dashboard.astro +61 -0
  24. package/src/admin/pages/pages-edit.astro +595 -0
  25. package/src/admin/pages/pages-index.astro +146 -0
  26. package/src/admin/pages/pages-new.astro +130 -0
  27. package/src/admin/pages/pages-preview.astro +111 -0
  28. package/src/admin/pages/pages-review.astro +236 -0
  29. package/src/admin/pages/settings.astro +203 -0
  30. package/src/admin/pages/tags.astro +21 -0
  31. package/src/admin/pages/templates-edit.astro +234 -0
  32. package/src/admin/pages/templates-index.astro +95 -0
  33. package/src/admin/pages/templates-new.astro +193 -0
  34. package/src/admin/pages/users.astro +74 -0
  35. package/src/admin/pages/versions.astro +74 -0
  36. package/src/astro/BlockRenderer.astro +44 -102
  37. package/src/astro/PageRenderer.astro +12 -5
  38. package/src/astro/blocks/CalloutBlock.astro +7 -7
  39. package/src/astro/blocks/CardBlock.astro +5 -5
  40. package/src/astro/blocks/CodeBlock.astro +2 -2
  41. package/src/astro/blocks/FileTreeBlock.astro +7 -7
  42. package/src/astro/blocks/ImageBlock.astro +2 -2
  43. package/src/astro/blocks/OrderedListBlock.astro +2 -2
  44. package/src/astro/blocks/ParagraphBlock.astro +3 -3
  45. package/src/astro/blocks/SectionBlock.astro +6 -6
  46. package/src/astro/blocks/StepItemBlock.astro +3 -3
  47. package/src/astro/blocks/StepsBlock.astro +1 -1
  48. package/src/astro/blocks/TableBlock.astro +6 -6
  49. package/src/astro/blocks/TabsBlock.astro +9 -9
  50. package/src/astro/blocks/UnorderedListBlock.astro +2 -2
  51. package/src/astro/blocks/index.ts +35 -0
  52. package/src/client/components/RimelightBlock.tsx +19 -19
  53. package/src/client/components/RimelightBlockPicker.tsx +9 -13
  54. package/src/client/components/RimelightBylinesManager.tsx +438 -0
  55. package/src/client/components/RimelightEditor.tsx +3 -3
  56. package/src/client/components/RimelightPreview.tsx +37 -45
  57. package/src/client/components/RimelightPropertiesPanel.tsx +368 -26
  58. package/src/client/components/RimelightTaxonomyManager.tsx +369 -0
  59. package/src/client/components/RimelightTaxonomyMasterDetail.tsx +412 -0
  60. package/src/client/components/RimelightTemplateEditor.tsx +6 -8
  61. package/src/client/components/editors/CalloutEditor.tsx +2 -4
  62. package/src/client/components/editors/CardsEditor.tsx +2 -4
  63. package/src/client/components/editors/CodeEditor.tsx +1 -3
  64. package/src/client/components/editors/FileTreeEditor.tsx +2 -4
  65. package/src/client/components/editors/ImageEditor.tsx +3 -3
  66. package/src/client/components/editors/ParagraphEditor.tsx +2 -2
  67. package/src/client/components/editors/SceneEditor.tsx +6 -12
  68. package/src/client/components/editors/ScriptEditor.tsx +8 -16
  69. package/src/client/components/editors/SectionEditor.tsx +4 -4
  70. package/src/client/components/editors/StepItemEditor.tsx +2 -2
  71. package/src/client/components/editors/StepsEditor.tsx +2 -4
  72. package/src/client/components/editors/TabItemEditor.tsx +3 -3
  73. package/src/client/components/editors/TableEditor.tsx +5 -5
  74. package/src/client/components/editors/TabsEditor.tsx +2 -4
  75. package/src/client/components/index.ts +3 -0
  76. package/src/client/loader.ts +3 -0
  77. package/src/core/diff.ts +145 -0
  78. package/src/core/excerpt.ts +159 -0
  79. package/src/core/preview.ts +87 -0
  80. package/src/core/registry.ts +0 -86
  81. package/src/core/types/blocks.ts +6 -1
  82. package/src/core/types/bylines.ts +14 -0
  83. package/src/core/types/media.ts +13 -0
  84. package/src/core/types/taxonomies.ts +20 -0
  85. package/src/cron/scheduled.ts +57 -0
  86. package/src/docs/agent.ts +116 -0
  87. package/src/docs/config.ts +25 -0
  88. package/src/docs/index.ts +5 -0
  89. package/src/docs/routing.ts +104 -0
  90. package/src/docs/sidebar.ts +251 -0
  91. package/src/docs/toc.ts +47 -0
  92. package/src/env.d.ts +19 -0
  93. package/src/index.ts +57 -12
  94. package/src/integration.ts +250 -0
  95. package/src/loader/live.ts +254 -0
  96. package/src/markdown/index.ts +0 -1
  97. package/src/mcp/index.ts +228 -0
  98. package/src/schema/bylines.ts +23 -0
  99. package/src/schema/index.ts +3 -4
  100. package/src/schema/page_versions.ts +2 -0
  101. package/src/schema/pages.ts +2 -0
  102. package/src/schema/site_settings.ts +41 -0
  103. package/src/schema/sqlite.ts +344 -0
  104. package/src/schema/taxonomies.ts +49 -0
  105. package/src/services/bylines.ts +74 -0
  106. package/src/services/search-indexer.ts +61 -0
  107. package/src/services/site-settings.ts +108 -0
  108. package/src/services/taxonomies.ts +276 -0
  109. package/src/storage/index.ts +256 -0
  110. package/src/astro/blocks/ApiDocumentationBlock.astro +0 -350
  111. package/src/astro/blocks/DialogueBlock.astro +0 -23
  112. package/src/astro/blocks/LivePreviewBlock.astro +0 -27
  113. package/src/astro/blocks/SceneBlock.astro +0 -65
  114. package/src/astro/blocks/ScriptBlock.astro +0 -59
  115. package/src/core/template-sync.ts +0 -75
  116. package/src/markdown/parser.ts +0 -347
  117. package/src/migration-tools.ts +0 -334
  118. package/src/migration.ts +0 -155
  119. package/src/schema/component_dependencies.ts +0 -21
  120. package/src/schema/component_metadata.ts +0 -31
  121. package/src/schema/component_metadata_cache.ts +0 -15
  122. package/src/schema/component_versions.ts +0 -19
  123. package/src/search/sync.ts +0 -32
  124. package/src/services/component-metadata.ts +0 -134
package/src/migration.ts DELETED
@@ -1,155 +0,0 @@
1
- import { sql } from "drizzle-orm"
2
- import { markdownToBlocks } from "./markdown/parser.ts"
3
- import type { BaseBlock } from "./core/types/blocks"
4
-
5
- export interface DocMigrationInput {
6
- slug: string
7
- title: string | Record<string, string>
8
- description?: string | Record<string, string>
9
- markdown: string
10
- properties?: Record<string, any>
11
- postedAt?: Date | null
12
- authorIds?: string[]
13
- }
14
-
15
- export function parseMarkdownWithFrontmatter(raw: string): {
16
- frontmatter: Record<string, any>
17
- body: string
18
- } {
19
- const frontmatter: Record<string, any> = {}
20
- const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/)
21
-
22
- if (!match) {
23
- return { frontmatter, body: raw.trim() }
24
- }
25
-
26
- const yamlBlock = match[1] || ""
27
- const body = (match[2] || "").trim()
28
-
29
- const lines = yamlBlock.split(/\r?\n/)
30
- for (const line of lines) {
31
- const trimmed = line.trim()
32
- if (!trimmed || trimmed.startsWith("#")) continue
33
- const colonIndex = trimmed.indexOf(":")
34
- if (colonIndex !== -1) {
35
- const key = trimmed.slice(0, colonIndex).trim()
36
- let value: any = trimmed.slice(colonIndex + 1).trim()
37
-
38
- if (value === "true") value = true
39
- else if (value === "false") value = false
40
- else if (value === "null") value = null
41
- else if (!isNaN(Number(value)) && value !== "") value = Number(value)
42
- else if (
43
- (value.startsWith('"') && value.endsWith('"')) ||
44
- (value.startsWith("'") && value.endsWith("'"))
45
- ) {
46
- value = value.slice(1, -1)
47
- }
48
-
49
- frontmatter[key] = value
50
- }
51
- }
52
-
53
- return { frontmatter, body }
54
- }
55
-
56
- export function convertMarkdownDocToPageRecord(input: DocMigrationInput) {
57
- const blocks: BaseBlock[] = markdownToBlocks(input.markdown)
58
- const titleObj =
59
- typeof input.title === "string" ? { en: input.title } : input.title || { en: input.slug }
60
- const descObj =
61
- typeof input.description === "string"
62
- ? { en: input.description }
63
- : input.description || undefined
64
-
65
- return {
66
- id: crypto.randomUUID(),
67
- slug: input.slug,
68
- type: "doc" as const,
69
- title: titleObj,
70
- description: descObj,
71
- tags: [],
72
- authorIds: input.authorIds || [],
73
- postedAt: input.postedAt !== undefined ? input.postedAt : new Date(),
74
- createdAt: new Date(),
75
- updatedAt: new Date(),
76
- content: {
77
- blocks,
78
- properties: input.properties || {}
79
- }
80
- }
81
- }
82
-
83
- export async function migrateLegacyPagesToCMSv2(db: any) {
84
- console.log("[Migration] Applying DDL schema updates...")
85
-
86
- await db.execute(sql`
87
- ALTER TABLE pages ADD COLUMN IF NOT EXISTS template_id UUID;
88
- ALTER TABLE pages ADD COLUMN IF NOT EXISTS template_version INTEGER DEFAULT 1 NOT NULL;
89
- ALTER TABLE page_versions ADD COLUMN IF NOT EXISTS version_number INTEGER DEFAULT 1 NOT NULL;
90
-
91
- CREATE UNIQUE INDEX IF NOT EXISTS page_versions_page_id_version_idx
92
- ON page_versions (page_id, version_number);
93
- `)
94
-
95
- console.log("[Migration] Transforming legacy page content in chunked batches...")
96
-
97
- const BATCH_SIZE = 100
98
- let offset = 0
99
-
100
- async function fetchBatch(currentOffset: number) {
101
- const batch = await db.execute(sql`
102
- SELECT id, content FROM pages ORDER BY id LIMIT ${BATCH_SIZE} OFFSET ${currentOffset};
103
- `)
104
-
105
- if (!batch || !batch.rows || batch.rows.length === 0) {
106
- return null
107
- }
108
-
109
- const rows: Array<{ id: string; content: unknown }> = batch.rows
110
- return rows
111
- }
112
-
113
- async function processBatch(pagesList: Array<{ id: string; content: unknown }>) {
114
- const updatePromises = pagesList.map((page) => {
115
- const transformed = transformLegacyContent(page.content)
116
- return db.execute(sql`
117
- UPDATE pages SET content = ${JSON.stringify(transformed)}::jsonb WHERE id = ${page.id}::uuid;
118
- `)
119
- })
120
-
121
- await Promise.all(updatePromises)
122
- }
123
-
124
- async function processAllBatches(currentOffset: number): Promise<void> {
125
- const pagesList = await fetchBatch(currentOffset)
126
- if (!pagesList) return
127
- await processBatch(pagesList)
128
- console.log(`[Migration] Migrated ${currentOffset + BATCH_SIZE} records...`)
129
- return processAllBatches(currentOffset + BATCH_SIZE)
130
- }
131
-
132
- await processAllBatches(offset)
133
-
134
- console.log("[Migration] Migration completed successfully.")
135
- }
136
-
137
- export function transformLegacyContent(raw: unknown) {
138
- if (typeof raw === "object" && raw !== null && "blocks" in raw) return raw
139
- let textContent = ""
140
- try {
141
- textContent = typeof raw === "string" ? raw : JSON.stringify(raw ?? "")
142
- } catch {
143
- textContent = ""
144
- }
145
- return {
146
- blocks: [
147
- {
148
- id: crypto.randomUUID(),
149
- type: "ParagraphBlock",
150
- props: { text: { en: textContent } }
151
- }
152
- ],
153
- properties: {}
154
- }
155
- }
@@ -1,21 +0,0 @@
1
- import { pgTable, text, uuid, uniqueIndex } from "drizzle-orm/pg-core"
2
-
3
- export const componentDependencies = pgTable(
4
- "component_dependencies",
5
- {
6
- id: uuid("id").defaultRandom().notNull().primaryKey(),
7
- sourceComponent: text("source_component").notNull(),
8
- targetComponent: text("target_component").notNull(),
9
- dependencyType: text("dependency_type").notNull()
10
- },
11
- (table) => [
12
- uniqueIndex("component_dependencies_unique_idx").on(
13
- table.sourceComponent,
14
- table.targetComponent,
15
- table.dependencyType
16
- )
17
- ]
18
- )
19
-
20
- export type ComponentDependency = typeof componentDependencies.$inferSelect
21
- export type NewComponentDependency = typeof componentDependencies.$inferInsert
@@ -1,31 +0,0 @@
1
- import {
2
- pgTable,
3
- text,
4
- timestamp,
5
- uuid,
6
- uniqueIndex,
7
- jsonb
8
- } from "drizzle-orm/pg-core"
9
-
10
- export const componentMetadata = pgTable(
11
- "component_metadata",
12
- {
13
- id: uuid("id").defaultRandom().notNull().primaryKey(),
14
- componentName: text("component_name").notNull(),
15
- version: text("version").notNull(),
16
- framework: text("framework").notNull(),
17
- filePath: text("file_path").notNull(),
18
- props: jsonb("props").$type<Record<string, any>>().notNull(),
19
- slots: jsonb("slots").$type<Record<string, any>>().notNull(),
20
- emits: jsonb("emits").$type<Record<string, any>>().notNull(),
21
- theme: jsonb("theme").$type<Record<string, any>>(),
22
- extractedAt: timestamp("extracted_at", { withTimezone: true }).defaultNow().notNull(),
23
- updatedAt: timestamp("updated_at", { withTimezone: true }).$onUpdate(() => new Date())
24
- },
25
- (table) => [
26
- uniqueIndex("component_metadata_name_version_idx").on(table.componentName, table.version)
27
- ]
28
- )
29
-
30
- export type ComponentMetadata = typeof componentMetadata.$inferSelect
31
- export type NewComponentMetadata = typeof componentMetadata.$inferInsert
@@ -1,15 +0,0 @@
1
- import { pgTable, text, timestamp, jsonb, index } from "drizzle-orm/pg-core"
2
-
3
- export const componentMetadataCache = pgTable(
4
- "component_metadata_cache",
5
- {
6
- componentName: text("component_name").primaryKey(),
7
- metadata: jsonb("metadata").$type<Record<string, any>>().notNull(),
8
- cacheKey: text("cache_key").notNull(),
9
- expiresAt: timestamp("expires_at", { withTimezone: true }).notNull()
10
- },
11
- (table) => [index("component_metadata_cache_expires_idx").on(table.expiresAt)]
12
- )
13
-
14
- export type ComponentMetadataCache = typeof componentMetadataCache.$inferSelect
15
- export type NewComponentMetadataCache = typeof componentMetadataCache.$inferInsert
@@ -1,19 +0,0 @@
1
- import { pgTable, text, timestamp, uuid, uniqueIndex } from "drizzle-orm/pg-core"
2
-
3
- export const componentVersions = pgTable(
4
- "component_versions",
5
- {
6
- id: uuid("id").defaultRandom().notNull().primaryKey(),
7
- componentName: text("component_name").notNull(),
8
- version: text("version").notNull(),
9
- filePath: text("file_path").notNull(),
10
- gitCommit: text("git_commit"),
11
- extractedAt: timestamp("extracted_at", { withTimezone: true }).defaultNow().notNull()
12
- },
13
- (table) => [
14
- uniqueIndex("component_versions_name_version_idx").on(table.componentName, table.version)
15
- ]
16
- )
17
-
18
- export type ComponentVersion = typeof componentVersions.$inferSelect
19
- export type NewComponentVersion = typeof componentVersions.$inferInsert
@@ -1,32 +0,0 @@
1
- import type { BaseBlock } from "../core/types/blocks"
2
-
3
- export function extractPlainTextFromBlocks(blocks: BaseBlock[], locale = "en"): string {
4
- const parts: string[] = []
5
-
6
- function walk(nodes: BaseBlock[]) {
7
- for (const node of nodes) {
8
- if (node.props) {
9
- if (typeof node.props.text === "object" && node.props.text !== null) {
10
- const locText = node.props.text[locale] || node.props.text.en
11
- if (locText) parts.push(String(locText))
12
- } else if (typeof node.props.text === "string") {
13
- parts.push(node.props.text)
14
- }
15
-
16
- if (typeof node.props.title === "object" && node.props.title !== null) {
17
- const locTitle = node.props.title[locale] || node.props.title.en
18
- if (locTitle) parts.push(String(locTitle))
19
- } else if (typeof node.props.title === "string") {
20
- parts.push(node.props.title)
21
- }
22
- }
23
-
24
- if (node.children?.length) {
25
- walk(node.children)
26
- }
27
- }
28
- }
29
-
30
- walk(blocks)
31
- return parts.join(" ")
32
- }
@@ -1,134 +0,0 @@
1
- import { eq, desc } from "drizzle-orm"
2
- import type {
3
- NewComponentMetadata
4
- } from "../schema/index.ts"
5
-
6
- export interface ComponentMeta {
7
- componentName: string
8
- version: string
9
- framework: string
10
- filePath: string
11
- props: Record<string, any>
12
- slots: Record<string, any>
13
- emits: Record<string, any>
14
- theme?: Record<string, any>
15
- }
16
-
17
- export interface ComponentDependencyRecord {
18
- sourceComponent: string
19
- targetComponent: string
20
- dependencyType: "uses" | "extends" | "related"
21
- }
22
-
23
- export class ComponentMetadataService {
24
- constructor(private db: any) {}
25
-
26
- async extractMetadata(componentPath: string): Promise<ComponentMeta> {
27
- const props: Record<string, any> = {}
28
- const slots: Record<string, any> = {}
29
- const emits: Record<string, any> = {}
30
-
31
- try {
32
- const content = await this.readComponentFile(componentPath)
33
- props.raw = content
34
- props.extractedAt = new Date().toISOString()
35
- } catch (e) {
36
- console.warn(`Failed to read component file: ${componentPath}`, e)
37
- }
38
-
39
- return {
40
- componentName: componentPath.split("/").pop()?.replace(/\.[^/.]+$/, "") || "unknown",
41
- version: "latest",
42
- framework: "astro",
43
- filePath: componentPath,
44
- props,
45
- slots,
46
- emits
47
- }
48
- }
49
-
50
- async storeMetadata(metadata: ComponentMeta): Promise<void> {
51
- const record: NewComponentMetadata = {
52
- componentName: metadata.componentName,
53
- version: metadata.version,
54
- framework: metadata.framework,
55
- filePath: metadata.filePath,
56
- props: metadata.props,
57
- slots: metadata.slots,
58
- emits: metadata.emits,
59
- theme: metadata.theme || {}
60
- }
61
-
62
- await this.db.insert(this.db.componentMetadata).values(record).onConflictDoUpdate({
63
- target: [this.db.componentMetadata.componentName, this.db.componentMetadata.version],
64
- set: {
65
- framework: record.framework,
66
- filePath: record.filePath,
67
- props: record.props,
68
- slots: record.slots,
69
- emits: record.emits,
70
- theme: record.theme,
71
- updatedAt: new Date()
72
- }
73
- })
74
- }
75
-
76
- async getMetadata(componentName: string): Promise<ComponentMeta | null> {
77
- const result = await this.db
78
- .select()
79
- .from(this.db.componentMetadata)
80
- .where(eq(this.db.componentMetadata.componentName, componentName))
81
- .orderBy(desc(this.db.componentMetadata.extractedAt))
82
- .limit(1)
83
-
84
- if (!result[0]) return null
85
-
86
- const row = result[0]
87
- return {
88
- componentName: row.componentName,
89
- version: row.version,
90
- framework: row.framework,
91
- filePath: row.filePath,
92
- props: row.props,
93
- slots: row.slots,
94
- emits: row.emits,
95
- theme: row.theme
96
- }
97
- }
98
-
99
- async updateMetadata(componentName: string): Promise<void> {
100
- const metadata = await this.getMetadata(componentName)
101
- if (!metadata) return
102
-
103
- const freshMeta = await this.extractMetadata(metadata.filePath)
104
- await this.storeMetadata(freshMeta)
105
- }
106
-
107
- async getDependencies(componentName: string): Promise<ComponentDependencyRecord[]> {
108
- const result = await this.db
109
- .select()
110
- .from(this.db.componentDependencies)
111
- .where(eq(this.db.componentDependencies.sourceComponent, componentName))
112
-
113
- return result.map((row: any) => ({
114
- sourceComponent: row.sourceComponent,
115
- targetComponent: row.targetComponent,
116
- dependencyType: row.dependencyType as "uses" | "extends" | "related"
117
- }))
118
- }
119
-
120
- async invalidateCache(componentName: string): Promise<void> {
121
- await this.db
122
- .delete(this.db.componentMetadataCache)
123
- .where(eq(this.db.componentMetadataCache.componentName, componentName))
124
- }
125
-
126
- private async readComponentFile(path: string): Promise<string> {
127
- try {
128
- const fs = await import("fs")
129
- return fs.readFileSync(path, "utf-8")
130
- } catch {
131
- return ""
132
- }
133
- }
134
- }