inlaycms 0.1.0 → 0.3.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.
Files changed (121) hide show
  1. package/README.md +344 -8
  2. package/assets/admin/admin.css +1 -1
  3. package/assets/admin/admin.js +1 -1
  4. package/assets/admin/editor.js +59 -44
  5. package/dist/adapters/admin/screens/redirects.js +12 -3
  6. package/dist/adapters/admin/views/layout.js +27 -7
  7. package/dist/adapters/cli/remote.js +9 -1
  8. package/dist/adapters/mcp/tools/redirects.js +16 -2
  9. package/dist/adapters/site/assets.d.ts +11 -0
  10. package/dist/adapters/site/assets.js +71 -0
  11. package/dist/adapters/site/cache.d.ts +2 -1
  12. package/dist/adapters/site/cache.js +6 -1
  13. package/dist/adapters/site/context.d.ts +6 -0
  14. package/dist/adapters/site/context.js +38 -13
  15. package/dist/adapters/site/head.d.ts +30 -7
  16. package/dist/adapters/site/head.js +145 -20
  17. package/dist/adapters/site/headers.d.ts +5 -0
  18. package/dist/adapters/site/headers.js +31 -0
  19. package/dist/adapters/site/plugin.d.ts +2 -0
  20. package/dist/adapters/site/plugin.js +32 -9
  21. package/dist/adapters/site/public.js +7 -24
  22. package/dist/adapters/site/render.d.ts +5 -0
  23. package/dist/adapters/site/render.js +23 -8
  24. package/dist/adapters/site/routes.d.ts +6 -0
  25. package/dist/adapters/site/routes.js +8 -3
  26. package/dist/adapters/site/seo.d.ts +20 -0
  27. package/dist/adapters/site/seo.js +45 -0
  28. package/dist/adapters/site/sitemap.d.ts +1 -1
  29. package/dist/adapters/site/sitemap.js +1 -1
  30. package/dist/config.js +3 -2
  31. package/dist/core/agent/format.js +1 -1
  32. package/dist/core/agent/schema.js +3 -0
  33. package/dist/core/boot.js +7 -0
  34. package/dist/core/check.js +6 -1
  35. package/dist/core/content/dry-run.d.ts +7 -6
  36. package/dist/core/content/dry-run.js +8 -8
  37. package/dist/core/content/publish.d.ts +1 -1
  38. package/dist/core/content/publish.js +5 -3
  39. package/dist/core/content/read.d.ts +3 -0
  40. package/dist/core/content/reader.js +3 -2
  41. package/dist/core/content/refs.js +1 -1
  42. package/dist/core/content/search.js +2 -2
  43. package/dist/core/content/shipped-images.d.ts +32 -0
  44. package/dist/core/content/shipped-images.js +62 -0
  45. package/dist/core/content/shipped-input.d.ts +9 -3
  46. package/dist/core/content/shipped-input.js +165 -28
  47. package/dist/core/content/shipped.js +8 -3
  48. package/dist/core/content/validate.js +7 -1
  49. package/dist/core/core.d.ts +5 -1
  50. package/dist/core/core.js +5 -4
  51. package/dist/core/db/connection.d.ts +6 -0
  52. package/dist/core/db/connection.js +13 -1
  53. package/dist/core/db/migrate.js +2 -0
  54. package/dist/core/db/migrations/0007_published_at.d.ts +3 -0
  55. package/dist/core/db/migrations/0007_published_at.js +16 -0
  56. package/dist/core/db/schema.d.ts +1 -0
  57. package/dist/core/export/export.js +3 -1
  58. package/dist/core/export/format.d.ts +8 -1
  59. package/dist/core/export/format.js +3 -2
  60. package/dist/core/export/read.js +7 -0
  61. package/dist/core/export/stage.d.ts +1 -1
  62. package/dist/core/export/stage.js +24 -1
  63. package/dist/core/fields/builtins.d.ts +28 -0
  64. package/dist/core/fields/builtins.js +103 -11
  65. package/dist/core/fields/define.d.ts +6 -0
  66. package/dist/core/fields/widgets.d.ts +7 -0
  67. package/dist/core/fields/widgets.js +76 -28
  68. package/dist/core/messages/en.d.ts +70 -6
  69. package/dist/core/messages/en.js +70 -6
  70. package/dist/core/redirects/collapse.d.ts +17 -1
  71. package/dist/core/redirects/collapse.js +19 -3
  72. package/dist/core/redirects/redirects.d.ts +13 -12
  73. package/dist/core/redirects/redirects.js +141 -53
  74. package/dist/core/redirects/rule.d.ts +25 -0
  75. package/dist/core/redirects/rule.js +55 -0
  76. package/dist/core/registry/define.d.ts +40 -0
  77. package/dist/core/registry/define.js +3 -0
  78. package/dist/core/registry/registry.d.ts +21 -0
  79. package/dist/core/registry/registry.js +114 -6
  80. package/dist/core/registry/render.d.ts +37 -1
  81. package/dist/core/registry/route.d.ts +4 -0
  82. package/dist/core/release/bundle.js +30 -5
  83. package/dist/core/release/manifest.d.ts +14 -0
  84. package/dist/core/release/manifest.js +42 -17
  85. package/dist/core/release/markdown-file.d.ts +21 -0
  86. package/dist/core/release/markdown-file.js +172 -0
  87. package/dist/core/release/pack.js +2 -2
  88. package/dist/core/release/read.js +4 -1
  89. package/dist/core/release/site-dir.d.ts +4 -0
  90. package/dist/core/release/site-dir.js +8 -0
  91. package/dist/core/report.d.ts +8 -2
  92. package/dist/core/richtext/html.d.ts +3 -1
  93. package/dist/core/richtext/html.js +16 -4
  94. package/dist/core/richtext/inline.d.ts +22 -0
  95. package/dist/core/richtext/inline.js +33 -0
  96. package/dist/core/richtext/markdown.d.ts +16 -1
  97. package/dist/core/richtext/markdown.js +137 -14
  98. package/dist/core/richtext/schema.d.ts +16 -4
  99. package/dist/core/richtext/schema.js +71 -1
  100. package/dist/core/site/live.d.ts +1 -0
  101. package/dist/core/site/live.js +1 -0
  102. package/dist/core/site/paths.d.ts +6 -0
  103. package/dist/core/site/paths.js +13 -0
  104. package/dist/core/site/resolve.d.ts +1 -1
  105. package/dist/core/site/resolve.js +119 -30
  106. package/dist/core/site/sitemap.d.ts +1 -1
  107. package/dist/core/site/sitemap.js +4 -0
  108. package/dist/core/types.d.ts +28 -3
  109. package/dist/host/app.d.ts +5 -0
  110. package/dist/host/app.js +8 -0
  111. package/dist/host/dev.js +3 -7
  112. package/dist/host/diff.d.ts +19 -1
  113. package/dist/host/diff.js +32 -2
  114. package/dist/index.d.ts +2 -2
  115. package/dist/markdown-modules.d.ts +8 -0
  116. package/dist/markdown-modules.js +1 -0
  117. package/dist/site.d.ts +8 -3
  118. package/dist/site.js +6 -0
  119. package/dist/testing.d.ts +22 -0
  120. package/dist/testing.js +155 -0
  121. package/package.json +6 -1
@@ -71,7 +71,7 @@ function atLineStart(out) {
71
71
  /** Characters as numeric character references, which read back as themselves. */
72
72
  const encodeChars = (s) => Array.from(s, (c) => `&#${c.codePointAt(0)};`).join('');
73
73
  /** URL as a link destination: `<…>` when it has spaces or brackets, escaped so markdown-it gives it back unchanged. */
74
- function destination(url) {
74
+ export function markdownDestination(url) {
75
75
  const entity = /&(?=#?[0-9A-Za-z]+;)/g;
76
76
  if (/[\s()<>]/.test(url))
77
77
  return '<' + url.replace(/[\\<>]/g, '\\$&').replace(entity, '\\&') + '>';
@@ -208,7 +208,9 @@ class State extends StateBase {
208
208
  out = out
209
209
  .replace(/^(\d{1,9})([.)])(?=[ \t]|$)/, '$1\\$2')
210
210
  .replace(/^\+(?=[ \t]|$)/, '\\+')
211
- .replace(/^=/, '\\=');
211
+ .replace(/^=/, '\\=')
212
+ // After a line break, a line starting with these could be read as a table's delimiter row.
213
+ .replace(/^[:|]/, '\\$&');
212
214
  }
213
215
  // A bare `_` is safe only between two letters or digits; next to anything else it could open or close.
214
216
  out = out.replace(/\\[\s\S]|_/g, (m, at, all) => m === '_' && !(/[A-Za-z0-9]/.test(all[at - 1] ?? '') && /[A-Za-z0-9]/.test(all[at + 1] ?? '')) ? '\\_' : m);
@@ -531,7 +533,26 @@ function separateList(state, node) {
531
533
  if ((empty || start !== 1) && state.closed && state.closed.type !== node.type)
532
534
  state.flushClose(2);
533
535
  }
536
+ /** A table cell's content on one line, written as any paragraph is, with each `|` escaped. */
537
+ function cellMarkdown(cell) {
538
+ const state = new State(nodes, marks, SERIALIZER_OPTIONS);
539
+ state.renderContent(richTextSchema.nodes.doc.create(null, cell.content));
540
+ return oneLine(state.result()).trim().replace(/\|/g, '\\|');
541
+ }
534
542
  const nodes = {
543
+ table(state, node) {
544
+ node.forEach((row, _, r) => {
545
+ const cells = [];
546
+ row.forEach((cell) => cells.push(cellMarkdown(cell)));
547
+ state.write(`| ${cells.join(' | ')} |`);
548
+ state.ensureNewLine();
549
+ if (r === 0) {
550
+ state.write(`| ${cells.map(() => '---').join(' | ')} |`);
551
+ state.ensureNewLine();
552
+ }
553
+ });
554
+ state.closeBlock(node);
555
+ },
535
556
  blockquote(state, node) {
536
557
  state.wrapBlock('> ', null, node, () => state.renderContent(node));
537
558
  },
@@ -635,7 +656,7 @@ const marks = {
635
656
  open: '[',
636
657
  close: (_state, mark) => {
637
658
  const href = typeof mark.attrs.document === 'string' ? DOCUMENT_PREFIX + mark.attrs.document : String(mark.attrs.href);
638
- return `](${destination(href)})`;
659
+ return `](${markdownDestination(href)})`;
639
660
  },
640
661
  mixable: true,
641
662
  },
@@ -655,9 +676,11 @@ const tokenizer = new MarkdownIt('commonmark', { html: false, linkify: false, ty
655
676
  tokenizer.validateLink = () => true;
656
677
  tokenizer.normalizeLink = (url) => url;
657
678
  tokenizer.normalizeLinkText = (url) => url;
679
+ tokenizer.enable('table');
658
680
  /**
659
681
  * Reads the syntax that CommonMark keeps as plain text but writers mean as formatting rich text can't hold:
660
- * HTML, tables and strikethrough. Used only to refuse it, so it isn't silently stored as literal characters.
682
+ * HTML and strikethrough. Used only to refuse it, so it isn't silently stored as literal characters.
683
+ * Tables are read here too, so syntax inside a cell is found as it is anywhere else.
661
684
  */
662
685
  const detector = new MarkdownIt('commonmark', { html: true, linkify: false, typographer: false }).enable([
663
686
  'table',
@@ -710,6 +733,43 @@ tokenizer.core.ruler.after('block', 'inlay_used_references', (state) => {
710
733
  if (env.definitions)
711
734
  env.inline = true;
712
735
  });
736
+ // Table cells hold a paragraph, as the schema requires: each cell's inline content gets one.
737
+ tokenizer.core.ruler.after('inline', 'inlay_table_cells', (state) => {
738
+ const out = [];
739
+ let cell = false;
740
+ for (const tok of state.tokens) {
741
+ if (cell && tok.type === 'inline') {
742
+ const open = new state.Token('paragraph_open', 'p', 1);
743
+ const close = new state.Token('paragraph_close', 'p', -1);
744
+ open.level = close.level = tok.level;
745
+ tok.level++;
746
+ out.push(open, tok, close);
747
+ }
748
+ else {
749
+ out.push(tok);
750
+ }
751
+ cell = tok.type === 'th_open' || tok.type === 'td_open';
752
+ }
753
+ state.tokens = out;
754
+ });
755
+ /** Image tokens, at any depth, whose target is named in `env.images` point at that library image instead. */
756
+ tokenizer.core.ruler.push('inlay_images', (state) => {
757
+ const images = state.env.images;
758
+ if (!images || images.size === 0)
759
+ return;
760
+ const rewrite = (tokens) => {
761
+ for (const tok of tokens) {
762
+ if (tok.type === 'image') {
763
+ const id = images.get(tok.attrGet('src') ?? '');
764
+ if (id !== undefined)
765
+ tok.attrSet('src', MEDIA_PREFIX + id);
766
+ }
767
+ if (tok.children)
768
+ rewrite(tok.children);
769
+ }
770
+ };
771
+ rewrite(state.tokens);
772
+ });
713
773
  /** An image's alt as plain text, the way a browser shows it. */
714
774
  function altText(children) {
715
775
  return (children ?? [])
@@ -739,6 +799,12 @@ const parser = new MarkdownParser(richTextSchema, tokenizer, {
739
799
  }),
740
800
  },
741
801
  hardbreak: { node: 'hardBreak' },
802
+ table: { block: 'table' },
803
+ thead: { ignore: true },
804
+ tbody: { ignore: true },
805
+ tr: { block: 'tableRow' },
806
+ th: { block: 'tableHeader' },
807
+ td: { block: 'tableCell' },
742
808
  em: { mark: 'italic' },
743
809
  strong: { mark: 'bold' },
744
810
  link: {
@@ -777,6 +843,7 @@ const TOKEN_FEATURE = {
777
843
  link_open: 'link',
778
844
  image: 'image',
779
845
  hardbreak: 'hardBreak',
846
+ table_open: 'table',
780
847
  };
781
848
  const TOKEN_UNSUPPORTED = {
782
849
  code_inline: 'code',
@@ -801,15 +868,25 @@ const PLAIN_TOKENS = new Set([
801
868
  'text',
802
869
  'text_special',
803
870
  'softbreak',
871
+ 'table_close',
872
+ 'thead_open',
873
+ 'thead_close',
874
+ 'tbody_open',
875
+ 'tbody_close',
876
+ 'tr_open',
877
+ 'tr_close',
878
+ 'th_open',
879
+ 'th_close',
880
+ 'td_open',
881
+ 'td_close',
804
882
  ]);
805
883
  /** Token types of `detector` for syntax that would otherwise be kept as literal text. */
806
884
  const TOKEN_LITERAL = {
807
885
  html_block: 'html',
808
886
  html_inline: 'html',
809
- table_open: 'table',
810
887
  s_open: 'strike',
811
888
  };
812
- /** One problem per line and kind for HTML, tables and strikethrough in `markdown`. */
889
+ /** One problem per line and kind for HTML and strikethrough in `markdown`. */
813
890
  function literalSyntaxProblems(markdown) {
814
891
  const problems = [];
815
892
  const seen = new Set();
@@ -847,7 +924,7 @@ function findProblems(tokens, opts, env) {
847
924
  problems.push({ code, line, message: t(id, { line, ...params }) });
848
925
  };
849
926
  const allowed = (f) => opts.features.includes(f);
850
- const check = (tok, line, inHeading) => {
927
+ const check = (tok, line, inHeading, inCell) => {
851
928
  const unsupported = TOKEN_UNSUPPORTED[tok.type];
852
929
  if (unsupported)
853
930
  return add('unsupported', line, 'richtext.unsupported', { feature: feature(unsupported) });
@@ -870,6 +947,9 @@ function findProblems(tokens, opts, env) {
870
947
  if (inHeading && (name === 'image' || name === 'hardBreak')) {
871
948
  return add('unsupported', line, 'richtext.headingContent', { feature: feature(name) });
872
949
  }
950
+ if (inCell && (name === 'image' || name === 'hardBreak')) {
951
+ return add('unsupported', line, 'richtext.tableCell', { feature: feature(name) });
952
+ }
873
953
  if (!allowed(name))
874
954
  return add('not_allowed', line, 'richtext.notAllowed', { feature: feature(name) });
875
955
  if (name === 'link' || name === 'image') {
@@ -888,34 +968,41 @@ function findProblems(tokens, opts, env) {
888
968
  }
889
969
  };
890
970
  /** Walks inline tokens; line breaks move the line on, including those inside an image's alt. */
891
- const walkInline = (children, line, inHeading, inAlt) => {
971
+ const walkInline = (children, line, inHeading, inCell, inAlt) => {
892
972
  for (const child of children) {
893
973
  if (!inAlt)
894
- check(child, line, inHeading);
974
+ check(child, line, inHeading, inCell);
895
975
  if (child.type === 'softbreak' || child.type === 'hardbreak')
896
976
  line++;
897
977
  if (child.type === 'image' && child.children)
898
- line = walkInline(child.children, line, inHeading, true);
978
+ line = walkInline(child.children, line, inHeading, inCell, true);
899
979
  }
900
980
  return line;
901
981
  };
902
982
  let line = 1;
903
983
  let inHeading = false;
984
+ let inCell = false;
904
985
  for (const tok of tokens) {
905
986
  if (tok.map)
906
987
  line = tok.map[0] + 1;
907
988
  if (tok.type === 'inline') {
908
- walkInline(tok.children ?? [], line, inHeading, false);
989
+ walkInline(tok.children ?? [], line, inHeading, inCell, false);
909
990
  continue;
910
991
  }
911
992
  if (tok.type === 'heading_open')
912
993
  inHeading = true;
913
994
  if (tok.type === 'heading_close')
914
995
  inHeading = false;
996
+ if (tok.type === 'th_open' || tok.type === 'td_open')
997
+ inCell = true;
998
+ if (tok.type === 'th_close' || tok.type === 'td_close')
999
+ inCell = false;
915
1000
  if ((tok.type === 'blockquote_open' || tok.type === 'list_item_open') && tok.level + 1 >= MAX_NESTING) {
916
1001
  add('unsupported', line, 'richtext.tooDeep', {});
917
1002
  }
918
- check(tok, line, false);
1003
+ if (tok.type === 'table_open' && tok.level > 0)
1004
+ add('unsupported', line, 'richtext.tableNested', {});
1005
+ check(tok, line, false, false);
919
1006
  }
920
1007
  // A definition no link uses would vanish; one that is used ends up in its links.
921
1008
  for (const def of env.definitions ?? []) {
@@ -925,11 +1012,44 @@ function findProblems(tokens, opts, env) {
925
1012
  }
926
1013
  return problems.sort((a, b) => a.line - b.line);
927
1014
  }
1015
+ /** The line (from 1) each top-level block of `markdown` starts on. */
1016
+ export function blockLines(markdown) {
1017
+ return tokenizer
1018
+ .parse(markdown, {})
1019
+ .flatMap((tok) => (tok.level === 0 && tok.nesting !== -1 && tok.map ? [tok.map[0] + 1] : []));
1020
+ }
1021
+ /**
1022
+ * Every image target in `markdown`, in order, as markdown-it reads it (escapes and `<…>` undone), with its line,
1023
+ * counted the way problems are. Images inside another image's alt, which become alt text, aren't listed.
1024
+ */
1025
+ export function markdownImages(markdown) {
1026
+ const found = [];
1027
+ const walk = (children, line, inAlt) => {
1028
+ for (const child of children) {
1029
+ if (child.type === 'image' && !inAlt)
1030
+ found.push({ src: child.attrGet('src') ?? '', line });
1031
+ if (child.type === 'softbreak' || child.type === 'hardbreak')
1032
+ line++;
1033
+ if (child.type === 'image' && child.children)
1034
+ line = walk(child.children, line, true);
1035
+ }
1036
+ return line;
1037
+ };
1038
+ let line = 1;
1039
+ for (const tok of tokenizer.parse(markdown, {})) {
1040
+ if (tok.map)
1041
+ line = tok.map[0] + 1;
1042
+ if (tok.type === 'inline')
1043
+ walk(tok.children ?? [], line, false);
1044
+ }
1045
+ return found;
1046
+ }
928
1047
  /**
929
1048
  * Reads CommonMark into a normalized rich text doc allowed by `opts`. Anything the
930
1049
  * format or the field can't hold is reported as a line-numbered problem. Never throws.
1050
+ * An image whose target is a key of `extra.images` reads as the library image it maps to.
931
1051
  */
932
- export function markdownToRichText(markdown, opts) {
1052
+ export function markdownToRichText(markdown, opts, extra = {}) {
933
1053
  const options = { ...DEFAULT_RICH_TEXT, ...opts };
934
1054
  const unreadable = () => ({
935
1055
  ok: false,
@@ -937,11 +1057,14 @@ export function markdownToRichText(markdown, opts) {
937
1057
  });
938
1058
  try {
939
1059
  const env = trackingEnv();
1060
+ if (extra.images)
1061
+ env.images = extra.images;
940
1062
  const tokens = tokenizer.parse(markdown, env);
941
1063
  const problems = [...findProblems(tokens, options, env), ...literalSyntaxProblems(markdown)];
942
1064
  if (problems.length > 0)
943
1065
  return { ok: false, problems: problems.sort((a, b) => a.line - b.line) };
944
- const node = parser.parse(markdown);
1066
+ const parseEnv = extra.images ? { images: extra.images } : {};
1067
+ const node = parser.parse(markdown, parseEnv);
945
1068
  const parsed = parseRichText(node.toJSON(), options);
946
1069
  return parsed.ok ? parsed : unreadable();
947
1070
  }
@@ -1,6 +1,6 @@
1
1
  import { Schema } from 'prosemirror-model';
2
2
  import type { ContentRef } from '../types.js';
3
- export declare const RICH_TEXT_FEATURES: readonly ['heading', 'bold', 'italic', 'link', 'bulletList', 'orderedList', 'blockquote', 'image', 'hardBreak'];
3
+ export declare const RICH_TEXT_FEATURES: readonly ['heading', 'bold', 'italic', 'link', 'bulletList', 'orderedList', 'blockquote', 'image', 'hardBreak', 'table'];
4
4
  export type RichTextFeature = (typeof RICH_TEXT_FEATURES)[number];
5
5
  export interface RichTextOptions {
6
6
  features: readonly RichTextFeature[];
@@ -67,14 +67,26 @@ export type RichTextBlockquote = {
67
67
  type: 'blockquote';
68
68
  content: RichTextBlock[];
69
69
  };
70
- export type RichTextBlock = RichTextParagraph | RichTextHeading | RichTextBulletList | RichTextOrderedList | RichTextBlockquote;
71
- export type RichTextNode = RichTextBlock | RichTextListItem | RichTextInline;
70
+ export type RichTextTableCell = {
71
+ type: 'tableHeader' | 'tableCell';
72
+ content: [RichTextParagraph];
73
+ };
74
+ export type RichTextTableRow = {
75
+ type: 'tableRow';
76
+ content: RichTextTableCell[];
77
+ };
78
+ export type RichTextTable = {
79
+ type: 'table';
80
+ content: RichTextTableRow[];
81
+ };
82
+ export type RichTextBlock = RichTextParagraph | RichTextHeading | RichTextBulletList | RichTextOrderedList | RichTextBlockquote | RichTextTable;
83
+ export type RichTextNode = RichTextBlock | RichTextListItem | RichTextTableRow | RichTextTableCell | RichTextInline;
72
84
  export type RichTextDoc = {
73
85
  type: 'doc';
74
86
  content: RichTextNode[];
75
87
  };
76
88
  /** Tiptap's node and mark names. The mark order is the canonical order of marks on a node. */
77
- export declare const richTextSchema: Schema<"blockquote" | "bulletList" | "doc" | "hardBreak" | "heading" | "image" | "listItem" | "orderedList" | "paragraph" | "text", "bold" | "italic" | "link">;
89
+ export declare const richTextSchema: Schema<"blockquote" | "bulletList" | "doc" | "hardBreak" | "heading" | "image" | "listItem" | "orderedList" | "paragraph" | "table" | "tableCell" | "tableHeader" | "tableRow" | "text", "bold" | "italic" | "link">;
78
90
  /**
79
91
  * A link address rich text can hold: a safe URL without control characters, which
80
92
  * Markdown can't carry and so wouldn't read back.
@@ -12,6 +12,7 @@ export const RICH_TEXT_FEATURES = [
12
12
  'blockquote',
13
13
  'image',
14
14
  'hardBreak',
15
+ 'table',
15
16
  ];
16
17
  export const DEFAULT_RICH_TEXT = { features: RICH_TEXT_FEATURES, headings: [2, 3, 4] };
17
18
  /** Tiptap's node and mark names. The mark order is the canonical order of marks on a node. */
@@ -24,6 +25,10 @@ export const richTextSchema = new Schema({
24
25
  orderedList: { group: 'block', content: 'listItem+', attrs: { start: { default: 1 } } },
25
26
  listItem: { content: 'paragraph block*' },
26
27
  blockquote: { group: 'block', content: 'block+' },
28
+ table: { group: 'block', content: 'tableRow+' },
29
+ tableRow: { content: '(tableHeader | tableCell)+' },
30
+ tableHeader: { content: 'paragraph' },
31
+ tableCell: { content: 'paragraph' },
27
32
  text: { group: 'inline' },
28
33
  hardBreak: { group: 'inline', inline: true },
29
34
  image: { group: 'inline', inline: true, attrs: { media: {}, alt: { default: null } } },
@@ -41,6 +46,7 @@ const NODE_FEATURE = {
41
46
  blockquote: 'blockquote',
42
47
  image: 'image',
43
48
  hardBreak: 'hardBreak',
49
+ table: 'table',
44
50
  };
45
51
  const LEAVES = new Set(['text', 'hardBreak', 'image']);
46
52
  const HEX64 = /^[0-9a-f]{64}$/;
@@ -152,6 +158,67 @@ function cleanNode(raw, opts) {
152
158
  out.content = content;
153
159
  return out;
154
160
  }
161
+ /** A cell: one paragraph, several joined with a space; no image or line break. */
162
+ function cleanCell(raw, type, opts) {
163
+ if (!isRecord(raw) || (raw.type !== 'tableHeader' && raw.type !== 'tableCell'))
164
+ reject();
165
+ if (absent(raw.content))
166
+ return { type, content: [{ type: 'paragraph' }] };
167
+ if (!Array.isArray(raw.content))
168
+ reject();
169
+ const inline = [];
170
+ for (const child of raw.content) {
171
+ if (!isRecord(child) || child.type !== 'paragraph')
172
+ reject();
173
+ if (!absent(child.marks))
174
+ reject();
175
+ if (absent(child.content))
176
+ continue;
177
+ if (!Array.isArray(child.content))
178
+ reject();
179
+ const part = [];
180
+ for (const item of child.content) {
181
+ if (isRecord(item) && (item.type === 'image' || item.type === 'hardBreak'))
182
+ reject();
183
+ const node = cleanNode(item, opts);
184
+ if (node !== null)
185
+ part.push(node);
186
+ }
187
+ if (part.length === 0)
188
+ continue;
189
+ if (inline.length > 0)
190
+ inline.push({ type: 'text', text: ' ' });
191
+ inline.push(...part);
192
+ }
193
+ return { type, content: [inline.length > 0 ? { type: 'paragraph', content: inline } : { type: 'paragraph' }] };
194
+ }
195
+ /** A table whose first row is its header and whose rows all have the header's width, or `null` if it has no cells. */
196
+ function cleanTable(raw, parent, opts) {
197
+ if (parent !== 'doc' || !opts.features.includes('table'))
198
+ reject();
199
+ if (absent(raw.content))
200
+ return null;
201
+ if (!Array.isArray(raw.content))
202
+ reject();
203
+ const rows = raw.content.map((row) => {
204
+ if (!isRecord(row) || row.type !== 'tableRow')
205
+ reject();
206
+ if (absent(row.content))
207
+ return [];
208
+ return Array.isArray(row.content) ? row.content : reject();
209
+ });
210
+ const width = rows[0]?.length ?? 0;
211
+ if (width === 0)
212
+ return null;
213
+ const content = rows.map((cells, r) => {
214
+ const type = r === 0 ? 'tableHeader' : 'tableCell';
215
+ const padded = cells.slice(0, width).map((c) => cleanCell(c, type, opts));
216
+ while (padded.length < width)
217
+ padded.push({ type, content: [{ type: 'paragraph' }] });
218
+ return { type: 'tableRow', content: padded };
219
+ });
220
+ return { type: 'table', content };
221
+ }
155
222
  /**
156
223
  * Empty paragraphs (including ones left empty once trailing line breaks are dropped) are
157
224
  * dropped, except a list item's first; so are blockquotes left empty.
@@ -163,7 +230,7 @@ function cleanContent(raw, parent, opts) {
163
230
  reject();
164
231
  const out = [];
165
232
  for (const child of raw) {
166
- const node = cleanNode(child, opts);
233
+ const node = isRecord(child) && child.type === 'table' ? cleanTable(child, parent, opts) : cleanNode(child, opts);
167
234
  if (node === null)
168
235
  continue;
169
236
  const empty = node.content === undefined;
@@ -228,12 +295,15 @@ function inlineText(node) {
228
295
  })
229
296
  .join('');
230
297
  }
298
+ const inlineCell = (cell) => inlineText(childrenOf(cell)[0]);
231
299
  function blockTexts(node, out) {
232
300
  for (const child of childrenOf(node)) {
233
301
  if (!isRecord(child))
234
302
  continue;
235
303
  if (child.type === 'paragraph' || child.type === 'heading')
236
304
  out.push(inlineText(child));
305
+ else if (child.type === 'tableRow')
306
+ out.push(childrenOf(child).map(inlineCell).join('\t'));
237
307
  else
238
308
  blockTexts(child, out);
239
309
  }
@@ -24,6 +24,7 @@ export declare function liveQuery(deps: CoreDeps, state: LiveState): import("kys
24
24
  created_at: string;
25
25
  deleted_at: string | null;
26
26
  edition: number | null;
27
+ first_published_at: string | null;
27
28
  group_id: string;
28
29
  head_path: string | null;
29
30
  head_rev: number | null;
@@ -43,6 +43,7 @@ function toLive(deps, state, locale, row, fallback) {
43
43
  slug,
44
44
  revisionId: row.rev_id,
45
45
  updatedAt: row.rev_created_at,
46
+ publishedAt: row.first_published_at,
46
47
  data,
47
48
  };
48
49
  }
@@ -4,6 +4,12 @@ export declare const RESERVED_PATHS: readonly string[];
4
4
  export declare function isReserved(path: string): boolean;
5
5
  /** The decoded, slash-trimmed form of a site path, or `null` if it isn't a clean site-relative path. */
6
6
  export declare function normalizePath(raw: string): string | null;
7
+ /**
8
+ * The lowercase form of a decoded, slash-trimmed path, for the fallback tried just before a 404.
9
+ * `null` when the path has no uppercase letter, lowercases to a reserved path, or ends in a segment
10
+ * that looks like a file (contains a `.`).
11
+ */
12
+ export declare function lowercaseFallback(path: string): string | null;
7
13
  export declare function encodePath(path: string): string;
8
14
  export declare function splitLocale(registry: Registry, path: string): {
9
15
  locale: string;
@@ -32,6 +32,19 @@ export function normalizePath(raw) {
32
32
  return null;
33
33
  return decoded.length > 1 && decoded.endsWith('/') ? decoded.slice(0, -1) : decoded;
34
34
  }
35
+ /**
36
+ * The lowercase form of a decoded, slash-trimmed path, for the fallback tried just before a 404.
37
+ * `null` when the path has no uppercase letter, lowercases to a reserved path, or ends in a segment
38
+ * that looks like a file (contains a `.`).
39
+ */
40
+ export function lowercaseFallback(path) {
41
+ const lower = path.toLowerCase();
42
+ if (lower === path || isReserved(lower))
43
+ return null;
44
+ if ((lower.split('/').at(-1) ?? '').includes('.'))
45
+ return null;
46
+ return lower;
47
+ }
35
48
  export function encodePath(path) {
36
49
  return path.split('/').map(encodeURIComponent).join('/');
37
50
  }
@@ -3,7 +3,7 @@ import { type LiveOpts } from './live.js';
3
3
  /** Resolves a still-encoded URL path (no query string) to a page, a redirect or not-found. */
4
4
  export declare function resolvePath(deps: CoreDeps, rawPath: string, opts?: LiveOpts): Promise<RouteMatch>;
5
5
  /**
6
- * What `resolvePath` answers before it looks at redirect rules (steps 1–6, then 8): a redirect rule
6
+ * What `resolvePath` answers before it looks at redirect rules (steps 1–6, then 9): a redirect rule
7
7
  * can only fire where this is `not_found`.
8
8
  */
9
9
  export declare function resolveWithoutRules(deps: CoreDeps, rawPath: string, opts?: LiveOpts): Promise<RouteMatch>;