@tinacms/schema-tools 2.8.0 → 2.8.2

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 CHANGED
@@ -4,3 +4,4 @@ export * from './validate';
4
4
  export * from './util/namer';
5
5
  export * from './util/parseURL';
6
6
  export * from './util/normalizePath';
7
+ export * from './util/headingLevels';
package/dist/index.js CHANGED
@@ -1627,7 +1627,7 @@ const parseURL = (url) => {
1627
1627
  if (!isTinaCloud) {
1628
1628
  return {
1629
1629
  branch: null,
1630
- isLocalClient: true,
1630
+ isLocalClient: false,
1631
1631
  clientId: null,
1632
1632
  host: params.host
1633
1633
  };
@@ -1642,7 +1642,7 @@ const parseURL = (url) => {
1642
1642
  const clientId = result == null ? void 0 : result.clientId;
1643
1643
  if (!branch || !clientId) {
1644
1644
  throw new Error(
1645
- `Invalid URL format provided. Expected: https://content.tinajs.io/<Version>/content/<ClientID>/github/<Branch> but but received ${url}`
1645
+ `Invalid URL format provided. Expected: https://content.tinajs.io/<Version>/content/<ClientID>/github/<Branch> but received ${url}`
1646
1646
  );
1647
1647
  }
1648
1648
  return {
@@ -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,
@@ -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
@@ -429,6 +446,14 @@ interface AuthHooks {
429
446
  }
430
447
  type AuthOptions = AuthHooks & AuthProvider;
431
448
  export interface Config<CMSCallback = undefined, FormifyCallback = undefined, DocumentCreatorCallback = undefined, Store = undefined, SearchClient = undefined> {
449
+ /**
450
+ * Points the admin UI at a custom/self-hosted content API instead of TinaCloud.
451
+ *
452
+ * Can be a relative URL, such as `/api/tina/gql`, or an absolute URL, such as
453
+ * `https://example.com/api/content`. When set, the admin UI will not show the
454
+ * Local Mode banner; Local Mode is only detected when this option is unset and
455
+ * the content API resolves to `localhost`.
456
+ */
432
457
  contentApiUrlOverride?: string;
433
458
  authProvider?: AuthProvider;
434
459
  admin?: {
@@ -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[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tinacms/schema-tools",
3
3
  "type": "module",
4
- "version": "2.8.0",
4
+ "version": "2.8.2",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
@@ -24,7 +24,7 @@
24
24
  "ts-jest": "^29.2.5",
25
25
  "typescript": "^5.7.3",
26
26
  "yup": "^1.6.1",
27
- "@tinacms/scripts": "1.6.1"
27
+ "@tinacms/scripts": "1.6.2"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": ">=16.14.0",