oasis-editor 0.0.216 → 0.0.218

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,10 +1,12 @@
1
- import { EditorParagraphStyle, EditorPosition, EditorState, EditorSection, EditorTabStop } from '../model.js';
1
+ import { EditorParagraphStyle, EditorPosition, EditorState, EditorSection, EditorTabStop, EditorPageSettings } from '../model.js';
2
2
  import { ValueParagraphStyleKey } from '../textStyle/textStyleKeys.js';
3
3
  export declare function moveBlockToPosition(state: EditorState, blockId: string, targetPosition: EditorPosition): EditorState;
4
4
  export declare function splitBlockAtSelection(state: EditorState): EditorState;
5
5
  export declare function insertPageBreakAtSelection(state: EditorState): EditorState;
6
6
  export declare function insertSectionBreakAtSelection(state: EditorState, breakType: "nextPage" | "continuous"): EditorState;
7
- export declare function updateSectionSettings(state: EditorState, sectionIndex: number, settings: Partial<EditorSection>): EditorState;
7
+ export declare function updateSectionSettings(state: EditorState, sectionIndex: number, settings: Omit<Partial<EditorSection>, "pageSettings"> & {
8
+ pageSettings?: Partial<EditorPageSettings>;
9
+ }): EditorState;
8
10
  export declare function setParagraphNamedStyle(state: EditorState, styleId: string | null): EditorState;
9
11
  export declare function setParagraphStyle<K extends ValueParagraphStyleKey>(state: EditorState, key: K, value: EditorParagraphStyle[K] | null): EditorState;
10
12
  export declare function setParagraphTabStops(state: EditorState, tabs: EditorTabStop[] | null): EditorState;
@@ -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", "setSectionPageNumbering", "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", "setPaperSize", "setPaperSizePreset", "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;
@@ -0,0 +1,31 @@
1
+ import { EditorState } from '../model.js';
2
+ /** Convert a physical dimension in points to the editor's px unit (×96/72). */
3
+ export declare function pointsToPx(points: number): number;
4
+ /** A named paper size in points (the author-facing physical dimension). */
5
+ export interface PaperSizePreset {
6
+ /** Machine id, e.g. "letter" / "a4". */
7
+ id: string;
8
+ /** Portrait dimensions in points. */
9
+ widthPt: number;
10
+ heightPt: number;
11
+ }
12
+ /** Common Word/WordCraft paper sizes (points). */
13
+ export declare const PAPER_SIZE_PRESETS: readonly PaperSizePreset[];
14
+ /**
15
+ * Set the active section's paper dimensions from physical points. Orientation
16
+ * is left untouched so switching a named preset never silently flips layout.
17
+ * Returns the same state when there's no section.
18
+ */
19
+ export declare function setSectionPaperSize(state: EditorState, dimensions: {
20
+ widthPt: number;
21
+ heightPt: number;
22
+ }): EditorState;
23
+ /** Look up a named preset by id, or undefined. */
24
+ export declare function getPaperSizePreset(id: string): PaperSizePreset | undefined;
25
+ /** Apply a named paper-size preset to the active section. */
26
+ export declare function setSectionPaperSizePreset(state: EditorState, presetId: string): EditorState;
27
+ /** Read the active section's paper dimensions in physical points. */
28
+ export declare function getActivePaperSize(state: EditorState): {
29
+ widthPt: number;
30
+ heightPt: number;
31
+ } | undefined;
@@ -144,6 +144,11 @@ export interface OasisCommandPayloads {
144
144
  start?: number;
145
145
  format?: SectionPageNumberFormat;
146
146
  };
147
+ setPaperSize: {
148
+ widthPt: number;
149
+ heightPt: number;
150
+ };
151
+ setPaperSizePreset: string;
147
152
  editHeader: undefined;
148
153
  editFooter: undefined;
149
154
  insertPageNumber: undefined;
@@ -152,6 +157,7 @@ export interface OasisCommandPayloads {
152
157
  placePageNumberBottom: undefined;
153
158
  insertBookmark: string | undefined;
154
159
  removeBookmark: string;
160
+ insertDateField: undefined;
155
161
  exitHeaderFooter: undefined;
156
162
  applyDocumentTheme: DesignThemeId;
157
163
  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