@twip/web 0.0.0-canary-7dfb59b → 0.0.0-canary-d060d80

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/README.md CHANGED
@@ -32,6 +32,19 @@ await editor.destroy();
32
32
 
33
33
  In Node, workers and tests, `HeadlessEditor.create()` gives the same API with no DOM.
34
34
 
35
+ ## Your own field types
36
+
37
+ A field whose type isn't one of Word's reads as a bookmark reference, and with no result it shows "Error! Bookmark
38
+ not defined.", as in Word. Declare the types your application fills itself after each `open`:
39
+
40
+ ```ts
41
+ await editor.commands.setApplicationFieldTypes({ types: ['CUSTOMVALUE', 'CUSTOMTEXT'] });
42
+ ```
43
+
44
+ Their fields then keep their results, show nothing when empty (their `setFieldLabels` label, else «first argument»,
45
+ in design mode) and are listed by `fieldsUpdateRequested` on `updateFields`, for `setFieldResults` to fill. Types
46
+ compare without case; each call replaces the list, and `[]` clears it. Setting it doesn't mark the document modified.
47
+
35
48
  ## Serving the engine's files yourself
36
49
 
37
50
  The engine runs from files in the package's `dist/`: `worker.js`, `twip-wasm.js`, `twip_wasm.wasm`, and the
@@ -1,5 +1,5 @@
1
1
  import type { RichText } from './review.js';
2
- import type { ControlKind, ControlOptions, DataBinding, ReferenceRule, SubTemplateVersion } from './services/elements.js';
2
+ import type { ControlKind, ControlOptions, DataBinding, ReferenceRule } from './services/elements.js';
3
3
  import type { TabAlignment, TabLeader, TabSelector } from './services/ruler.js';
4
4
  import type { ViewOptions } from './services/view.js';
5
5
  import type { AutoCorrectChange, HighlightColor, HorizontalPosition, LineSpacing, MarkupView, ObjectWrap, RowHeight, TablePosition, TableWidth, UnderlineStyle, VerticalPosition, WrapSide } from './state.js';
@@ -19,10 +19,7 @@ export interface PlaceholderLook {
19
19
  } | {
20
20
  prefix: string;
21
21
  } | 'default';
22
- /**
23
- * A fill, label and icon, or an image. With `placeholderUi` on, `fill` is the input block's base colour: its tint,
24
- * outlines and primary button are derived from it.
25
- */
22
+ /** A fill, label and icon, or an image. */
26
23
  look: {
27
24
  fill?: Color;
28
25
  label?: string;
@@ -31,19 +28,6 @@ export interface PlaceholderLook {
31
28
  image: Uint8Array;
32
29
  mime: string;
33
30
  };
34
- /** The hint an input block shows while hovered. Default: "Click to add". */
35
- hint?: string;
36
- /** The buttons a selected input block shows, in order; none: a press on the block activates it. */
37
- actions?: PlaceholderAction[];
38
- }
39
- /** A button on a selected input block: a press raises `placeholderActivated` with its `id` as `action`. */
40
- export interface PlaceholderAction {
41
- /** What `placeholderActivated` names as `action`. */
42
- id: string;
43
- /** Its text. */
44
- label: string;
45
- /** Filled in the block's colour (the others are outlined); Enter presses it. Default: false. */
46
- primary?: boolean;
47
31
  }
48
32
  /**
49
33
  * Every edit, one method per command. Each resolves after its change commits, with `getState()` already at that
@@ -492,22 +476,19 @@ export interface Commands {
492
476
  labels: Record<string, string>;
493
477
  merge?: boolean;
494
478
  }): Promise<void>;
495
- /** The type text a field's caption shows, by field code (default: the field type, `MERGEFIELD`). View. */
496
- setFieldTypes(options: {
497
- types: Record<string, string>;
498
- merge?: boolean;
499
- }): Promise<void>;
500
- /**
501
- * The merge fields (by name, their first argument) the data source lacks: drawn neutral, struck through. Replaces
502
- * the list, and `[]` clears it. View.
503
- */
504
- setUnmappedFields(options: {
505
- names: string[];
506
- }): Promise<void>;
507
479
  /** Which fields are sub-template references: replaces the rules; an empty list turns sub-templates off. View. */
508
480
  setSubTemplateRules(options: {
509
481
  rules: ReferenceRule[];
510
482
  }): Promise<void>;
483
+ /**
484
+ * The application's own field types (a code's first word, compared without case), replacing those set before:
485
+ * their fields keep their results, show their labels in design mode ({@link Commands.setFieldLabels}, else
486
+ * «first argument»), are listed by `fieldsUpdateRequested` and are never read as bookmark references
487
+ * ("Error! Bookmark not defined."). `[]` clears them. Set it after each `open`, as the rules. View.
488
+ */
489
+ setApplicationFieldTypes(options: {
490
+ types: string[];
491
+ }): Promise<void>;
511
492
  /** Shows references' sub-template bodies in their place, or their fields (default: every reference). View. */
512
493
  setSubTemplateView(options: {
513
494
  ids?: ElementId[];
@@ -538,10 +519,6 @@ export interface Commands {
538
519
  name: string;
539
520
  category?: string;
540
521
  }): Promise<void>;
541
- /** The version text sub-templates' cards and tabs show, and their newer versions; replaces the list. View. */
542
- setSubTemplateVersions(options: {
543
- versions: SubTemplateVersion[];
544
- }): Promise<void>;
545
522
  /** Inserts a content control, optionally around the selection. */
546
523
  insertControl(options: {
547
524
  kind: ControlKind;
@@ -615,14 +592,6 @@ export interface Commands {
615
592
  looks: PlaceholderLook[];
616
593
  merge?: boolean;
617
594
  }): Promise<void>;
618
- /** Draws a placeholder hovered until cleared (`null`), as when the application's field list hovers it. View. */
619
- highlightElement(options: {
620
- id: ElementId | null;
621
- }): Promise<void>;
622
- /** Selects the next placeholder in document order, wrapping; Tab while one is selected. View. */
623
- selectNextPlaceholder(): Promise<void>;
624
- /** Selects the previous placeholder in document order, wrapping; Shift+Tab while one is selected. View. */
625
- selectPreviousPlaceholder(): Promise<void>;
626
595
  /** Fills the selected placeholder, or every unfilled one with `key`: each becomes a plain picture, its content control removed. */
627
596
  fillPlaceholder(options: {
628
597
  key?: string;
@@ -699,7 +668,7 @@ export interface Commands {
699
668
  setZoom(zoom: number | 'pageWidth' | 'wholePage'): Promise<void>;
700
669
  /**
701
670
  * Sets view options: formatting marks (Ctrl+Shift+8), gridlines, text boundaries, live layout, the chrome's theme
702
- * and accent, the page's appearance, the measuring detail, the object grid and the placeholder UI.
671
+ * and accent, the page's appearance, the measuring detail and the object grid.
703
672
  */
704
673
  setViewOptions(options: ViewOptions): Promise<void>;
705
674
  /** Switches between editing and design mode. */
package/dist/commands.js CHANGED
@@ -143,16 +143,14 @@ const encodings = {
143
143
  unlinkFields: 'spread',
144
144
  showFieldCodes: 'spread',
145
145
  setFieldLabels: 'spread',
146
- setFieldTypes: 'spread',
147
- setUnmappedFields: 'spread',
148
146
  setSubTemplateRules: 'spread',
147
+ setApplicationFieldTypes: 'spread',
149
148
  setSubTemplateView: 'spread',
150
149
  editSubTemplate: 'spread',
151
150
  closeSubTemplate: 'none',
152
151
  createSubTemplate: 'spread',
153
152
  renameSubTemplate: 'spread',
154
153
  removeSubTemplate: 'spread',
155
- setSubTemplateVersions: 'spread',
156
154
  insertControl: 'spread',
157
155
  setControl: 'spread',
158
156
  removeControl: 'spread',
@@ -163,9 +161,6 @@ const encodings = {
163
161
  replaceInElements: 'spread',
164
162
  markElements: 'spread',
165
163
  setPlaceholderLooks: 'spread',
166
- highlightElement: 'spread',
167
- selectNextPlaceholder: 'none',
168
- selectPreviousPlaceholder: 'none',
169
164
  fillPlaceholder: 'spread',
170
165
  writeDataPart: 'spread',
171
166
  removeDataPart: 'spread',
package/dist/events.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { EditorError } from './errors.js';
2
2
  import type { BalloonPlacement, CommentAnchor } from './review.js';
3
3
  import type { AnnouncementKind } from './services/accessibility.js';
4
4
  import type { DialogKind } from './services/dialogs.js';
5
- import type { ElementInfo, SubTemplateReference } from './services/elements.js';
5
+ import type { ElementInfo } from './services/elements.js';
6
6
  import type { ContextMenuEvent } from './services/menus.js';
7
7
  import type { RulerView } from './services/ruler.js';
8
8
  import type { GestureEvent, Popover } from './services/view.js';
@@ -21,28 +21,10 @@ export interface TwipEvents {
21
21
  address: string;
22
22
  via: 'ctrlClick' | 'click';
23
23
  };
24
- /**
25
- * An unfilled picture placeholder was clicked, or one of its buttons (`action`: the button's id).
26
- */
24
+ /** An unfilled picture placeholder was clicked. */
27
25
  placeholderActivated: {
28
26
  key: string;
29
27
  element: ElementId | null;
30
- action?: string;
31
- };
32
- /**
33
- * With `placeholderUi` on, the pointer starts or stops being over a placeholder, or the hovered one's anchor moves;
34
- * `null` when it leaves.
35
- */
36
- placeholderHovered: PlaceholderTarget | null;
37
- /**
38
- * With `placeholderUi` on, the selection starts or stops covering exactly one placeholder, or the selected one's
39
- * anchor moves (scroll, zoom, layout); `null` when it's no longer selected.
40
- */
41
- placeholderSelected: PlaceholderTarget | null;
42
- /** A shown sub-template's newer-version notice (`setSubTemplateVersions`) was pressed: the application updates it. */
43
- subTemplateUpdateRequested: {
44
- name: string;
45
- category: string;
46
28
  };
47
29
  /**
48
30
  * Typing, pasting or dropping was refused: into a sub-template's body shown in place of its reference (edit the
@@ -158,7 +140,7 @@ export type HostCommand = 'save' | 'saveAs' | 'print' | 'open' | 'new' | 'find'
158
140
  /** A hover tooltip to show. */
159
141
  export interface Tooltip {
160
142
  /** What is hovered. */
161
- kind: 'link' | 'mark' | 'revision' | 'comment' | 'placeholder';
143
+ kind: 'link' | 'mark' | 'revision' | 'comment';
162
144
  /** The text to show. */
163
145
  text: string;
164
146
  /** The pointer. */
@@ -166,26 +148,3 @@ export interface Tooltip {
166
148
  /** The hovered thing's box. */
167
149
  rect: ClientRect;
168
150
  }
169
- /** What kind of placeholder a {@link PlaceholderTarget} is. */
170
- export type PlaceholderKind = 'field' | 'control' | 'repeatingSection' | 'subTemplate' | 'inputBlock' | 'ifField';
171
- /** A placeholder the pointer is over or the selection covers, with `placeholderUi` on. */
172
- export interface PlaceholderTarget {
173
- /** The field or control; absent for an input block outside a content control. */
174
- element?: ElementId;
175
- /** What it is. */
176
- kind: PlaceholderKind;
177
- /** What it shows, in full: a field's label or result, a control's title. */
178
- label: string;
179
- /** A field's name (its first argument), a control's tag, or a picture placeholder's key. */
180
- key?: string;
181
- /** A field's code. */
182
- code?: string;
183
- /** The caption's type text: `setFieldTypes`' text for the code, else the field type (`MERGEFIELD`), or a control's kind. */
184
- typeText: string;
185
- /** The data source lacks the field (`setUnmappedFields`). */
186
- unmapped: boolean;
187
- /** For a sub-template reference: what it names and whether its body shows. */
188
- reference?: SubTemplateReference;
189
- /** Where it is, in the same space as a popover's anchor: a field's last line, else its box. */
190
- anchor: ClientRect;
191
- }
@@ -112,7 +112,6 @@ export function startChrome(s, dom, ledger, frames, report, toViewport) {
112
112
  setThemeColors: (themeColors) => setLook({ themeColors }),
113
113
  setAppearance: (appearance) => setLook({ appearance }),
114
114
  setDetail: (detail) => setLook({ detail }),
115
- setPlaceholderUi: (placeholderUi) => setLook({ placeholderUi }),
116
115
  visiblePages: () => {
117
116
  const r = dom.canvas.getBoundingClientRect();
118
117
  return pages.map(({ page, rect }) => ({ page, rect: { ...rect, left: rect.left + r.left, top: rect.top + r.top } }));
@@ -34,10 +34,6 @@ export async function mountHost(container, s, options, claims) {
34
34
  const t = event;
35
35
  return { ...t, at: client(t.at), rect: { ...t.rect, left: t.rect.left + r.left, top: t.rect.top + r.top } };
36
36
  }
37
- if ((type === 'placeholderHovered' || type === 'placeholderSelected') && event) {
38
- const t = event;
39
- return { ...t, anchor: { ...t.anchor, left: t.anchor.left + r.left, top: t.anchor.top + r.top } };
40
- }
41
37
  if (type === 'popoverRequested') {
42
38
  const p = event;
43
39
  return { ...p, anchor: { ...p.anchor, left: p.anchor.left + r.left, top: p.anchor.top + r.top } };
package/dist/index.d.ts CHANGED
@@ -7,9 +7,9 @@
7
7
  export { Editor, HeadlessEditor } from './editor.js';
8
8
  export { configure } from './transport/module.js';
9
9
  export type { ExportOptions, ExportResult, MountOptions, PdfOptions, SessionOptions } from './editor.js';
10
- export type { CommandEntry, CommandId, CommandInfo, Commands, FieldTargets, NoArgumentCommandId, Op, OpArgs, PlaceholderAction, PlaceholderLook, } from './commands.js';
10
+ export type { CommandEntry, CommandId, CommandInfo, Commands, FieldTargets, NoArgumentCommandId, Op, OpArgs, PlaceholderLook, } from './commands.js';
11
11
  export type { AutoCorrectChange, AutoCorrectEntry, AutoCorrectOptions, CharacterFormatting, CommandState, CommandValues, EditingTarget, EditorState, ElementContext, HighlightColor, HorizontalPosition, HorizontalReference, LineSpacing, MarkupView, Mixed, ObjectHorizontalAlignment, ObjectPlacement, ObjectSelection, ObjectVerticalAlignment, ObjectWrap, PageFormatting, ParagraphFormatting, ReviewState, RowHeight, SelectionSummary, TablePosition, TableSelection, TableStyleOptions, TableWidth, TextDistance, Tri, UnderlineStyle, VerticalPosition, VerticalReference, ViewState, WrapSide, } from './state.js';
12
- export type { HostCommand, PlaceholderKind, PlaceholderTarget, Tooltip, TransactionRecord, TwipEvents } from './events.js';
12
+ export type { HostCommand, Tooltip, TransactionRecord, TwipEvents } from './events.js';
13
13
  export { EditorError } from './errors.js';
14
14
  export type { ErrorCode } from './errors.js';
15
15
  export { FontLibrary } from './fonts/library.js';
@@ -19,7 +19,7 @@ export type { ContextMenu, ContextMenuEvent, MenuAction, MenuItem, MenuTarget, M
19
19
  export type { AccessibilityDialogSession, DialogKind, DialogSession, DialogSessionOf, DialogValues, Dialogs, FieldInfo, } from './services/dialogs.js';
20
20
  export type { Find, FindMatch, FindQuery, FindResult } from './services/find.js';
21
21
  export type { Dictionary, Spelling } from './services/spelling.js';
22
- export type { Block, ControlKind, ControlOptions, DataBinding, DataParts, ElementDetail, ElementInfo, Elements, MountedElements, PlaceholderInfo, ReferenceResolution, ReferenceRule, SubTemplateInfo, SubTemplateReference, SubTemplates, SubTemplateVersion, } from './services/elements.js';
22
+ export type { Block, ControlKind, ControlOptions, DataBinding, DataParts, ElementDetail, ElementInfo, Elements, MountedElements, PlaceholderInfo, ReferenceResolution, ReferenceRule, SubTemplateInfo, SubTemplateReference, SubTemplates, } from './services/elements.js';
23
23
  export type { Accessibility, AccessibleId, AccessibleNode, AnnouncementKind, CellPlace, ListPosition, Shortcuts } from './services/accessibility.js';
24
24
  export type { Heading, Navigation, StyleInfo, Styles } from './services/navigation.js';
25
25
  export type { Ruler, RulerModel, RulerModelSource, RulerUnit, RulerView, TabAlignment, TabLeader, TabSelector, } from './services/ruler.js';
@@ -37,8 +37,6 @@ export interface PlaceholderInfo {
37
37
  key: string;
38
38
  /** The control it is in. */
39
39
  element: ElementId | null;
40
- /** The input block's button pressed (its id); absent: the block itself. */
41
- action?: string;
42
40
  }
43
41
  /** {@link Elements} on a mounted editor: adds drop targets and hit testing. */
44
42
  export interface MountedElements extends Elements {
@@ -93,17 +91,6 @@ export interface ReferenceRule {
93
91
  /** The building block gallery (`custom1`), when it matters. */
94
92
  gallery?: string;
95
93
  }
96
- /** A sub-template's version, as its card and its shown body's tab show it (`setSubTemplateVersions`). */
97
- export interface SubTemplateVersion {
98
- /** The sub-template's name. */
99
- name: string;
100
- /** Its category. Default: the first reference rule's. */
101
- category?: string;
102
- /** The version text (`v4`). */
103
- version: string;
104
- /** A newer version's notice (`v5 available`); a press on it raises `subTemplateUpdateRequested`. */
105
- newer?: string;
106
- }
107
94
  /** Whether a reference's sub-template resolves, or why its body can't show. */
108
95
  export type ReferenceResolution = 'resolved' | 'missing' | 'nearMatch' | 'cycle' | 'tooDeep' | 'notAlone' | 'notInBody';
109
96
  /** What a sub-template reference field names and whether its body shows. */
@@ -31,12 +31,6 @@ export interface View {
31
31
  setAppearance(appearance: DocumentAppearance): Promise<void>;
32
32
  /** How much the editor measures while you drag and hover. `setViewOptions` with `detail`. */
33
33
  setDetail(detail: MeasureDetail): Promise<void>;
34
- /**
35
- * Draws placeholders as editor UI (field marks, repeating sections, sub-template cards and input blocks), with the
36
- * `placeholderHovered` and `placeholderSelected` events; never changes the output. `setViewOptions` with
37
- * `placeholderUi`.
38
- */
39
- setPlaceholderUi(on: boolean): Promise<void>;
40
34
  /** The pages on screen, for a page navigator or a thumbnails strip. */
41
35
  visiblePages(): {
42
36
  page: number;
@@ -77,8 +71,6 @@ export interface ViewOptions {
77
71
  detail?: MeasureDetail;
78
72
  /** When the dot grid objects snap to shows (unrelated to `gridlines`, the table gridlines). */
79
73
  objectGrid?: ObjectGrid;
80
- /** Draws placeholders as editor UI: field marks, repeating sections, sub-template cards and input blocks. Default: off. */
81
- placeholderUi?: boolean;
82
74
  }
83
75
  /**
84
76
  * The editor chrome's colour scheme: the desk, rulers, handles, guides and readouts. `highContrast` takes the
package/dist/state.d.ts CHANGED
@@ -570,8 +570,6 @@ export interface ViewState {
570
570
  detail: MeasureDetail;
571
571
  /** When the objects' dot grid shows. */
572
572
  objectGrid: ObjectGrid;
573
- /** Placeholders are drawn as editor UI (`placeholderUi`). */
574
- placeholderUi: boolean;
575
573
  /** Which fields are sub-template references (`setSubTemplateRules`); absent when none are. */
576
574
  subTemplateRules?: ReferenceRule[];
577
575
  }
@@ -126,7 +126,7 @@ export function decodeEvent(wire) {
126
126
  return { type, event: 'value' in fields ? fields.value : fields };
127
127
  }
128
128
  /** The events whose payload always travels as `value`, an object or not: the engine's optional payloads. */
129
- const valueEvents = new Set(['tooltip', 'placeholderHovered', 'placeholderSelected']);
129
+ const valueEvents = new Set(['tooltip']);
130
130
  /** The inverse of {@link decodeEvent}. */
131
131
  export function encodeEvent(type, event) {
132
132
  if (event instanceof EditorError)
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twip/web",
3
- "version": "0.0.0-canary-7dfb59b",
3
+ "version": "0.0.0-canary-d060d80",
4
4
  "description": "The Twip DOCX editor for the browser and Node: a managed, framework-independent editor over the WebAssembly engine.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",