@tinacms/schema-tools 2.8.0 → 2.8.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/dist/index.d.ts +1 -0
- package/dist/index.js +32 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/util/headingLevels.d.ts +14 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2292,6 +2292,14 @@ const CONTENT_FORMATS = [
|
|
|
2292
2292
|
"yml",
|
|
2293
2293
|
"toml"
|
|
2294
2294
|
];
|
|
2295
|
+
const ALL_HEADING_LEVELS = [
|
|
2296
|
+
"h1",
|
|
2297
|
+
"h2",
|
|
2298
|
+
"h3",
|
|
2299
|
+
"h4",
|
|
2300
|
+
"h5",
|
|
2301
|
+
"h6"
|
|
2302
|
+
];
|
|
2295
2303
|
const parseZodError = ({ zodError }) => {
|
|
2296
2304
|
var _a, _b, _c, _d;
|
|
2297
2305
|
const errors = zodError.flatten((issue) => {
|
|
@@ -2804,7 +2812,29 @@ const validateSchema = ({ schema }) => {
|
|
|
2804
2812
|
throw new Error(e);
|
|
2805
2813
|
}
|
|
2806
2814
|
};
|
|
2815
|
+
const isHeadingLevel = (value) => {
|
|
2816
|
+
switch (value) {
|
|
2817
|
+
case "h1":
|
|
2818
|
+
case "h2":
|
|
2819
|
+
case "h3":
|
|
2820
|
+
case "h4":
|
|
2821
|
+
case "h5":
|
|
2822
|
+
case "h6":
|
|
2823
|
+
return true;
|
|
2824
|
+
default:
|
|
2825
|
+
return false;
|
|
2826
|
+
}
|
|
2827
|
+
};
|
|
2828
|
+
const normalizeHeadingLevels = (configured) => {
|
|
2829
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2830
|
+
for (const level of configured) {
|
|
2831
|
+
if (isHeadingLevel(level))
|
|
2832
|
+
seen.add(level);
|
|
2833
|
+
}
|
|
2834
|
+
return Array.from(seen);
|
|
2835
|
+
};
|
|
2807
2836
|
export {
|
|
2837
|
+
ALL_HEADING_LEVELS,
|
|
2808
2838
|
CONTENT_FORMATS,
|
|
2809
2839
|
NAMER,
|
|
2810
2840
|
TINA_HOST,
|
|
@@ -2812,6 +2842,8 @@ export {
|
|
|
2812
2842
|
TinaSchemaValidationError,
|
|
2813
2843
|
addNamespaceToSchema,
|
|
2814
2844
|
canonicalPath,
|
|
2845
|
+
isHeadingLevel,
|
|
2846
|
+
normalizeHeadingLevels,
|
|
2815
2847
|
normalizePath,
|
|
2816
2848
|
parseURL,
|
|
2817
2849
|
resolveField,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -255,6 +255,13 @@ export type DisplayOnlyField = BaseField & {
|
|
|
255
255
|
};
|
|
256
256
|
};
|
|
257
257
|
export type ToolbarOverrideType = 'heading' | 'link' | 'image' | 'quote' | 'ul' | 'ol' | 'code' | 'codeBlock' | 'bold' | 'italic' | 'strikethrough' | 'highlight' | 'raw' | 'embed' | 'mermaid' | 'table' | 'hr';
|
|
258
|
+
/**
|
|
259
|
+
* Heading node type as used by the rich-text editor. Mirrors
|
|
260
|
+
* `@udecode/plate-heading`'s `HEADING_KEYS` so consumers can pass these
|
|
261
|
+
* values straight through without translation.
|
|
262
|
+
*/
|
|
263
|
+
export type HeadingLevel = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
264
|
+
export declare const ALL_HEADING_LEVELS: readonly HeadingLevel[];
|
|
258
265
|
type RichTextAst = {
|
|
259
266
|
type: 'root';
|
|
260
267
|
children: Record<string, unknown>[];
|
|
@@ -274,6 +281,16 @@ export type RichTextField<WithNamespace extends boolean = false> = (FieldGeneric
|
|
|
274
281
|
toolbar?: ToolbarOverrideType[];
|
|
275
282
|
/**Default set to true */
|
|
276
283
|
showFloatingToolbar?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Restricts which heading levels are offered in the editor UI
|
|
286
|
+
* (headings dropdown, "Turn into" menu, slash menu, and markdown
|
|
287
|
+
* autoformat shortcuts like `## `). When omitted, all levels are
|
|
288
|
+
* available. UI-only — existing content with disallowed levels is
|
|
289
|
+
* rendered as-is.
|
|
290
|
+
*
|
|
291
|
+
* @example headingLevels: ['h1', 'h2', 'h3']
|
|
292
|
+
*/
|
|
293
|
+
headingLevels?: HeadingLevel[];
|
|
277
294
|
};
|
|
278
295
|
/**
|
|
279
296
|
* By default, Tina parses markdown with MDX, this is a more strict parser
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type HeadingLevel } from '../types/index';
|
|
2
|
+
/**
|
|
3
|
+
* Cast-free type guard for HeadingLevel. The exhaustive switch lets TS
|
|
4
|
+
* narrow `string` → `HeadingLevel` without an `as` cast, so it doubles
|
|
5
|
+
* as a runtime validator for untrusted (pure-JS) schema input.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isHeadingLevel: (value: string) => value is HeadingLevel;
|
|
8
|
+
/**
|
|
9
|
+
* Filters out values that aren't real HeadingLevels (a JS schema can
|
|
10
|
+
* declare anything at runtime), dedupes, and preserves the order the
|
|
11
|
+
* user wrote. Returns an empty array when no valid levels remain — an
|
|
12
|
+
* explicit `[]` therefore means "no headings", not "fall back to all".
|
|
13
|
+
*/
|
|
14
|
+
export declare const normalizeHeadingLevels: (configured: readonly string[]) => readonly HeadingLevel[];
|