feat: tighten types — MasterPageBlock JSON tags + *string, BlockNote []map[string]any
- Add JSON struct tags to MasterPageBlock and MasterPageDefinition - Change MasterPageBlock.HtmlContent from string to *string (nullable) - Change BlockNote renderer signatures from []any to []map[string]any - Move type assertions to JSON boundary in blocksFromRaw/inlineContentFromRaw Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
13d741979a
commit
43deff21f7
@ -47,20 +47,20 @@ type AIAction struct {
|
|||||||
|
|
||||||
// MasterPageBlock defines a block to add to a master page during provisioning.
|
// MasterPageBlock defines a block to add to a master page during provisioning.
|
||||||
type MasterPageBlock struct {
|
type MasterPageBlock struct {
|
||||||
BlockKey string
|
BlockKey string `json:"block_key"`
|
||||||
Title string
|
Title string `json:"title"`
|
||||||
Content map[string]any
|
Content map[string]any `json:"content"`
|
||||||
HtmlContent string
|
HtmlContent *string `json:"html_content"`
|
||||||
Slot string
|
Slot string `json:"slot"`
|
||||||
SortOrder int32
|
SortOrder int32 `json:"sort_order"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MasterPageDefinition defines a default master page that a plugin provisions.
|
// MasterPageDefinition defines a default master page that a plugin provisions.
|
||||||
type MasterPageDefinition struct {
|
type MasterPageDefinition struct {
|
||||||
Key string
|
Key string `json:"key"`
|
||||||
Title string
|
Title string `json:"title"`
|
||||||
PageTemplates []string
|
PageTemplates []string `json:"page_templates"`
|
||||||
Blocks []MasterPageBlock
|
Blocks []MasterPageBlock `json:"blocks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin status constants.
|
// Plugin status constants.
|
||||||
|
|||||||
@ -16,7 +16,7 @@ func BlockNoteToHTML(doc map[string]any) string {
|
|||||||
return renderBlocks(blocks)
|
return renderBlocks(blocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderBlocks(blocks []any) string {
|
func renderBlocks(blocks []map[string]any) string {
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
var currentListType string
|
var currentListType string
|
||||||
var listItems []map[string]any
|
var listItems []map[string]any
|
||||||
@ -47,11 +47,7 @@ func renderBlocks(blocks []any) string {
|
|||||||
currentListType = ""
|
currentListType = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, block := range blocks {
|
for _, blockMap := range blocks {
|
||||||
blockMap, ok := block.(map[string]any)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
blockType, _ := blockMap["type"].(string)
|
blockType, _ := blockMap["type"].(string)
|
||||||
|
|
||||||
if blockType == "bulletListItem" || blockType == "numberedListItem" {
|
if blockType == "bulletListItem" || blockType == "numberedListItem" {
|
||||||
@ -71,36 +67,40 @@ func renderBlocks(blocks []any) string {
|
|||||||
return sb.String()
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func inlineContentFromRaw(raw any) []any {
|
func inlineContentFromRaw(raw any) []map[string]any {
|
||||||
switch v := raw.(type) {
|
switch v := raw.(type) {
|
||||||
case []any:
|
case []any:
|
||||||
return v
|
items := make([]map[string]any, 0, len(v))
|
||||||
case []map[string]any:
|
|
||||||
items := make([]any, 0, len(v))
|
|
||||||
for _, item := range v {
|
for _, item := range v {
|
||||||
items = append(items, item)
|
if m, ok := item.(map[string]any); ok {
|
||||||
|
items = append(items, m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
|
case []map[string]any:
|
||||||
|
return v
|
||||||
case string:
|
case string:
|
||||||
if v == "" {
|
if v == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return []any{map[string]any{"type": "text", "text": v}}
|
return []map[string]any{{"type": "text", "text": v}}
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func blocksFromRaw(raw any) []any {
|
func blocksFromRaw(raw any) []map[string]any {
|
||||||
switch v := raw.(type) {
|
switch v := raw.(type) {
|
||||||
case []any:
|
case []any:
|
||||||
return v
|
items := make([]map[string]any, 0, len(v))
|
||||||
case []map[string]any:
|
|
||||||
items := make([]any, 0, len(v))
|
|
||||||
for _, item := range v {
|
for _, item := range v {
|
||||||
items = append(items, item)
|
if m, ok := item.(map[string]any); ok {
|
||||||
|
items = append(items, m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
|
case []map[string]any:
|
||||||
|
return v
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -265,14 +265,9 @@ func renderChildren(children any) string {
|
|||||||
return renderBlocks(blocks)
|
return renderBlocks(blocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderInlineContent(content []any) string {
|
func renderInlineContent(content []map[string]any) string {
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
for _, item := range content {
|
for _, itemMap := range content {
|
||||||
itemMap, ok := item.(map[string]any)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
itemType, _ := itemMap["type"].(string)
|
itemType, _ := itemMap["type"].(string)
|
||||||
text, _ := itemMap["text"].(string)
|
text, _ := itemMap["text"].(string)
|
||||||
styles, _ := itemMap["styles"].(map[string]any)
|
styles, _ := itemMap["styles"].(map[string]any)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user