@canonical/design-system 0.2.2 → 0.2.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.
- package/data/concept/Foundations-Grid.ttl +9 -0
- package/data/concept/How-to-differentiate-components-variantsinheritance.ttl +9 -0
- package/data/concept/Indicating-required-fields-in-forms.ttl +9 -0
- package/data/concept/Question-mark-vs-information-icon.ttl +9 -0
- package/data/concepttype/Decision-guide.ttl +5 -0
- package/data/concepttype/Explanation.ttl +5 -0
- package/data/concepttype/How-to-guide.ttl +5 -0
- package/data/concepttype/Mental-model.ttl +5 -0
- package/data/concepttype/Reference.ttl +5 -0
- package/data/concepttype/Tutorial.ttl +5 -0
- package/definitions/ontology.ttl +35 -0
- package/package.json +1 -1
- package/skills/adoption-a1-styles/SKILL.md +111 -1
- package/skills/adoption-a2-components/SKILL.md +106 -1
- package/skills/adoption-a3-forms/SKILL.md +106 -1
- package/skills/anatomy-author/SKILL.md +102 -1
- package/skills/design-auditor/SKILL.md +100 -1
- package/skills/implement-component/SKILL.md +90 -1
- package/skills/specify-component/SKILL.md +100 -1
- package/skills/specify-pattern/SKILL.md +101 -1
- package/source.json +36 -1
- package/src/config/source.schema.json +27 -0
- package/src/config/types.ts +25 -0
- package/src/transform/rowFilter.tests.ts +100 -0
- package/src/transform/rowFilter.ts +55 -0
- package/src/transform/transform.ts +7 -1
package/src/config/types.ts
CHANGED
|
@@ -48,6 +48,26 @@ export type JsonLdContext = {
|
|
|
48
48
|
[columnName: string]: ContextValue | undefined;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Row-level include filter for a table transform. A row is emitted only when it
|
|
53
|
+
* satisfies EVERY declared condition (logical AND). Absent → every row is
|
|
54
|
+
* emitted (the historical behaviour). Use this to ingest only a named,
|
|
55
|
+
* non-empty subset of a large-but-mostly-stub table (e.g. Concepts, where most
|
|
56
|
+
* rows carry no `content` body yet).
|
|
57
|
+
*/
|
|
58
|
+
export interface RowFilter {
|
|
59
|
+
/**
|
|
60
|
+
* Keep only rows whose `column` (case-insensitively, after trimming) equals
|
|
61
|
+
* one of these values. The column is typically the name/title column.
|
|
62
|
+
*/
|
|
63
|
+
nameIn?: { column: string; values: string[] };
|
|
64
|
+
/**
|
|
65
|
+
* Keep only rows whose named column is non-empty (a trimmed length ≥
|
|
66
|
+
* `minLength`, default 1). Repeatable across columns — ALL must be non-empty.
|
|
67
|
+
*/
|
|
68
|
+
nonEmpty?: { column: string; minLength?: number }[];
|
|
69
|
+
}
|
|
70
|
+
|
|
51
71
|
/**
|
|
52
72
|
* Table transformation configuration
|
|
53
73
|
* Note: Column names in @context ARE the Coda column names
|
|
@@ -63,6 +83,11 @@ export interface TableTransform {
|
|
|
63
83
|
* treated as plain string literals (same semantics as a bare string in @context).
|
|
64
84
|
*/
|
|
65
85
|
classProperties?: Record<string, Record<string, string>>;
|
|
86
|
+
/**
|
|
87
|
+
* Optional include-filter: emit only the rows matching every condition.
|
|
88
|
+
* Absent → emit every row.
|
|
89
|
+
*/
|
|
90
|
+
rowFilter?: RowFilter;
|
|
66
91
|
}
|
|
67
92
|
|
|
68
93
|
/**
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type { RowFilter } from "../config/types.js";
|
|
3
|
+
import { rowPassesFilter } from "./rowFilter.js";
|
|
4
|
+
|
|
5
|
+
describe("rowPassesFilter", () => {
|
|
6
|
+
describe("nonEmpty", () => {
|
|
7
|
+
const filter: RowFilter = {
|
|
8
|
+
nonEmpty: [{ column: "content", minLength: 20 }],
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
it("keeps a row whose column meets the minimum length", () => {
|
|
12
|
+
const row = { name: "Foundations: Grid", content: "x".repeat(20) };
|
|
13
|
+
expect(rowPassesFilter(row, filter)).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("drops a row whose column is empty", () => {
|
|
17
|
+
const row = { name: "A stub concept", content: "" };
|
|
18
|
+
expect(rowPassesFilter(row, filter)).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("drops a row whose column is shorter than minLength", () => {
|
|
22
|
+
const row = { name: "Tiny", content: "too short" };
|
|
23
|
+
expect(rowPassesFilter(row, filter)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("drops a row whose column is missing", () => {
|
|
27
|
+
const row = { name: "No content column at all" };
|
|
28
|
+
expect(rowPassesFilter(row, filter)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("defaults minLength to 1 (any non-empty value passes)", () => {
|
|
32
|
+
const row = { content: "a" };
|
|
33
|
+
expect(rowPassesFilter(row, { nonEmpty: [{ column: "content" }] })).toBe(
|
|
34
|
+
true,
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("requires EVERY listed column to be non-empty (logical AND)", () => {
|
|
39
|
+
const both: RowFilter = {
|
|
40
|
+
nonEmpty: [{ column: "content" }, { column: "summary" }],
|
|
41
|
+
};
|
|
42
|
+
expect(rowPassesFilter({ content: "yes", summary: "" }, both)).toBe(
|
|
43
|
+
false,
|
|
44
|
+
);
|
|
45
|
+
expect(rowPassesFilter({ content: "yes", summary: "also" }, both)).toBe(
|
|
46
|
+
true,
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("nameIn", () => {
|
|
52
|
+
const filter: RowFilter = {
|
|
53
|
+
nameIn: {
|
|
54
|
+
column: "name",
|
|
55
|
+
values: ["Foundations: Grid", "SkeletonLoading"],
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
it("keeps a named row (case-insensitive, trimmed)", () => {
|
|
60
|
+
expect(rowPassesFilter({ name: " foundations: grid " }, filter)).toBe(
|
|
61
|
+
true,
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("drops a row not in the name list", () => {
|
|
66
|
+
expect(rowPassesFilter({ name: "Something else" }, filter)).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("lookup-object cells", () => {
|
|
71
|
+
it("reads a { id, name } lookup cell by its name", () => {
|
|
72
|
+
const filter: RowFilter = {
|
|
73
|
+
nameIn: { column: "type", values: ["Decision guide"] },
|
|
74
|
+
};
|
|
75
|
+
const row = { type: { id: "i-abc", name: "Decision guide" } };
|
|
76
|
+
expect(rowPassesFilter(row, filter)).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("combines nameIn AND nonEmpty (both must hold)", () => {
|
|
81
|
+
const filter: RowFilter = {
|
|
82
|
+
nameIn: { column: "name", values: ["Foundations: Grid"] },
|
|
83
|
+
nonEmpty: [{ column: "content", minLength: 20 }],
|
|
84
|
+
};
|
|
85
|
+
expect(
|
|
86
|
+
rowPassesFilter(
|
|
87
|
+
{ name: "Foundations: Grid", content: "x".repeat(20) },
|
|
88
|
+
filter,
|
|
89
|
+
),
|
|
90
|
+
).toBe(true);
|
|
91
|
+
// Right name, empty content → dropped.
|
|
92
|
+
expect(
|
|
93
|
+
rowPassesFilter({ name: "Foundations: Grid", content: "" }, filter),
|
|
94
|
+
).toBe(false);
|
|
95
|
+
// Non-empty content, wrong name → dropped.
|
|
96
|
+
expect(
|
|
97
|
+
rowPassesFilter({ name: "Other", content: "x".repeat(20) }, filter),
|
|
98
|
+
).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { RowFilter } from "../config/types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Coerce a normalized cell value to a comparable/measurable string.
|
|
5
|
+
*
|
|
6
|
+
* The provider normalizes lookups to `{ id, name }` and strips whole-value
|
|
7
|
+
* Markdown fences, so a cell is typically a string; a lookup object is reduced
|
|
8
|
+
* to its `name`. Anything else stringifies. Used by the row filter to read the
|
|
9
|
+
* name column and to measure a body column's length.
|
|
10
|
+
*
|
|
11
|
+
* @param value - The raw normalized cell value.
|
|
12
|
+
* @returns The cell as a trimmed string ("" for null/undefined).
|
|
13
|
+
*/
|
|
14
|
+
function cellText(value: unknown): string {
|
|
15
|
+
if (value === null || value === undefined) return "";
|
|
16
|
+
if (typeof value === "string") return value.trim();
|
|
17
|
+
if (
|
|
18
|
+
typeof value === "object" &&
|
|
19
|
+
"name" in (value as Record<string, unknown>)
|
|
20
|
+
) {
|
|
21
|
+
const name = (value as { name?: unknown }).name;
|
|
22
|
+
return typeof name === "string" ? name.trim() : "";
|
|
23
|
+
}
|
|
24
|
+
return String(value).trim();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Whether a row passes a table's {@link RowFilter} (logical AND over every
|
|
29
|
+
* declared condition). A row is kept when every condition holds; an absent
|
|
30
|
+
* filter keeps every row (the caller guards that case).
|
|
31
|
+
*
|
|
32
|
+
* @param row - The normalized row (column name → cell value).
|
|
33
|
+
* @param filter - The include-filter to apply.
|
|
34
|
+
* @returns True when the row should be emitted.
|
|
35
|
+
*/
|
|
36
|
+
export function rowPassesFilter(
|
|
37
|
+
row: Record<string, unknown>,
|
|
38
|
+
filter: RowFilter,
|
|
39
|
+
): boolean {
|
|
40
|
+
const { nameIn, nonEmpty } = filter;
|
|
41
|
+
|
|
42
|
+
if (nameIn) {
|
|
43
|
+
const actual = cellText(row[nameIn.column]).toLowerCase();
|
|
44
|
+
const wanted = nameIn.values.map((v) => v.trim().toLowerCase());
|
|
45
|
+
if (!wanted.includes(actual)) return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (nonEmpty) {
|
|
49
|
+
for (const { column, minLength } of nonEmpty) {
|
|
50
|
+
if (cellText(row[column]).length < (minLength ?? 1)) return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { TransformConfig } from "../config/types.js";
|
|
|
2
2
|
import { GraphStore, PrefixMap } from "../graph/index.js";
|
|
3
3
|
import expectedTables from "./expectedTables.js";
|
|
4
4
|
import resolveReferences from "./resolveReferences.js";
|
|
5
|
+
import { rowPassesFilter } from "./rowFilter.js";
|
|
5
6
|
import transformRow from "./transformRow.js";
|
|
6
7
|
import type {
|
|
7
8
|
InlineDataMap,
|
|
@@ -116,9 +117,14 @@ export default function transform(
|
|
|
116
117
|
prefixes.add(prefix, namespace);
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
// Transform each row
|
|
120
|
+
// Transform each row, skipping any excluded by an optional include-filter
|
|
121
|
+
// (e.g. Concepts narrowed to the named, non-empty subset).
|
|
122
|
+
const { rowFilter } = tableConfig;
|
|
120
123
|
let subjectCount = 0;
|
|
121
124
|
for (const row of tableData) {
|
|
125
|
+
if (rowFilter && !rowPassesFilter(row, rowFilter)) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
122
128
|
const subjectUri = transformRow(
|
|
123
129
|
row,
|
|
124
130
|
tableConfig,
|