@crombolo/content 0.63.0 → 0.65.1
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/package.json +3 -3
- package/src/block-aliases.ts +18 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/content",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.65.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The rules every page and media write follows, whoever starts it: who may, where it may go, approvals, and what it announces. No transport.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@crombolo/core": "0.
|
|
33
|
-
"@crombolo/data": "0.
|
|
32
|
+
"@crombolo/core": "0.65.1",
|
|
33
|
+
"@crombolo/data": "0.65.1"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/block-aliases.ts
CHANGED
|
@@ -3,63 +3,35 @@
|
|
|
3
3
|
* its layout entry, that views and the `content block` commands pick it out
|
|
4
4
|
* by. Two blocks in one list may not share one.
|
|
5
5
|
*/
|
|
6
|
-
import type
|
|
6
|
+
import { blockLists, blockValueOf, type DocumentValue, everyBlock } from '@crombolo/core'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (isRecord(item) && Array.isArray(item.areas))
|
|
20
|
-
for (const area of item.areas) if (isRecord(area)) walk(area.items)
|
|
21
|
-
}
|
|
22
|
-
for (const items of Object.values(value.layout)) walk(items)
|
|
23
|
-
return lists
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** The block values inside a block value's own elements, for a list within a block. */
|
|
27
|
-
function nested(value: unknown): unknown[] {
|
|
28
|
-
if (!isRecord(value)) return []
|
|
29
|
-
return ['contentData', 'settingsData'].flatMap((name) =>
|
|
30
|
-
Array.isArray(value[name])
|
|
31
|
-
? (value[name] as unknown[]).flatMap((data) =>
|
|
32
|
-
isRecord(data) && Array.isArray(data.values)
|
|
33
|
-
? data.values.flatMap((v) => (isRecord(v) ? [v.value] : []))
|
|
34
|
-
: [],
|
|
35
|
-
)
|
|
36
|
-
: [],
|
|
37
|
-
)
|
|
8
|
+
/**
|
|
9
|
+
* Each list of blocks in a value, through the one reader (story 345): its own,
|
|
10
|
+
* its grid areas', and those in its blocks' own values, at any depth.
|
|
11
|
+
*/
|
|
12
|
+
function lists(value: unknown) {
|
|
13
|
+
const out = blockLists(value)
|
|
14
|
+
for (const block of everyBlock(value))
|
|
15
|
+
for (const data of [block.content, block.settings])
|
|
16
|
+
for (const own of data?.values ?? [])
|
|
17
|
+
out.push(...blockLists(blockValueOf(own.editorAlias ?? '', own.value) ?? own.value))
|
|
18
|
+
return out
|
|
38
19
|
}
|
|
39
20
|
|
|
40
21
|
/** The first alias two blocks of one list share, with the property it is in. */
|
|
41
22
|
export function duplicateBlockAlias(
|
|
42
23
|
values: readonly DocumentValue[],
|
|
43
24
|
): { property: string; alias: string } | undefined {
|
|
44
|
-
const
|
|
45
|
-
for (const list of
|
|
25
|
+
for (const v of values) {
|
|
26
|
+
for (const list of lists(v.value)) {
|
|
46
27
|
const seen = new Set<string>()
|
|
47
|
-
for (const
|
|
48
|
-
if (
|
|
49
|
-
const alias =
|
|
50
|
-
if (seen.has(alias)) return
|
|
28
|
+
for (const { layout } of list) {
|
|
29
|
+
if (typeof layout.alias !== 'string' || !layout.alias) continue
|
|
30
|
+
const alias = layout.alias.toLowerCase()
|
|
31
|
+
if (seen.has(alias)) return { property: v.alias, alias: layout.alias }
|
|
51
32
|
seen.add(alias)
|
|
52
33
|
}
|
|
53
34
|
}
|
|
54
|
-
for (const inner of nested(value)) {
|
|
55
|
-
const found = inValue(inner)
|
|
56
|
-
if (found) return found
|
|
57
|
-
}
|
|
58
|
-
return undefined
|
|
59
|
-
}
|
|
60
|
-
for (const v of values) {
|
|
61
|
-
const alias = inValue(v.value)
|
|
62
|
-
if (alias) return { property: v.alias, alias }
|
|
63
35
|
}
|
|
64
36
|
return undefined
|
|
65
37
|
}
|