@portabletext/astro 0.0.0 → 0.2.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 +17 -0
- package/LICENSE +15 -0
- package/README.md +338 -27
- package/components/Block.astro +36 -0
- package/components/HardBreak.astro +7 -0
- package/components/List.astro +24 -0
- package/components/ListItem.astro +9 -0
- package/components/Mark.astro +32 -0
- package/components/PortableText.astro +483 -0
- package/components/Text.astro +9 -0
- package/components/UnknownBlock.astro +7 -0
- package/components/UnknownList.astro +7 -0
- package/components/UnknownListItem.astro +7 -0
- package/components/UnknownMark.astro +7 -0
- package/components/UnknownType.astro +21 -0
- package/lib/astro.d.ts +9 -0
- package/lib/components.ts +4 -0
- package/lib/context.ts +21 -0
- package/lib/index.ts +2 -0
- package/lib/internal.ts +183 -0
- package/lib/types.ts +469 -0
- package/lib/utils.d.ts +26 -0
- package/lib/utils.ts +3 -0
- package/lib/warnings.ts +42 -0
- package/package.json +89 -7
package/lib/warnings.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {slotNames} from './internal'
|
|
2
|
+
import type {NodeType} from './types'
|
|
3
|
+
|
|
4
|
+
const getTemplate = (prop: string, type: string): string =>
|
|
5
|
+
`PortableText [components.${prop}] is missing "${type}"`
|
|
6
|
+
|
|
7
|
+
export const unknownTypeWarning = (type: string): string => getTemplate('type', type)
|
|
8
|
+
|
|
9
|
+
export const unknownMarkWarning = (markType: string): string => getTemplate('mark', markType)
|
|
10
|
+
|
|
11
|
+
export const unknownBlockWarning = (style: string): string => getTemplate('block', style)
|
|
12
|
+
|
|
13
|
+
export const unknownListWarning = (listItem: string): string => getTemplate('list', listItem)
|
|
14
|
+
|
|
15
|
+
export const unknownListItemWarning = (listStyle: string): string =>
|
|
16
|
+
getTemplate('listItem', listStyle)
|
|
17
|
+
|
|
18
|
+
export const unknownSlotWarning = (slotName: string): string =>
|
|
19
|
+
`PortableText slot "${slotName}" does not target a node type and will be ignored. ` +
|
|
20
|
+
`Expected ${slotNames.map((it) => `"${it}"`).join(', ')}, ` +
|
|
21
|
+
`optionally scoped to a type, e.g. "block:h1"`
|
|
22
|
+
|
|
23
|
+
export const ignoredChildrenWarning = (): string =>
|
|
24
|
+
'PortableText was given children that are not assigned to a slot, so they will be ignored. ' +
|
|
25
|
+
'Assign them to a node type, e.g. <fragment slot="block">'
|
|
26
|
+
|
|
27
|
+
export const getWarningMessage = (nodeType: NodeType, type: string) => {
|
|
28
|
+
const fncs = {
|
|
29
|
+
block: unknownBlockWarning,
|
|
30
|
+
list: unknownListWarning,
|
|
31
|
+
listItem: unknownListItemWarning,
|
|
32
|
+
mark: unknownMarkWarning,
|
|
33
|
+
type: unknownTypeWarning,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return fncs[nodeType](type)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function printWarning(message: string): void {
|
|
40
|
+
// oxlint-disable-next-line no-console
|
|
41
|
+
console.warn(message)
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,92 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/astro",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Render Portable Text with Astro",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
"astro",
|
|
7
|
+
"astro-component",
|
|
8
|
+
"portable-text",
|
|
9
|
+
"sanity",
|
|
10
|
+
"withastro"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/portabletext/astro-portabletext#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/portabletext/astro-portabletext/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
18
|
+
"contributors": [
|
|
19
|
+
"Tom Theisel <tom.theisel@gmail.com> (original author of astro-portabletext)"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+ssh://git@github.com/portabletext/astro-portabletext.git"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"CHANGELOG.md",
|
|
27
|
+
"components",
|
|
28
|
+
"lib"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"typesVersions": {
|
|
32
|
+
"*": {
|
|
33
|
+
"*": [
|
|
34
|
+
"lib/*"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
".": "./lib/index.ts",
|
|
40
|
+
"./components": "./lib/components.ts",
|
|
41
|
+
"./types": "./lib/types.ts",
|
|
42
|
+
"./utils": {
|
|
43
|
+
"types": "./lib/utils.d.ts",
|
|
44
|
+
"import": "./lib/utils.ts",
|
|
45
|
+
"default": "./lib/utils.ts"
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@portabletext/toolkit": "^6.0.0",
|
|
51
|
+
"@portabletext/types": "^4.0.2"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@astrojs/check": "^0.9.10",
|
|
55
|
+
"@changesets/changelog-github": "^0.7.0",
|
|
56
|
+
"@changesets/cli": "^2.31.1",
|
|
57
|
+
"@types/leaflet": "^1.9.21",
|
|
58
|
+
"@types/node": "^26.2.0",
|
|
59
|
+
"astro": "^7.2.1",
|
|
60
|
+
"cheerio": "^1.2.0",
|
|
61
|
+
"leaflet": "^1.9.4",
|
|
62
|
+
"oxfmt": "^0.63.0",
|
|
63
|
+
"oxlint": "^1.78.0",
|
|
64
|
+
"oxlint-tsgolint": "^7.0.2001",
|
|
65
|
+
"rimraf": "^5.0.1",
|
|
66
|
+
"typescript": "^6.0.3",
|
|
67
|
+
"vitest": "^4.1.10"
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"astro": ">=4.6.0"
|
|
71
|
+
},
|
|
72
|
+
"lint-staged": {
|
|
73
|
+
"*": [
|
|
74
|
+
"oxfmt"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"node": ">=22.12"
|
|
79
|
+
},
|
|
80
|
+
"scripts": {
|
|
81
|
+
"prebuild:demo": "pnpm clean",
|
|
82
|
+
"build:demo": "astro build --root demo",
|
|
83
|
+
"clean": "rimraf demo/dist test/dist",
|
|
84
|
+
"dev": "astro dev --root demo",
|
|
85
|
+
"format": "oxfmt .",
|
|
86
|
+
"lint": "oxlint",
|
|
87
|
+
"release": "changeset publish",
|
|
88
|
+
"start": "pnpm dev",
|
|
89
|
+
"test": "vitest",
|
|
90
|
+
"type-check": "astro check"
|
|
91
|
+
}
|
|
92
|
+
}
|