oasis-editor 0.0.215 → 0.0.217

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.
@@ -9854,18 +9854,23 @@ while (n === s[++o] && n === s[++o] && n === s[++o] && n === s[++o] && n === s[+
9854
9854
  });
9855
9855
  const e = c.pop();
9856
9856
  e && ((e) => {
9857
- const t = /\bNUMPAGES\b/i.test(e.instruction) ? "NUMPAGES" : /\bPAGE\b/i.test(e.instruction) ? "PAGE" : null;
9857
+ const t = /\bNUMPAGES\b/i.test(e.instruction) ? "NUMPAGES" : /\bPAGE\b/i.test(e.instruction) ? "PAGE" : /\bDATE\b/i.test(e.instruction) ? "DATE" : null;
9858
9858
  if (!t) return;
9859
- const r = Kt(/\*\s*([A-Za-z]+)/.exec(e.instruction)?.[1]), n = l.slice(e.beginIndex);
9860
- if (n.some((e) => e.bookmark)) return;
9861
- const o = n.filter((e) => !e.fieldChar && void 0 === e.fieldInstruction), i = o.map((e) => e.text).join("") || "1", a = o.find((e) => e.styles)?.styles ?? e.beginStyles;
9862
- l.length = e.beginIndex, l.push({
9863
- text: i,
9864
- ...a ? { styles: a } : {},
9865
- field: r ? {
9866
- type: t,
9867
- format: r
9868
- } : { type: t }
9859
+ const r = Kt(/\*\s*([A-Za-z]+)/.exec(e.instruction)?.[1]), n = "DATE" === t ? /@\s*"([^"]*)"/.exec(e.instruction)?.[1] : void 0, o = l.slice(e.beginIndex);
9860
+ if (o.some((e) => e.bookmark)) return;
9861
+ const i = o.filter((e) => !e.fieldChar && void 0 === e.fieldInstruction), a = i.map((e) => e.text).join("") || "1", s = i.find((e) => e.styles)?.styles ?? e.beginStyles;
9862
+ l.length = e.beginIndex;
9863
+ const c = "DATE" === t ? n ? {
9864
+ type: "DATE",
9865
+ dateFormat: n
9866
+ } : { type: "DATE" } : r ? {
9867
+ type: t,
9868
+ format: r
9869
+ } : { type: t };
9870
+ l.push({
9871
+ text: a,
9872
+ ...s ? { styles: s } : {},
9873
+ field: c
9869
9874
  });
9870
9875
  })(e);
9871
9876
  }
@@ -10030,16 +10035,19 @@ while (n === s[++o] && n === s[++o] && n === s[++o] && n === s[++o] && n === s[+
10030
10035
  continue;
10031
10036
  }
10032
10037
  if ("fldSimple" === f.localName) {
10033
- const e = f.getAttribute("w:instr") ?? f.getAttributeNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "instr") ?? f.getAttribute("instr") ?? "", c = /\bNUMPAGES\b/i.test(e) ? "NUMPAGES" : /\bPAGE\b/i.test(e) ? "PAGE" : null, u = /\*\s*([A-Za-z]+)/.exec(e)?.[1], d = Kt(u), p = await Pr(f, t, r, n, o, i, a, s);
10038
+ const e = f.getAttribute("w:instr") ?? f.getAttributeNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "instr") ?? f.getAttribute("instr") ?? "", c = /\bNUMPAGES\b/i.test(e) ? "NUMPAGES" : /\bPAGE\b/i.test(e) ? "PAGE" : /\bDATE\b/i.test(e) ? "DATE" : null, u = /\*\s*([A-Za-z]+)/.exec(e)?.[1], d = Kt(u), p = "DATE" === c ? /@\s*"([^"]*)"/.exec(e)?.[1] : void 0, h = await Pr(f, t, r, n, o, i, a, s);
10034
10039
  if (c) {
10035
- const e = p.map((e) => e.text).join("") || "1", t = p.find((e) => e.styles)?.styles;
10040
+ const e = h.map((e) => e.text).join("") || "1", t = h.find((e) => e.styles)?.styles, r = "DATE" === c ? p ? {
10041
+ type: "DATE",
10042
+ dateFormat: p
10043
+ } : { type: "DATE" } : d ? {
10044
+ type: c,
10045
+ format: d
10046
+ } : { type: c };
10036
10047
  l.push({
10037
10048
  text: e,
10038
10049
  styles: t,
10039
- field: d ? {
10040
- type: c,
10041
- format: d
10042
- } : { type: c }
10050
+ field: r
10043
10051
  });
10044
10052
  } else l.push({
10045
10053
  text: "",
@@ -10050,7 +10058,7 @@ while (n === s[++o] && n === s[++o] && n === s[++o] && n === s[++o] && n === s[+
10050
10058
  }), l.push({
10051
10059
  text: "",
10052
10060
  fieldChar: { kind: "separate" }
10053
- }), l.push(...p), l.push({
10061
+ }), l.push(...h), l.push({
10054
10062
  text: "",
10055
10063
  fieldChar: { kind: "end" }
10056
10064
  });
@@ -13046,12 +13054,17 @@ while (n === s[++o] && n === s[++o] && n === s[++o] && n === s[++o] && n === s[+
13046
13054
  return t = e.fieldInstruction, `<w:r>${s()}<w:instrText xml:space="preserve">${to(t)}</w:instrText></w:r>`;
13047
13055
  var t;
13048
13056
  },
13049
- field: (e) => function(e, t, r) {
13050
- const n = "PAGE" === e ? " PAGE " : " NUMPAGES ", o = function(e) {
13051
- if (e && "decimal" !== e) return e;
13052
- }(t);
13053
- return `<w:fldSimple w:instr="${o ? ` ${n.trim()} \\* ${o} ` : n}"><w:r>${r}<w:t>1</w:t></w:r></w:fldSimple>`;
13054
- }(e.field.type, e.field.format, s()),
13057
+ field: (e) => function(e, t, r = "1") {
13058
+ let n;
13059
+ if ("DATE" === e.type) n = ` DATE \\@ "${e.dateFormat ?? "M/d/yyyy"}" `;
13060
+ else {
13061
+ const t = "PAGE" === e.type ? " PAGE " : " NUMPAGES ", r = function(e) {
13062
+ if (e && "decimal" !== e) return e;
13063
+ }(e.format);
13064
+ n = r ? ` ${t.trim()} \\* ${r} ` : t;
13065
+ }
13066
+ return `<w:fldSimple w:instr="${to(n)}"><w:r>${t}<w:t xml:space="preserve">${to(r)}</w:t></w:r></w:fldSimple>`;
13067
+ }(e.field, s(), "DATE" === e.field.type ? e.text : void 0),
13055
13068
  textBox: (e) => zi(e, e.textBox, t, n, s(), o),
13056
13069
  image: (e) => {
13057
13070
  const r = t.imageMap.get(e.id);
@@ -1,2 +1,2 @@
1
- export declare const OASIS_BUILTIN_COMMANDS: readonly ["selectAll", "insertFootnote", "insertText", "insertEquation", "updateEquation", "insertTableOfContents", "updateTableOfContents", "pastePlainText", "paste", "pasteAsPlainText", "pasteMergeFormatting", "formatPainter", "formatPainterContinuous", "cancelFormatPainter", "bold", "italic", "underline", "strike", "superscript", "subscript", "link", "unlink", "alignLeft", "alignCenter", "alignRight", "alignJustify", "orderedList", "bulletList", "find", "replace", "toggleTrackChanges", "acceptRevisions", "rejectRevisions", "nextRevision", "previousRevision", "nextComment", "previousComment", "newComment", "replyComment", "editComment", "toggleCommentsPanel", "resolveComment", "reopenComment", "deleteComment", "toggleShowMargins", "toggleShowParagraphMarks", "togglePreciseFonts", "undo", "redo", "pageBreak", "lineBreak", "splitBlock", "setFontFamily", "setFontSize", "increaseFontSize", "decreaseFontSize", "changeTextCase", "clearFormatting", "setColor", "setHighlight", "setTextShading", "setStyleId", "setCharacterStyleId", "setUnderlineStyle", "documentStyles", "print", "copy", "cut", "newDocument", "exportDocx", "exportPdf", "importDocument", "insertHtml", "insertImage", "editImageAlt", "insertImageCaption", "imageContext", "imageWidthCm", "imageHeightCm", "imageCrop", "imageCropAspect", "imageCropShape", "imageCropFill", "imageCropFit", "imageCropReset", "imageBorder", "outdent", "indent", "togglePageBreakBefore", "toggleKeepWithNext", "setSpacingAfter", "setSpacingBefore", "setIndentLeft", "setIndentRight", "setIndentFirstLine", "setIndentHanging", "setSpecialIndent", "setParagraphShading", "applyParagraphBorders", "setLineHeight", "setListFormat", "setListStartAt", "toggleOrientation", "setOrientation", "sectionBreakNextPage", "sectionBreakContinuous", "setPageMargins", "editHeader", "editFooter", "insertPageNumber", "insertPageNumberXOfY", "placePageNumberTop", "placePageNumberBottom", "insertBookmark", "removeBookmark", "exitHeaderFooter", "applyDocumentTheme", "setDocumentColorScheme", "setDocumentFontScheme", "setDocumentParagraphSpacing", "setDocumentEffects", "setDocumentPageColor", "setDocumentWatermark", "setDocumentPageBorder", "setDocumentDesignDefault", "tableContext", "tableMerge", "tableSplit", "tableInsertColumnBefore", "tableInsertColumnAfter", "tableDeleteColumn", "tableInsertRowBefore", "tableInsertRowAfter", "tableDeleteRow", "tableCellShading", "tableCellBorders", "tableCellNoBorders", "tableApplyBorderPreset", "toggleTableDrawBorders", "toggleTableGridlines", "tableWidth100", "tableAlignLeft", "tableAlignCenter", "tableAlignRight", "tableSetCellWidth", "tableToggleHeaderRow", "tableToggleTotalRow", "tableToggleBandedRows", "tableToggleFirstColumn", "tableToggleLastColumn", "tableToggleBandedColumns", "setTableStyle", "tableToggleAutoFit", "tableDistributeColumns", "tableDistributeRows", "insertTable", "insertShape", "openSymbolDialog", "openEquationDialog"];
1
+ export declare const OASIS_BUILTIN_COMMANDS: readonly ["selectAll", "insertFootnote", "insertText", "insertEquation", "updateEquation", "insertTableOfContents", "updateTableOfContents", "pastePlainText", "paste", "pasteAsPlainText", "pasteMergeFormatting", "formatPainter", "formatPainterContinuous", "cancelFormatPainter", "bold", "italic", "underline", "strike", "superscript", "subscript", "link", "unlink", "alignLeft", "alignCenter", "alignRight", "alignJustify", "orderedList", "bulletList", "find", "replace", "toggleTrackChanges", "acceptRevisions", "rejectRevisions", "nextRevision", "previousRevision", "nextComment", "previousComment", "newComment", "replyComment", "editComment", "toggleCommentsPanel", "resolveComment", "reopenComment", "deleteComment", "toggleShowMargins", "toggleShowParagraphMarks", "togglePreciseFonts", "undo", "redo", "pageBreak", "lineBreak", "splitBlock", "setFontFamily", "setFontSize", "increaseFontSize", "decreaseFontSize", "changeTextCase", "clearFormatting", "setColor", "setHighlight", "setTextShading", "setStyleId", "setCharacterStyleId", "setUnderlineStyle", "documentStyles", "print", "copy", "cut", "newDocument", "exportDocx", "exportPdf", "importDocument", "insertHtml", "insertImage", "editImageAlt", "insertImageCaption", "imageContext", "imageWidthCm", "imageHeightCm", "imageCrop", "imageCropAspect", "imageCropShape", "imageCropFill", "imageCropFit", "imageCropReset", "imageBorder", "outdent", "indent", "togglePageBreakBefore", "toggleKeepWithNext", "setSpacingAfter", "setSpacingBefore", "setIndentLeft", "setIndentRight", "setIndentFirstLine", "setIndentHanging", "setSpecialIndent", "setParagraphShading", "applyParagraphBorders", "setLineHeight", "setListFormat", "setListStartAt", "toggleOrientation", "setOrientation", "sectionBreakNextPage", "sectionBreakContinuous", "setPageMargins", "setSectionPageNumbering", "editHeader", "editFooter", "insertPageNumber", "insertPageNumberXOfY", "placePageNumberTop", "placePageNumberBottom", "insertBookmark", "removeBookmark", "insertDateField", "exitHeaderFooter", "applyDocumentTheme", "setDocumentColorScheme", "setDocumentFontScheme", "setDocumentParagraphSpacing", "setDocumentEffects", "setDocumentPageColor", "setDocumentWatermark", "setDocumentPageBorder", "setDocumentDesignDefault", "tableContext", "tableMerge", "tableSplit", "tableInsertColumnBefore", "tableInsertColumnAfter", "tableDeleteColumn", "tableInsertRowBefore", "tableInsertRowAfter", "tableDeleteRow", "tableCellShading", "tableCellBorders", "tableCellNoBorders", "tableApplyBorderPreset", "toggleTableDrawBorders", "toggleTableGridlines", "tableWidth100", "tableAlignLeft", "tableAlignCenter", "tableAlignRight", "tableSetCellWidth", "tableToggleHeaderRow", "tableToggleTotalRow", "tableToggleBandedRows", "tableToggleFirstColumn", "tableToggleLastColumn", "tableToggleBandedColumns", "setTableStyle", "tableToggleAutoFit", "tableDistributeColumns", "tableDistributeRows", "insertTable", "insertShape", "openSymbolDialog", "openEquationDialog"];
2
2
  export type OasisBuiltinCommand = (typeof OASIS_BUILTIN_COMMANDS)[number];
@@ -0,0 +1,13 @@
1
+ import { EditorState, EditorTextRun } from '../model.js';
2
+ export declare const DEFAULT_DATE_PICTURE = "M/d/yyyy";
3
+ export interface InsertDateFieldOptions {
4
+ /** `\@` picture controlling the result. Default `M/d/yyyy`. */
5
+ dateFormat?: string;
6
+ /** Value to resolve, for deterministic tests. Default now. */
7
+ value?: Date;
8
+ }
9
+ /** Insert a DATE field at the caret with a resolved, cached result. */
10
+ export declare function insertDateField(state: EditorState, options?: InsertDateFieldOptions): EditorState;
11
+ export declare function isDateFieldRun(run: EditorTextRun): boolean;
12
+ /** Whether the active zone is a header or footer (recall DATE fields in them). */
13
+ export declare function isInHeaderOrFooter(state: EditorState): boolean;
@@ -2,6 +2,12 @@ import { EditorState, EditorTextRun, PageNumberFormat } from '../model.js';
2
2
  export type PageNumberFieldKind = "page" | "xOfY";
3
3
  export type PageNumberPlacement = "current" | "top" | "bottom";
4
4
  export type PageNumberAlign = "left" | "center" | "right" | "justify";
5
+ /**
6
+ * OOXML `ST_NumberFormat` page-number values the editor can author. Stored
7
+ * verbatim on `EditorPageNumbering.format` so uncommon imports still
8
+ * round-trip even though only these can be authored.
9
+ */
10
+ export type SectionPageNumberFormat = "decimal" | "upperRoman" | "lowerRoman" | "upperLetter" | "lowerLetter" | "none";
5
11
  export interface PageNumberPlacementOptions {
6
12
  /** Field shape: bare PAGE or the Page X of Y combination. Default `page`. */
7
13
  kind?: PageNumberFieldKind;
@@ -38,3 +44,14 @@ export declare function insertPageNumberField(state: EditorState, kind?: PageNum
38
44
  export declare function placePageNumber(state: EditorState, position: PageNumberPlacement, options?: PageNumberPlacementOptions): EditorState;
39
45
  /** Exported for tests: whether the active zone is a header or footer. */
40
46
  export declare function isInHeaderOrFooter(state: EditorState): boolean;
47
+ /**
48
+ * Set page numbering on the active section (`w:pgNumType`): the starting page
49
+ * number and/or the number format. Only explicitly provided fields update;
50
+ * omitted fields are left unchanged. `format` uses the OOXML `ST_NumberFormat`
51
+ * vocabulary (`decimal`, `upperRoman`, `lowerRoman`, `upperLetter`,
52
+ * `lowerLetter`, `none`).
53
+ */
54
+ export declare function setSectionPageNumbering(state: EditorState, numbering: {
55
+ start?: number;
56
+ format?: SectionPageNumberFormat;
57
+ }): EditorState;
@@ -1,5 +1,6 @@
1
1
  import { CommandRef } from './CommandRef.js';
2
2
  import { EditorPageMargins, EditorMathExpression, EditorPageBorder, EditorWatermark } from '../model.js';
3
+ import { SectionPageNumberFormat } from './pageNumber.js';
3
4
  import { TextCaseMode } from './text.js';
4
5
  import { TableBorderPreset } from './table.js';
5
6
  import { DesignThemeId } from './design.js';
@@ -139,6 +140,10 @@ export interface OasisCommandPayloads {
139
140
  sectionBreakNextPage: undefined;
140
141
  sectionBreakContinuous: undefined;
141
142
  setPageMargins: SetPageMarginsPayload;
143
+ setSectionPageNumbering: {
144
+ start?: number;
145
+ format?: SectionPageNumberFormat;
146
+ };
142
147
  editHeader: undefined;
143
148
  editFooter: undefined;
144
149
  insertPageNumber: undefined;
@@ -147,6 +152,7 @@ export interface OasisCommandPayloads {
147
152
  placePageNumberBottom: undefined;
148
153
  insertBookmark: string | undefined;
149
154
  removeBookmark: string;
155
+ insertDateField: undefined;
150
156
  exitHeaderFooter: undefined;
151
157
  applyDocumentTheme: DesignThemeId;
152
158
  setDocumentColorScheme: string;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Date/time field formatting.
3
+ *
4
+ * DATE/TIME fields in Word carry a `\@` picture (e.g. `"M/d/yyyy"`) that
5
+ * controls the displayed result. This module mirrors WordCraft's `DATE_FORMATS`
6
+ * vocabulary and formats a JavaScript Date according to the common picture
7
+ * tokens Word understands, so an authored date field renders deterministically
8
+ * and round-trips through DOCX.
9
+ */
10
+ export declare const DATE_FORMATS: ReadonlyArray<string>;
11
+ /**
12
+ * Format a Date according to a Word `\@` picture. Unrecognized tokens are
13
+ * passed through literally; `am/pm` renders "am"/"pm". Supports the common
14
+ * tokens: d/dd/ddd/dddd (day), M/MM/MMM/MMMM (month), yy/yyyy (year),
15
+ * h/hh (12h), H (24h), m/mm (minute), s/ss (second), and literal text.
16
+ */
17
+ export declare function formatDate(value: Date, picture: string): string;
@@ -190,10 +190,14 @@ export interface EditorImageRunData {
190
190
  }
191
191
  /** `\*` number-format switch for PAGE/NUMPAGES fields (WordCraft NUMBER_FORMATS). */
192
192
  export type PageNumberFormat = "decimal" | "roman" | "ROMAN" | "alphabetic" | "ALPHABETIC" | "Ordinal";
193
+ /** Field types the editor can author/evaluate for display. */
194
+ export type EditorFieldType = "PAGE" | "NUMPAGES" | "DATE";
193
195
  export interface EditorFieldData {
194
- type: "PAGE" | "NUMPAGES";
196
+ type: EditorFieldType;
195
197
  /** Page-number `\*` format switch. Absent ⇒ decimal. */
196
198
  format?: PageNumberFormat;
199
+ /** `\@` picture for DATE fields (e.g. "M/d/yyyy"). Absent ⇒ default. */
200
+ dateFormat?: string;
197
201
  }
198
202
  /**
199
203
  * A preserved complex-field control character (`w:fldChar`). Carried on a