@folijs/core 0.5.0 → 0.6.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 (125) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/state/commands.d.ts +2 -0
  3. package/dist/state/commands.d.ts.map +1 -1
  4. package/dist/state/commands.js +38 -6
  5. package/dist/state/commands.js.map +1 -1
  6. package/dist/state/comments.d.ts.map +1 -1
  7. package/dist/state/comments.js +12 -3
  8. package/dist/state/comments.js.map +1 -1
  9. package/dist/state/controls.d.ts +128 -0
  10. package/dist/state/controls.d.ts.map +1 -0
  11. package/dist/state/controls.js +1459 -0
  12. package/dist/state/controls.js.map +1 -0
  13. package/dist/state/editor.d.ts +86 -1
  14. package/dist/state/editor.d.ts.map +1 -1
  15. package/dist/state/editor.js +168 -42
  16. package/dist/state/editor.js.map +1 -1
  17. package/dist/state/fields.d.ts +79 -0
  18. package/dist/state/fields.d.ts.map +1 -0
  19. package/dist/state/fields.js +398 -0
  20. package/dist/state/fields.js.map +1 -0
  21. package/dist/state/fieldupdate.d.ts +178 -0
  22. package/dist/state/fieldupdate.d.ts.map +1 -0
  23. package/dist/state/fieldupdate.js +1574 -0
  24. package/dist/state/fieldupdate.js.map +1 -0
  25. package/dist/state/find.d.ts +68 -0
  26. package/dist/state/find.d.ts.map +1 -0
  27. package/dist/state/find.js +397 -0
  28. package/dist/state/find.js.map +1 -0
  29. package/dist/state/history.d.ts +12 -1
  30. package/dist/state/history.d.ts.map +1 -1
  31. package/dist/state/history.js +43 -7
  32. package/dist/state/history.js.map +1 -1
  33. package/dist/state/index.d.ts +12 -5
  34. package/dist/state/index.d.ts.map +1 -1
  35. package/dist/state/index.js +10 -3
  36. package/dist/state/index.js.map +1 -1
  37. package/dist/state/mark.d.ts.map +1 -1
  38. package/dist/state/mark.js +8 -1
  39. package/dist/state/mark.js.map +1 -1
  40. package/dist/state/navigation.d.ts +70 -0
  41. package/dist/state/navigation.d.ts.map +1 -0
  42. package/dist/state/navigation.js +226 -0
  43. package/dist/state/navigation.js.map +1 -0
  44. package/dist/state/notes.d.ts +94 -0
  45. package/dist/state/notes.d.ts.map +1 -0
  46. package/dist/state/notes.js +444 -0
  47. package/dist/state/notes.js.map +1 -0
  48. package/dist/state/review.d.ts +13 -4
  49. package/dist/state/review.d.ts.map +1 -1
  50. package/dist/state/review.js +133 -18
  51. package/dist/state/review.js.map +1 -1
  52. package/dist/state/sections.d.ts +101 -0
  53. package/dist/state/sections.d.ts.map +1 -0
  54. package/dist/state/sections.js +472 -0
  55. package/dist/state/sections.js.map +1 -0
  56. package/dist/state/state.d.ts +2 -0
  57. package/dist/state/state.d.ts.map +1 -1
  58. package/dist/state/state.js +4 -0
  59. package/dist/state/state.js.map +1 -1
  60. package/dist/state/stories.d.ts +41 -0
  61. package/dist/state/stories.d.ts.map +1 -0
  62. package/dist/state/stories.js +243 -0
  63. package/dist/state/stories.js.map +1 -0
  64. package/dist/state/tables.d.ts.map +1 -1
  65. package/dist/state/tables.js +2 -1
  66. package/dist/state/tables.js.map +1 -1
  67. package/dist/state/track.d.ts +23 -0
  68. package/dist/state/track.d.ts.map +1 -1
  69. package/dist/state/track.js +58 -9
  70. package/dist/state/track.js.map +1 -1
  71. package/dist/state/word.d.ts +78 -16
  72. package/dist/state/word.d.ts.map +1 -1
  73. package/dist/state/word.js +230 -10
  74. package/dist/state/word.js.map +1 -1
  75. package/dist/state/wordclip.d.ts +15 -6
  76. package/dist/state/wordclip.d.ts.map +1 -1
  77. package/dist/state/wordclip.js +192 -14
  78. package/dist/state/wordclip.js.map +1 -1
  79. package/dist/state/wordformat.d.ts +1 -1
  80. package/dist/state/wordformat.d.ts.map +1 -1
  81. package/dist/state/wordformat.js +60 -1
  82. package/dist/state/wordformat.js.map +1 -1
  83. package/dist/v3/document.d.ts +130 -7
  84. package/dist/v3/document.d.ts.map +1 -1
  85. package/dist/v3/document.js +172 -30
  86. package/dist/v3/document.js.map +1 -1
  87. package/dist/v3/index.d.ts +1 -1
  88. package/dist/v3/index.d.ts.map +1 -1
  89. package/dist/v3/index.js +1 -1
  90. package/dist/v3/index.js.map +1 -1
  91. package/dist/v3/resolve.d.ts +9 -3
  92. package/dist/v3/resolve.d.ts.map +1 -1
  93. package/dist/v3/resolve.js +22 -4
  94. package/dist/v3/resolve.js.map +1 -1
  95. package/dist/v3/schema.d.ts +2 -0
  96. package/dist/v3/schema.d.ts.map +1 -1
  97. package/dist/v3/schema.js +89 -3
  98. package/dist/v3/schema.js.map +1 -1
  99. package/package.json +1 -1
  100. package/src/state/commands.ts +41 -4
  101. package/src/state/comments.ts +11 -3
  102. package/src/state/controls.ts +1596 -0
  103. package/src/state/editor.ts +291 -47
  104. package/src/state/fields.ts +432 -0
  105. package/src/state/fieldupdate.ts +1770 -0
  106. package/src/state/find.ts +510 -0
  107. package/src/state/history.ts +51 -7
  108. package/src/state/index.ts +123 -0
  109. package/src/state/mark.ts +8 -1
  110. package/src/state/navigation.ts +305 -0
  111. package/src/state/notes.ts +519 -0
  112. package/src/state/numeric-pictures.word.json +172 -0
  113. package/src/state/review.ts +171 -19
  114. package/src/state/sections.ts +571 -0
  115. package/src/state/state.ts +5 -0
  116. package/src/state/stories.ts +285 -0
  117. package/src/state/tables.ts +2 -1
  118. package/src/state/track.ts +65 -10
  119. package/src/state/word.ts +275 -12
  120. package/src/state/wordclip.ts +211 -29
  121. package/src/state/wordformat.ts +61 -1
  122. package/src/v3/document.ts +326 -41
  123. package/src/v3/index.ts +7 -0
  124. package/src/v3/resolve.ts +33 -9
  125. package/src/v3/schema.ts +92 -3
package/src/v3/schema.ts CHANGED
@@ -136,12 +136,24 @@ const ID = int(0, 2_147_483_647);
136
136
  const revisionFields = { id: ID, author: str(), date: nullable(date) };
137
137
  const revision = shape(revisionFields, ["id", "author"]);
138
138
 
139
+ /** How notes are placed and numbered (`w:footnotePr`, `w:endnotePr`), for a document or section. */
140
+ export const checkNoteProperties: Check = shape({
141
+ position: oneOf(["pageBottom", "beneathText", "sectEnd", "docEnd"]),
142
+ format: token,
143
+ start: ID,
144
+ restart: oneOf(["continuous", "eachSect", "eachPage"]),
145
+ });
146
+
147
+ /** Word's limit on a section's columns. */
148
+ const MAX_SECTION_COLUMNS = 45;
149
+
139
150
  /**
140
151
  * A section's page setup (`w:sectPr`): on the last paragraph of each section, and the
141
152
  * envelope's for the last. Every part is optional (Word's defaults apply); `{}` is a section
142
153
  * break with Word's defaults.
143
154
  */
144
- export const checkSection: Check = shape(
155
+ export const checkSection: Check = (value) => sectionShape(value);
156
+ const sectionShape: Check = shape(
145
157
  {
146
158
  pageSize: shape({
147
159
  width: int(1, MAX_TWIPS),
@@ -161,6 +173,23 @@ export const checkSection: Check = shape(
161
173
  titlePage: bool,
162
174
  headers: shape({ default: text(), first: text(), even: text() }),
163
175
  footers: shape({ default: text(), first: text(), even: text() }),
176
+ /** `w:cols` (schema v5): `widths` when the columns are not equal. */
177
+ columns: shape({
178
+ count: int(1, MAX_SECTION_COLUMNS),
179
+ space: positiveTwips,
180
+ equalWidth: bool,
181
+ separator: bool,
182
+ widths: listOf(
183
+ shape({ width: positiveTwips, space: positiveTwips }, ["width"]),
184
+ MAX_SECTION_COLUMNS,
185
+ ),
186
+ }),
187
+ /** `w:pgNumType` (schema v5). */
188
+ pageNumbers: shape({ start: ID, format: token }),
189
+ footnotes: checkNoteProperties,
190
+ endnotes: checkNoteProperties,
191
+ /** `w:sectPrChange`: a tracked change of the page setup, and the setup before it. */
192
+ change: shape({ ...revisionFields, previous: checkSection }, ["id", "author", "previous"]),
164
193
  ext: xml,
165
194
  },
166
195
  [],
@@ -433,6 +462,18 @@ const reviewMark: MarkSpec = {
433
462
  };
434
463
  /** A marker's own unknown attributes (`w:displacedByCustomXml`…). */
435
464
  const markerAttributes = { attributes: nullableAttr(attributes) };
465
+ /** Ids of content controls, outermost first: at least one, none twice. */
466
+ const controlIds: Check = (v) => {
467
+ const error = listOf(text(), 64)(v);
468
+ if (error) return error;
469
+ const ids = v as string[];
470
+ if (!ids.length) return "must not be empty (use null)";
471
+ return new Set(ids).size === ids.length ? undefined : "must not repeat an id";
472
+ };
473
+ /** The content controls around a block, row or cell (schema v5, ADR-0007). */
474
+ const controlsAttr = { controls: nullableAttr(controlIds) };
475
+ /** Part of a field (schema v5): stands in a run, verbatim XML of what the model does not hold. */
476
+ const fieldPart = { group: "inline", inline: true, selectable: false } as const;
436
477
  const fontName = markAttr(nullable(text()), null);
437
478
  const themeFont = markAttr(nullable(oneOf(THEME_FONTS)), null);
438
479
  const hexByte = (v: unknown) =>
@@ -446,6 +487,7 @@ export const schema = new Schema({
446
487
  content: "inline*",
447
488
  attrs: {
448
489
  ...paragraphProperties,
490
+ ...controlsAttr,
449
491
  /** Ends a section: its page setup. The last section's is the envelope's `section`. */
450
492
  section: nullableAttr(checkSection),
451
493
  /** The paragraph mark inserted and/or deleted as tracked changes. */
@@ -472,6 +514,7 @@ export const schema = new Schema({
472
514
  content: "tableRow+",
473
515
  attrs: {
474
516
  ...tableProperties,
517
+ ...controlsAttr,
475
518
  /** The grid's column widths in twips (`w:tblGrid`). */
476
519
  grid: { default: [], validate: listOf(positiveTwips, MAX_COLUMNS) },
477
520
  /** The `w:tblGrid` the grid was read from, verbatim. */
@@ -482,6 +525,7 @@ export const schema = new Schema({
482
525
  content: "tableCell+",
483
526
  attrs: {
484
527
  ...rowProperties,
528
+ ...controlsAttr,
485
529
  /** The row inserted or deleted as a tracked change (`w:trPr/w:ins`, `w:del`). */
486
530
  revision: nullableAttr(shape({ insertion: revision, deletion: revision })),
487
531
  /** The row's table property exceptions (`w:tblPrEx`). */
@@ -493,12 +537,12 @@ export const schema = new Schema({
493
537
  tableCell: {
494
538
  // As Word requires, a cell ends with a paragraph.
495
539
  content: "block* paragraph",
496
- attrs: cellProperties,
540
+ attrs: { ...cellProperties, ...controlsAttr },
497
541
  },
498
542
  /** Block content Foli does not model yet (a table inside a content control…), kept verbatim. */
499
543
  opaqueBlock: {
500
544
  group: "block",
501
- attrs: { xml: { validate: xml }, label: nullableAttr(text()) },
545
+ attrs: { xml: { validate: xml }, label: nullableAttr(text()), ...controlsAttr },
502
546
  },
503
547
  text: { group: "inline" },
504
548
  tab: { group: "inline", inline: true },
@@ -541,6 +585,51 @@ export const schema = new Schema({
541
585
  inline: true,
542
586
  attrs: { id: { validate: ID }, ...markerAttributes },
543
587
  },
588
+ /**
589
+ * A field, as Word has it (schema v5, ADR-0007): start, code, optional separator, result,
590
+ * end. The code range runs from the start to the separator (or the end) and may hold other
591
+ * fields; the result is ordinary content.
592
+ */
593
+ fieldStart: {
594
+ ...fieldPart,
595
+ attrs: {
596
+ dirty: nullableAttr(bool),
597
+ locked: nullableAttr(bool),
598
+ /** Read from `w:fldSimple`, and written back as one. */
599
+ simple: nullableAttr(bool),
600
+ ext: nullableAttr(xml),
601
+ },
602
+ },
603
+ /** One `w:instrText`: part of a field's code. */
604
+ fieldCode: { ...fieldPart, attrs: { text: { validate: str(65_535) }, ...markerAttributes } },
605
+ fieldSeparator: { ...fieldPart, attrs: { ext: nullableAttr(xml) } },
606
+ fieldEnd: { ...fieldPart, attrs: { ext: nullableAttr(xml) } },
607
+ /** An inline content control's ends; its properties are the envelope's `controls[id]`. */
608
+ controlStart: {
609
+ group: "inline",
610
+ inline: true,
611
+ selectable: false,
612
+ attrs: { id: { validate: text() } },
613
+ },
614
+ controlEnd: {
615
+ group: "inline",
616
+ inline: true,
617
+ selectable: false,
618
+ attrs: { id: { validate: text() } },
619
+ },
620
+ /** A footnote's or endnote's reference: its text is the envelope's `stories[story]`. */
621
+ noteReference: {
622
+ group: "inline",
623
+ inline: true,
624
+ attrs: {
625
+ story: { validate: text() },
626
+ /** `w:customMarkFollows`: the mark is the text after it, not a number. */
627
+ customMark: nullableAttr(bool),
628
+ ...markerAttributes,
629
+ },
630
+ },
631
+ /** Where a note shows its own number (`w:footnoteRef`, `w:endnoteRef`). */
632
+ noteMark: { group: "inline", inline: true, selectable: false },
544
633
  /**
545
634
  * A picture (`w:drawing` holding `pic:pic`, schema v4), inline or floating. Its bytes are
546
635
  * the envelope's `resources[resource]`.