@ai-matrx/office 0.3.1 → 0.5.2
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/CHANGELOG.md +47 -2
- package/dist/chunk-2UBGQUXW.cjs +37 -0
- package/dist/chunk-2UBGQUXW.cjs.map +1 -0
- package/dist/chunk-5T2M6LSI.js +529 -0
- package/dist/chunk-5T2M6LSI.js.map +1 -0
- package/dist/chunk-BWMAYLW4.cjs +272 -0
- package/dist/chunk-BWMAYLW4.cjs.map +1 -0
- package/dist/chunk-IDEA5UXK.js +272 -0
- package/dist/chunk-IDEA5UXK.js.map +1 -0
- package/dist/chunk-MPKXXZZV.js +37 -0
- package/dist/chunk-MPKXXZZV.js.map +1 -0
- package/dist/chunk-O6FTSXHE.cjs +463 -0
- package/dist/chunk-O6FTSXHE.cjs.map +1 -0
- package/dist/chunk-PI473GES.js +463 -0
- package/dist/chunk-PI473GES.js.map +1 -0
- package/dist/chunk-QZE7HBZB.cjs +529 -0
- package/dist/chunk-QZE7HBZB.cjs.map +1 -0
- package/dist/chunk-WKBWRG7N.js +209 -0
- package/dist/chunk-WKBWRG7N.js.map +1 -0
- package/dist/chunk-ZDZCCOUB.cjs +209 -0
- package/dist/chunk-ZDZCCOUB.cjs.map +1 -0
- package/dist/core.d.cts +5 -1
- package/dist/core.d.ts +5 -1
- package/dist/docs-io.cjs +496 -0
- package/dist/docs-io.cjs.map +1 -0
- package/dist/docs-io.d.cts +147 -0
- package/dist/docs-io.d.ts +147 -0
- package/dist/docs-io.js +496 -0
- package/dist/docs-io.js.map +1 -0
- package/dist/docs-tools.cjs +217 -0
- package/dist/docs-tools.cjs.map +1 -0
- package/dist/docs-tools.d.cts +150 -0
- package/dist/docs-tools.d.ts +150 -0
- package/dist/docs-tools.js +217 -0
- package/dist/docs-tools.js.map +1 -0
- package/dist/docs.cjs +657 -0
- package/dist/docs.cjs.map +1 -0
- package/dist/docs.d.cts +582 -0
- package/dist/docs.d.ts +582 -0
- package/dist/docs.js +657 -0
- package/dist/docs.js.map +1 -0
- package/dist/matrxImagePorts-JDFYE4QI.cjs +59 -0
- package/dist/matrxImagePorts-JDFYE4QI.cjs.map +1 -0
- package/dist/matrxImagePorts-VPBBUADM.js +59 -0
- package/dist/matrxImagePorts-VPBBUADM.js.map +1 -0
- package/dist/sheets-xlsx.cjs +525 -0
- package/dist/sheets-xlsx.cjs.map +1 -0
- package/dist/sheets-xlsx.d.cts +153 -0
- package/dist/sheets-xlsx.d.ts +153 -0
- package/dist/sheets-xlsx.js +525 -0
- package/dist/sheets-xlsx.js.map +1 -0
- package/dist/sheets.cjs +921 -0
- package/dist/sheets.cjs.map +1 -0
- package/dist/sheets.d.cts +605 -0
- package/dist/sheets.d.ts +605 -0
- package/dist/sheets.js +921 -0
- package/dist/sheets.js.map +1 -0
- package/dist/univer-collab.cjs +4 -77
- package/dist/univer-collab.cjs.map +1 -1
- package/dist/univer-collab.d.cts +8 -15
- package/dist/univer-collab.d.ts +8 -15
- package/dist/univer-collab.js +4 -77
- package/dist/univer-collab.js.map +1 -1
- package/dist/univer-realtime.cjs +102 -0
- package/dist/univer-realtime.cjs.map +1 -0
- package/dist/univer-realtime.d.cts +15 -0
- package/dist/univer-realtime.d.ts +15 -0
- package/dist/univer-realtime.js +80 -0
- package/dist/univer-realtime.js.map +1 -0
- package/dist/xlsx-to-univer-AQAXU3TC.cjs +7 -0
- package/dist/xlsx-to-univer-AQAXU3TC.cjs.map +1 -0
- package/dist/xlsx-to-univer-OPMMBWEW.js +7 -0
- package/dist/xlsx-to-univer-OPMMBWEW.js.map +1 -0
- package/package.json +75 -4
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkO6FTSXHEcjs = require('./chunk-O6FTSXHE.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk2UBGQUXWcjs = require('./chunk-2UBGQUXW.cjs');
|
|
7
|
+
|
|
8
|
+
// src/docs/doc-tools-core.ts
|
|
9
|
+
var BUILDING_BLOCKS = [
|
|
10
|
+
{ id: "meeting-notes", label: "Meeting notes", description: "Date, attendees, agenda, decisions and action items.", markdown: "## Meeting notes\n\nDate: \nAttendees: \n\n### Agenda\n\n1. \n\n### Discussion\n\n### Decisions\n\n### Action items\n\n\u2610 Owner: Task, due date\n" },
|
|
11
|
+
{ id: "project-tracker", label: "Project tracker", description: "Goal, milestones, owners, risks and status.", markdown: "## Project tracker\n\nGoal: \nOwner: \nStatus: On track\n\n### Milestones\n\n\u2610 Milestone, owner, due date\n\n### Risks\n\n### Next steps\n" },
|
|
12
|
+
{ id: "email-draft", label: "Email draft", description: "To, subject and a three-part message ready to fill in.", markdown: "## Email draft\n\nTo: \nSubject: \n\nHi ,\n\nI am writing about .\n\nThe next step is .\n\nThanks,\n" },
|
|
13
|
+
{ id: "weekly-status", label: "Weekly status", description: "Done, next, and blocked, for one week.", markdown: "## Weekly status\n\nWeek of: \n\n### Done this week\n\n### Next week\n\n### Blocked\n" },
|
|
14
|
+
{ id: "decision-log", label: "Decision record", description: "Context, options, decision and consequences.", markdown: "## Decision record\n\nDate: \nDecider: \n\n### Context\n\n### Options considered\n\n### Decision\n\n### Consequences\n" },
|
|
15
|
+
{ id: "pros-cons", label: "Pros and cons", description: "A side-by-side weighing of one choice.", markdown: "## Pros and cons\n\nChoice: \n\n### Pros\n\n### Cons\n\n### Verdict\n" }
|
|
16
|
+
];
|
|
17
|
+
function insertableBody(markdown) {
|
|
18
|
+
const body = _nullishCoalesce(_chunkO6FTSXHEcjs.markdownToUniverDoc.call(void 0, markdown).body, () => ( { dataStream: "" }));
|
|
19
|
+
let stream = body.dataStream;
|
|
20
|
+
if (stream.endsWith("\n")) stream = stream.slice(0, -1);
|
|
21
|
+
const paragraphs = (_nullishCoalesce(body.paragraphs, () => ( []))).filter((p) => p.startIndex < stream.length);
|
|
22
|
+
const textRuns = (_nullishCoalesce(body.textRuns, () => ( []))).filter((r) => r.st < stream.length).map((r) => ({ ...r, ed: Math.min(r.ed, stream.length) }));
|
|
23
|
+
return { dataStream: stream, paragraphs, ...textRuns.length ? { textRuns } : {} };
|
|
24
|
+
}
|
|
25
|
+
function blockInsertPlan(dataStream, caret) {
|
|
26
|
+
const c = Math.max(0, Math.min(caret, dataStream.length));
|
|
27
|
+
const start = Math.max(dataStream.lastIndexOf("\r", c - 1), dataStream.lastIndexOf("\n", c - 1)) + 1;
|
|
28
|
+
let end = dataStream.indexOf("\r", c);
|
|
29
|
+
if (end < 0) end = dataStream.length;
|
|
30
|
+
const text = dataStream.slice(start, end).replace(/[\u0000-\u001f\u200b]/g, "").trim();
|
|
31
|
+
if (c === start || text === "") return { at: start, breakAt: null };
|
|
32
|
+
return { at: end + 1, breakAt: end };
|
|
33
|
+
}
|
|
34
|
+
var BOOKMARK_RANGE_TYPE = 3;
|
|
35
|
+
var BOOKMARK_ANCHOR = "\u200B";
|
|
36
|
+
function collectBookmarks(snapshot) {
|
|
37
|
+
const body = _optionalChain([snapshot, 'optionalAccess', _ => _.body]);
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const r of _nullishCoalesce(_optionalChain([body, 'optionalAccess', _2 => _2.customRanges]), () => ( []))) {
|
|
40
|
+
if (r.rangeType !== BOOKMARK_RANGE_TYPE) continue;
|
|
41
|
+
out.push({ id: r.rangeId, name: typeof _optionalChain([r, 'access', _3 => _3.properties, 'optionalAccess', _4 => _4.name]) === "string" ? r.properties.name : "", offset: r.startIndex });
|
|
42
|
+
}
|
|
43
|
+
return out.sort((a, b) => a.offset - b.offset);
|
|
44
|
+
}
|
|
45
|
+
function bookmarkBody(id, name) {
|
|
46
|
+
return {
|
|
47
|
+
dataStream: BOOKMARK_ANCHOR,
|
|
48
|
+
customRanges: [{ startIndex: 0, endIndex: 0, rangeId: id, rangeType: BOOKMARK_RANGE_TYPE, properties: { name }, wholeEntity: true }]
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function cleanBookmarkName(raw, existing) {
|
|
52
|
+
const name = raw.replace(/\s+/g, " ").trim().slice(0, 80);
|
|
53
|
+
if (!name) return { ok: false, why: "Give the bookmark a name." };
|
|
54
|
+
if (existing.some((b) => b.name.toLowerCase() === name.toLowerCase())) return { ok: false, why: `A bookmark named "${name}" already exists.` };
|
|
55
|
+
return { ok: true, name };
|
|
56
|
+
}
|
|
57
|
+
function bookmarkFromHash(hash) {
|
|
58
|
+
const m = /^#bookmark=(.+)$/.exec(hash);
|
|
59
|
+
if (!m) return null;
|
|
60
|
+
try {
|
|
61
|
+
return decodeURIComponent(m[1]);
|
|
62
|
+
} catch (e2) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
var bookmarkHash = (name) => `#bookmark=${encodeURIComponent(name)}`;
|
|
67
|
+
var DASH = { solid: 1, dotted: 2, dashed: 3 };
|
|
68
|
+
function paragraphBorderParams(c) {
|
|
69
|
+
const line = { color: { rgb: c.color }, width: c.width, dashStyle: DASH[c.dash], padding: c.padding };
|
|
70
|
+
return {
|
|
71
|
+
borderTop: c.side === "top" || c.side === "both" ? line : null,
|
|
72
|
+
borderBottom: c.side === "bottom" || c.side === "both" ? line : null
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function rulerGeometry(a) {
|
|
76
|
+
const pageWidth = a.pageWidthPx * a.zoom;
|
|
77
|
+
const pageLeft = Math.max(0, (a.containerWidth - pageWidth) / 2);
|
|
78
|
+
const ticks = [];
|
|
79
|
+
const inches = a.pageWidthPx / _chunk2UBGQUXWcjs.PX_PER_INCH;
|
|
80
|
+
for (let eighth = 0; eighth <= Math.floor(inches * 8); eighth++) {
|
|
81
|
+
const x = pageLeft + eighth * _chunk2UBGQUXWcjs.PX_PER_INCH * a.zoom / 8;
|
|
82
|
+
if (eighth % 8 === 0) {
|
|
83
|
+
const marginInches = a.marginLeftPx / _chunk2UBGQUXWcjs.PX_PER_INCH;
|
|
84
|
+
ticks.push({ x, kind: "inch", ...eighth / 8 !== marginInches ? { label: String(Math.round(Math.abs(eighth / 8 - marginInches))) } : {} });
|
|
85
|
+
} else ticks.push({ x, kind: eighth % 4 === 0 ? "half" : "eighth" });
|
|
86
|
+
}
|
|
87
|
+
return { pageLeft, pageWidth, marginLeft: a.marginLeftPx * a.zoom, marginRight: a.marginRightPx * a.zoom, ticks };
|
|
88
|
+
}
|
|
89
|
+
var DOCUMENT_LANGUAGE_KEY = "matrxLanguage";
|
|
90
|
+
var DOCUMENT_LANGUAGES = [
|
|
91
|
+
{ code: "en-US", label: "English (United States)" },
|
|
92
|
+
{ code: "en-GB", label: "English (United Kingdom)" },
|
|
93
|
+
{ code: "es", label: "Spanish" },
|
|
94
|
+
{ code: "fr", label: "French" },
|
|
95
|
+
{ code: "de", label: "German" },
|
|
96
|
+
{ code: "it", label: "Italian" },
|
|
97
|
+
{ code: "pt-BR", label: "Portuguese (Brazil)" },
|
|
98
|
+
{ code: "nl", label: "Dutch" },
|
|
99
|
+
{ code: "ja", label: "Japanese" },
|
|
100
|
+
{ code: "ko", label: "Korean" },
|
|
101
|
+
{ code: "zh-CN", label: "Chinese (Simplified)" },
|
|
102
|
+
{ code: "ar", label: "Arabic" },
|
|
103
|
+
{ code: "hi", label: "Hindi" },
|
|
104
|
+
{ code: "ru", label: "Russian" }
|
|
105
|
+
];
|
|
106
|
+
function readDocumentLanguage(documentStyle) {
|
|
107
|
+
const v = _optionalChain([documentStyle, 'optionalAccess', _5 => _5[DOCUMENT_LANGUAGE_KEY]]);
|
|
108
|
+
return typeof v === "string" && DOCUMENT_LANGUAGES.some((l) => l.code === v) ? v : "en-US";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/docs/doc-edit-ops.ts
|
|
112
|
+
function createDocEditOps(deps) {
|
|
113
|
+
const doc = () => _nullishCoalesce(_optionalChain([deps, 'access', _6 => _6.api, 'call', _7 => _7(), 'optionalAccess', _8 => _8.getActiveDocument, 'optionalCall', _9 => _9()]), () => ( null));
|
|
114
|
+
const snapshot = () => _nullishCoalesce(_optionalChain([doc, 'call', _10 => _10(), 'optionalAccess', _11 => _11.save, 'optionalCall', _12 => _12()]), () => ( null));
|
|
115
|
+
const range = async () => {
|
|
116
|
+
const { DocSelectionManagerService } = await Promise.resolve().then(() => _interopRequireWildcard(require("@univerjs/docs")));
|
|
117
|
+
const live = _optionalChain([deps, 'access', _13 => _13.injector, 'call', _14 => _14(), 'optionalAccess', _15 => _15.get, 'call', _16 => _16(DocSelectionManagerService), 'optionalAccess', _17 => _17.getActiveTextRange, 'optionalCall', _18 => _18()]);
|
|
118
|
+
return _nullishCoalesce(live, () => ( null));
|
|
119
|
+
};
|
|
120
|
+
const exec = async (id, params) => await _optionalChain([deps, 'access', _19 => _19.api, 'call', _20 => _20(), 'optionalAccess', _21 => _21.executeCommand, 'call', _22 => _22(id, params)]) !== false;
|
|
121
|
+
const toBlockStart = async () => {
|
|
122
|
+
const d = doc();
|
|
123
|
+
const r = await range();
|
|
124
|
+
const stream = _optionalChain([snapshot, 'call', _23 => _23(), 'optionalAccess', _24 => _24.body, 'optionalAccess', _25 => _25.dataStream]);
|
|
125
|
+
if (!d || !r || typeof stream !== "string") return false;
|
|
126
|
+
const plan = blockInsertPlan(stream, r.startOffset);
|
|
127
|
+
if (plan.breakAt === null) {
|
|
128
|
+
_optionalChain([d, 'access', _26 => _26.setSelection, 'optionalCall', _27 => _27(plan.at, plan.at)]);
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
_optionalChain([d, 'access', _28 => _28.setSelection, 'optionalCall', _29 => _29(plan.breakAt, plan.breakAt)]);
|
|
132
|
+
return exec("doc.command.break-line", { unitId: d.getId() });
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
snapshot,
|
|
136
|
+
async insertText(text) {
|
|
137
|
+
if (!text || !await range()) return false;
|
|
138
|
+
return exec("doc.command.insert-special-character", { value: text });
|
|
139
|
+
},
|
|
140
|
+
toBlockStart,
|
|
141
|
+
async insertMarkdown(markdown) {
|
|
142
|
+
const d = doc();
|
|
143
|
+
if (!d || !await toBlockStart()) return false;
|
|
144
|
+
return exec("doc.command.replace-selection", { unitId: d.getId(), body: insertableBody(markdown) });
|
|
145
|
+
},
|
|
146
|
+
bookmarks: () => collectBookmarks(snapshot()),
|
|
147
|
+
async addBookmark(name) {
|
|
148
|
+
const d = doc();
|
|
149
|
+
const r = await range();
|
|
150
|
+
if (!d || !r) return false;
|
|
151
|
+
_optionalChain([d, 'access', _30 => _30.setSelection, 'optionalCall', _31 => _31(r.startOffset, r.startOffset)]);
|
|
152
|
+
const id = `bm_${Math.random().toString(36).slice(2, 10)}`;
|
|
153
|
+
return exec("doc.command.replace-selection", { unitId: d.getId(), body: bookmarkBody(id, name) });
|
|
154
|
+
},
|
|
155
|
+
async deleteBookmark(b) {
|
|
156
|
+
const d = doc();
|
|
157
|
+
if (!d) return false;
|
|
158
|
+
_optionalChain([d, 'access', _32 => _32.setSelection, 'optionalCall', _33 => _33(b.offset + 1, b.offset + 1)]);
|
|
159
|
+
return exec("doc.command.delete-left", { unitId: d.getId() });
|
|
160
|
+
},
|
|
161
|
+
async setViewOnly(viewOnly) {
|
|
162
|
+
const perm = _optionalChain([doc, 'call', _34 => _34(), 'optionalAccess', _35 => _35.getPermission, 'optionalCall', _36 => _36()]);
|
|
163
|
+
if (!perm) return;
|
|
164
|
+
if (viewOnly) await perm.setReadOnly();
|
|
165
|
+
else await perm.setEditable(true);
|
|
166
|
+
const { IPermissionService } = await Promise.resolve().then(() => _interopRequireWildcard(require("@univerjs/core")));
|
|
167
|
+
_optionalChain([deps, 'access', _37 => _37.injector, 'call', _38 => _38(), 'optionalAccess', _39 => _39.get, 'call', _40 => _40(IPermissionService), 'optionalAccess', _41 => _41.setShowComponents, 'optionalCall', _42 => _42(!viewOnly)]);
|
|
168
|
+
},
|
|
169
|
+
async onEditDenied(cb) {
|
|
170
|
+
const { ErrorService } = await Promise.resolve().then(() => _interopRequireWildcard(require("@univerjs/core")));
|
|
171
|
+
const errors = _optionalChain([deps, 'access', _43 => _43.injector, 'call', _44 => _44(), 'optionalAccess', _45 => _45.get, 'call', _46 => _46(ErrorService)]);
|
|
172
|
+
const sub = _optionalChain([errors, 'optionalAccess', _47 => _47.error$, 'optionalAccess', _48 => _48.subscribe, 'call', _49 => _49((e) => {
|
|
173
|
+
if (e.code === "PERMISSION_DENIED") cb();
|
|
174
|
+
})]);
|
|
175
|
+
return () => _optionalChain([sub, 'optionalAccess', _50 => _50.unsubscribe, 'call', _51 => _51()]);
|
|
176
|
+
},
|
|
177
|
+
async openImagePanel() {
|
|
178
|
+
return exec("sidebar.operation.doc-image", { value: "doc-image" });
|
|
179
|
+
},
|
|
180
|
+
goTo(offset) {
|
|
181
|
+
_optionalChain([doc, 'call', _52 => _52(), 'optionalAccess', _53 => _53.setSelection, 'optionalCall', _54 => _54(offset, offset)]);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
async function writeDocumentStyleKey(api, key, value) {
|
|
186
|
+
const doc = _optionalChain([api, 'access', _55 => _55.getActiveDocument, 'optionalCall', _56 => _56()]);
|
|
187
|
+
if (!doc) return;
|
|
188
|
+
const style = _nullishCoalesce(_optionalChain([doc, 'access', _57 => _57.getDocumentDataModel, 'optionalCall', _58 => _58(), 'optionalAccess', _59 => _59.getSnapshot, 'call', _60 => _60(), 'access', _61 => _61.documentStyle]), () => ( {}));
|
|
189
|
+
const old = style[key];
|
|
190
|
+
if (old === value) return;
|
|
191
|
+
const { JSONX } = await Promise.resolve().then(() => _interopRequireWildcard(require("@univerjs/core")));
|
|
192
|
+
const jsonX = JSONX.getInstance();
|
|
193
|
+
const path = ["documentStyle", key];
|
|
194
|
+
const action = old === void 0 ? jsonX.insertOp(path, value) : jsonX.replaceOp(path, old, value);
|
|
195
|
+
if (!action) return;
|
|
196
|
+
await api.executeCommand("doc.mutation.rich-text-editing", { unitId: doc.getId(), actions: action, textRanges: void 0 });
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
exports.BOOKMARK_ANCHOR = BOOKMARK_ANCHOR; exports.BOOKMARK_RANGE_TYPE = BOOKMARK_RANGE_TYPE; exports.BUILDING_BLOCKS = BUILDING_BLOCKS; exports.DOCUMENT_LANGUAGES = DOCUMENT_LANGUAGES; exports.DOCUMENT_LANGUAGE_KEY = DOCUMENT_LANGUAGE_KEY; exports.blockInsertPlan = blockInsertPlan; exports.bookmarkBody = bookmarkBody; exports.bookmarkFromHash = bookmarkFromHash; exports.bookmarkHash = bookmarkHash; exports.cleanBookmarkName = cleanBookmarkName; exports.collectBookmarks = collectBookmarks; exports.createDocEditOps = createDocEditOps; exports.insertableBody = insertableBody; exports.paragraphBorderParams = paragraphBorderParams; exports.readDocumentLanguage = readDocumentLanguage; exports.rulerGeometry = rulerGeometry; exports.writeDocumentStyleKey = writeDocumentStyleKey;
|
|
217
|
+
//# sourceMappingURL=docs-tools.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/aidream/aidream/apps/shared/office/dist/docs-tools.cjs","../src/docs/doc-tools-core.ts","../src/docs/doc-edit-ops.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACQO,IAAM,gBAAA,EAAmC;AAAA,EAC9C,EAAE,EAAA,EAAI,eAAA,EAAiB,KAAA,EAAO,eAAA,EAAiB,WAAA,EAAa,sDAAA,EAAwD,QAAA,EAAU,wJAAmJ,CAAA;AAAA,EACjR,EAAE,EAAA,EAAI,iBAAA,EAAmB,KAAA,EAAO,iBAAA,EAAmB,WAAA,EAAa,6CAAA,EAA+C,QAAA,EAAU,kJAA6I,CAAA;AAAA,EACtQ,EAAE,EAAA,EAAI,aAAA,EAAe,KAAA,EAAO,aAAA,EAAe,WAAA,EAAa,wDAAA,EAA0D,QAAA,EAAU,uGAAuG,CAAA;AAAA,EACnO,EAAE,EAAA,EAAI,eAAA,EAAiB,KAAA,EAAO,eAAA,EAAiB,WAAA,EAAa,wCAAA,EAA0C,QAAA,EAAU,wFAAwF,CAAA;AAAA,EACxM,EAAE,EAAA,EAAI,cAAA,EAAgB,KAAA,EAAO,iBAAA,EAAmB,WAAA,EAAa,8CAAA,EAAgD,QAAA,EAAU,yHAAyH,CAAA;AAAA,EAChP,EAAE,EAAA,EAAI,WAAA,EAAa,KAAA,EAAO,eAAA,EAAiB,WAAA,EAAa,wCAAA,EAA0C,QAAA,EAAU,wEAAwE;AACtL,CAAA;AASO,SAAS,cAAA,CAAe,QAAA,EAAkC;AAC/D,EAAA,MAAM,KAAA,mBAAQ,mDAAA,QAA4B,CAAA,CAAE,IAAA,UAAQ,EAAE,UAAA,EAAY,GAAG,GAAA;AACrE,EAAA,IAAI,OAAA,EAAS,IAAA,CAAK,UAAA;AAClB,EAAA,GAAA,CAAI,MAAA,CAAO,QA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AACiC,MAAA;AACmF,MAAA;AAC5F,MAAA;AACJ,QAAA;AACxC,MAAA;AAC6B,MAAA;AAChC,IAAA;AACuB,IAAA;AAC+B,MAAA;AACtD,IAAA;AACa,IAAA;AACyB,sBAAA;AACtC,IAAA;AACF,EAAA;AACF;AAGqG;AAC/D,EAAA;AAC1B,EAAA;AAC4J,EAAA;AACjJ,EAAA;AACF,EAAA;AAC4B,EAAA;AACf,EAAA;AACE,EAAA;AAC+B,EAAA;AACpD,EAAA;AACgD,EAAA;AAC/D;AFkEmE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/aidream/aidream/apps/shared/office/dist/docs-tools.cjs","sourcesContent":[null,"/**\n * The pure half of the Docs tools: building blocks, bookmarks, paragraph borders, the ruler's\n * geometry and the document language. No Univer import, so each is proven on plain snapshots.\n */\n\nimport { PX_PER_INCH } from \"../core\";\nimport { markdownToUniverDoc } from \"./markdown-to-univer-doc\";\n\nexport interface BuildingBlock {\n id: string;\n label: string;\n description: string;\n markdown: string;\n}\n\nexport const BUILDING_BLOCKS: BuildingBlock[] = [\n { id: \"meeting-notes\", label: \"Meeting notes\", description: \"Date, attendees, agenda, decisions and action items.\", markdown: \"## Meeting notes\\n\\nDate: \\nAttendees: \\n\\n### Agenda\\n\\n1. \\n\\n### Discussion\\n\\n### Decisions\\n\\n### Action items\\n\\n☐ Owner: Task, due date\\n\" },\n { id: \"project-tracker\", label: \"Project tracker\", description: \"Goal, milestones, owners, risks and status.\", markdown: \"## Project tracker\\n\\nGoal: \\nOwner: \\nStatus: On track\\n\\n### Milestones\\n\\n☐ Milestone, owner, due date\\n\\n### Risks\\n\\n### Next steps\\n\" },\n { id: \"email-draft\", label: \"Email draft\", description: \"To, subject and a three-part message ready to fill in.\", markdown: \"## Email draft\\n\\nTo: \\nSubject: \\n\\nHi ,\\n\\nI am writing about .\\n\\nThe next step is .\\n\\nThanks,\\n\" },\n { id: \"weekly-status\", label: \"Weekly status\", description: \"Done, next, and blocked, for one week.\", markdown: \"## Weekly status\\n\\nWeek of: \\n\\n### Done this week\\n\\n### Next week\\n\\n### Blocked\\n\" },\n { id: \"decision-log\", label: \"Decision record\", description: \"Context, options, decision and consequences.\", markdown: \"## Decision record\\n\\nDate: \\nDecider: \\n\\n### Context\\n\\n### Options considered\\n\\n### Decision\\n\\n### Consequences\\n\" },\n { id: \"pros-cons\", label: \"Pros and cons\", description: \"A side-by-side weighing of one choice.\", markdown: \"## Pros and cons\\n\\nChoice: \\n\\n### Pros\\n\\n### Cons\\n\\n### Verdict\\n\" },\n];\n\nexport interface InsertableBody {\n dataStream: string;\n paragraphs: Array<{ startIndex: number; paragraphStyle?: Record<string, unknown> }>;\n textRuns?: Array<{ st: number; ed: number; ts?: Record<string, unknown> }>;\n}\n\n/** Markdown to a body Univer can insert at the caret: the document-closing `\\n` is dropped. */\nexport function insertableBody(markdown: string): InsertableBody {\n const body = (markdownToUniverDoc(markdown).body ?? { dataStream: \"\" }) as unknown as Partial<InsertableBody> & { dataStream: string };\n let stream = body.dataStream;\n if (stream.endsWith(\"\\n\")) stream = stream.slice(0, -1);\n const paragraphs = (body.paragraphs ?? []).filter((p) => p.startIndex < stream.length);\n const textRuns = (body.textRuns ?? []).filter((r) => r.st < stream.length).map((r) => ({ ...r, ed: Math.min(r.ed, stream.length) }));\n return { dataStream: stream, paragraphs, ...(textRuns.length ? { textRuns } : {}) };\n}\n\n/**\n * Where a BLOCK (table of contents, building block) goes for a caret: never inside a paragraph's\n * text, so a heading is never split. Caret at the start of a paragraph (or in an empty one) →\n * insert right there; anywhere else → end the caret's paragraph with a new line and insert at the\n * start of that new paragraph. `dataStream` is Univer's body stream (paragraphs end in `\\r`).\n */\nexport function blockInsertPlan(dataStream: string, caret: number): { at: number; breakAt: number | null } {\n const c = Math.max(0, Math.min(caret, dataStream.length));\n const start = Math.max(dataStream.lastIndexOf(\"\\r\", c - 1), dataStream.lastIndexOf(\"\\n\", c - 1)) + 1;\n let end = dataStream.indexOf(\"\\r\", c);\n if (end < 0) end = dataStream.length;\n // Field marks and anchors are zero-width: a paragraph holding only them is empty.\n const text = dataStream.slice(start, end).replace(/[\\u0000-\\u001f\\u200b]/g, \"\").trim();\n if (c === start || text === \"\") return { at: start, breakAt: null };\n return { at: end + 1, breakAt: end };\n}\n\n/** Univer's CustomRangeType.BOOKMARK. */\nexport const BOOKMARK_RANGE_TYPE = 3;\n/** A bookmark is an invisible anchor: one zero-width character the custom range wraps. */\nexport const BOOKMARK_ANCHOR = \"\";\n\nexport interface Bookmark {\n id: string;\n name: string;\n offset: number;\n}\n\ninterface BodyWithRanges {\n customRanges?: Array<{ rangeId: string; rangeType: number; startIndex: number; properties?: { name?: unknown } }>;\n}\n\nexport function collectBookmarks(snapshot: unknown): Bookmark[] {\n const body = (snapshot as { body?: BodyWithRanges } | null)?.body;\n const out: Bookmark[] = [];\n for (const r of body?.customRanges ?? []) {\n if (r.rangeType !== BOOKMARK_RANGE_TYPE) continue;\n out.push({ id: r.rangeId, name: typeof r.properties?.name === \"string\" ? r.properties.name : \"\", offset: r.startIndex });\n }\n return out.sort((a, b) => a.offset - b.offset);\n}\n\nexport function bookmarkBody(id: string, name: string) {\n return {\n dataStream: BOOKMARK_ANCHOR,\n customRanges: [{ startIndex: 0, endIndex: 0, rangeId: id, rangeType: BOOKMARK_RANGE_TYPE, properties: { name }, wholeEntity: true }],\n };\n}\n\nexport function cleanBookmarkName(raw: string, existing: readonly Bookmark[]): { ok: true; name: string } | { ok: false; why: string } {\n const name = raw.replace(/\\s+/g, \" \").trim().slice(0, 80);\n if (!name) return { ok: false, why: \"Give the bookmark a name.\" };\n if (existing.some((b) => b.name.toLowerCase() === name.toLowerCase())) return { ok: false, why: `A bookmark named \"${name}\" already exists.` };\n return { ok: true, name };\n}\n\n/** `#bookmark=<name>` in the page address names a bookmark to jump to on open. */\nexport function bookmarkFromHash(hash: string): string | null {\n const m = /^#bookmark=(.+)$/.exec(hash);\n if (!m) return null;\n try {\n return decodeURIComponent(m[1]!);\n } catch {\n return null;\n }\n}\nexport const bookmarkHash = (name: string) => `#bookmark=${encodeURIComponent(name)}`;\n\nexport type BorderSide = \"top\" | \"bottom\" | \"both\" | \"none\";\nexport type BorderDash = \"solid\" | \"dashed\" | \"dotted\";\n/** Univer's DashStyleType values. */\nconst DASH: Record<BorderDash, number> = { solid: 1, dotted: 2, dashed: 3 };\n\nexport interface BorderChoice {\n side: BorderSide;\n color: string;\n width: number;\n dash: BorderDash;\n padding: number;\n}\n\n/** The `paragraph` argument of `doc-paragraph-setting.command` for a choice (Univer draws top and bottom paragraph borders). */\nexport function paragraphBorderParams(c: BorderChoice): Record<string, unknown> {\n const line = { color: { rgb: c.color }, width: c.width, dashStyle: DASH[c.dash], padding: c.padding };\n return {\n borderTop: c.side === \"top\" || c.side === \"both\" ? line : null,\n borderBottom: c.side === \"bottom\" || c.side === \"both\" ? line : null,\n };\n}\n\nexport interface RulerGeometry {\n pageLeft: number;\n pageWidth: number;\n marginLeft: number;\n marginRight: number;\n ticks: Array<{ x: number; kind: \"inch\" | \"half\" | \"eighth\"; label?: string }>;\n}\n\n/** The ruler above the page: inch ticks from the page's left edge (margins shaded), at the current zoom. */\nexport function rulerGeometry(a: { containerWidth: number; zoom: number; pageWidthPx: number; marginLeftPx: number; marginRightPx: number }): RulerGeometry {\n const pageWidth = a.pageWidthPx * a.zoom;\n const pageLeft = Math.max(0, (a.containerWidth - pageWidth) / 2);\n const ticks: RulerGeometry[\"ticks\"] = [];\n const inches = a.pageWidthPx / PX_PER_INCH;\n for (let eighth = 0; eighth <= Math.floor(inches * 8); eighth++) {\n const x = pageLeft + (eighth * PX_PER_INCH * a.zoom) / 8;\n if (eighth % 8 === 0) {\n const marginInches = a.marginLeftPx / PX_PER_INCH;\n ticks.push({ x, kind: \"inch\", ...(eighth / 8 !== marginInches ? { label: String(Math.round(Math.abs(eighth / 8 - marginInches))) } : {}) });\n } else ticks.push({ x, kind: eighth % 4 === 0 ? \"half\" : \"eighth\" });\n }\n return { pageLeft, pageWidth, marginLeft: a.marginLeftPx * a.zoom, marginRight: a.marginRightPx * a.zoom, ticks };\n}\n\n/** The key on the document style that carries the language (the slot the paper colour also uses). */\nexport const DOCUMENT_LANGUAGE_KEY = \"matrxLanguage\";\nexport const DOCUMENT_LANGUAGES: Array<{ code: string; label: string }> = [\n { code: \"en-US\", label: \"English (United States)\" },\n { code: \"en-GB\", label: \"English (United Kingdom)\" },\n { code: \"es\", label: \"Spanish\" },\n { code: \"fr\", label: \"French\" },\n { code: \"de\", label: \"German\" },\n { code: \"it\", label: \"Italian\" },\n { code: \"pt-BR\", label: \"Portuguese (Brazil)\" },\n { code: \"nl\", label: \"Dutch\" },\n { code: \"ja\", label: \"Japanese\" },\n { code: \"ko\", label: \"Korean\" },\n { code: \"zh-CN\", label: \"Chinese (Simplified)\" },\n { code: \"ar\", label: \"Arabic\" },\n { code: \"hi\", label: \"Hindi\" },\n { code: \"ru\", label: \"Russian\" },\n];\n\nexport function readDocumentLanguage(documentStyle: unknown): string {\n const v = (documentStyle as Record<string, unknown> | undefined)?.[DOCUMENT_LANGUAGE_KEY];\n return typeof v === \"string\" && DOCUMENT_LANGUAGES.some((l) => l.code === v) ? v : \"en-US\";\n}\n","/**\n * The Univer-facing half of the Docs tools: insert text, markdown and bookmarks at the caret, move\n * the selection, read the live snapshot, set view-only. Every operation is a real Univer command.\n */\n\nimport { blockInsertPlan, bookmarkBody, collectBookmarks, insertableBody, type Bookmark } from \"./doc-tools-core\";\n\ninterface ApiLike {\n executeCommand(id: string, params?: object): Promise<unknown> | unknown;\n getActiveDocument?(): {\n getId(): string;\n save?(): unknown;\n setSelection?(a: number, b: number): void;\n getPermission?(): { setReadOnly(): Promise<void>; setEditable(editable?: boolean): Promise<void> };\n } | null;\n}\ninterface InjectorLike {\n get<T>(token: unknown): T | undefined;\n}\ninterface TextRangeLike {\n startOffset: number;\n endOffset: number;\n}\n\nexport interface DocEditOps {\n insertText(text: string): Promise<boolean>;\n /** A block (building block) at a new paragraph, never mid-line. */\n insertMarkdown(markdown: string): Promise<boolean>;\n /** Move the caret to where a block goes (`blockInsertPlan`); false when there is no caret. */\n toBlockStart(): Promise<boolean>;\n bookmarks(): Bookmark[];\n addBookmark(name: string): Promise<boolean>;\n deleteBookmark(b: Bookmark): Promise<boolean>;\n goTo(offset: number): void;\n snapshot(): unknown;\n setViewOnly(viewOnly: boolean): Promise<void>;\n /** Calls back when Univer refuses an edit (Viewing mode); returns the unsubscribe. */\n onEditDenied(cb: () => void): Promise<() => void>;\n openImagePanel(): Promise<boolean>;\n}\n\nexport function createDocEditOps(deps: { api: () => ApiLike | null; injector: () => InjectorLike | null }): DocEditOps {\n const doc = () => deps.api()?.getActiveDocument?.() ?? null;\n const snapshot = () => doc()?.save?.() ?? null;\n const range = async (): Promise<TextRangeLike | null> => {\n const { DocSelectionManagerService } = await import(\"@univerjs/docs\");\n const live = deps.injector()?.get<{ getActiveTextRange?(): TextRangeLike | null | undefined }>(DocSelectionManagerService)?.getActiveTextRange?.();\n return live ?? null;\n };\n const exec = async (id: string, params: object) => (await deps.api()?.executeCommand(id, params)) !== false;\n const toBlockStart = async (): Promise<boolean> => {\n const d = doc();\n const r = await range();\n const stream = (snapshot() as { body?: { dataStream?: string } } | null)?.body?.dataStream;\n if (!d || !r || typeof stream !== \"string\") return false;\n const plan = blockInsertPlan(stream, r.startOffset);\n if (plan.breakAt === null) {\n d.setSelection?.(plan.at, plan.at);\n return true;\n }\n d.setSelection?.(plan.breakAt, plan.breakAt);\n return exec(\"doc.command.break-line\", { unitId: d.getId() });\n };\n\n return {\n snapshot,\n async insertText(text) {\n if (!text || !(await range())) return false;\n return exec(\"doc.command.insert-special-character\", { value: text });\n },\n toBlockStart,\n async insertMarkdown(markdown) {\n const d = doc();\n if (!d || !(await toBlockStart())) return false;\n return exec(\"doc.command.replace-selection\", { unitId: d.getId(), body: insertableBody(markdown) });\n },\n bookmarks: () => collectBookmarks(snapshot()),\n async addBookmark(name) {\n const d = doc();\n const r = await range();\n if (!d || !r) return false;\n d.setSelection?.(r.startOffset, r.startOffset);\n const id = `bm_${Math.random().toString(36).slice(2, 10)}`;\n return exec(\"doc.command.replace-selection\", { unitId: d.getId(), body: bookmarkBody(id, name) });\n },\n async deleteBookmark(b) {\n const d = doc();\n if (!d) return false;\n d.setSelection?.(b.offset + 1, b.offset + 1);\n return exec(\"doc.command.delete-left\", { unitId: d.getId() });\n },\n async setViewOnly(viewOnly) {\n const perm = doc()?.getPermission?.();\n if (!perm) return;\n if (viewOnly) await perm.setReadOnly();\n else await perm.setEditable(true);\n // Univer's own refusal notice (\"This content is protected…\") stays off while viewing; the\n // editor shows ours through onEditDenied.\n const { IPermissionService } = await import(\"@univerjs/core\");\n deps.injector()?.get<{ setShowComponents?(show: boolean): void }>(IPermissionService)?.setShowComponents?.(!viewOnly);\n },\n async onEditDenied(cb) {\n const { ErrorService } = await import(\"@univerjs/core\");\n const errors = deps.injector()?.get<{ error$?: { subscribe(fn: (e: { code?: string }) => void): { unsubscribe(): void } } }>(ErrorService);\n const sub = errors?.error$?.subscribe((e) => {\n if (e.code === \"PERMISSION_DENIED\") cb();\n });\n return () => sub?.unsubscribe();\n },\n async openImagePanel() {\n return exec(\"sidebar.operation.doc-image\", { value: \"doc-image\" });\n },\n goTo(offset) {\n doc()?.setSelection?.(offset, offset);\n },\n };\n}\n\n/** Write one plain key onto the document style (it rides the snapshot like the paper colour does). */\nexport async function writeDocumentStyleKey(api: ApiLike, key: string, value: string): Promise<void> {\n const doc = api.getActiveDocument?.();\n if (!doc) return;\n const style = (doc as unknown as { getDocumentDataModel?(): { getSnapshot(): { documentStyle?: Record<string, unknown> } } }).getDocumentDataModel?.()?.getSnapshot().documentStyle ?? {};\n const old = style[key];\n if (old === value) return;\n const { JSONX } = await import(\"@univerjs/core\");\n const jsonX = JSONX.getInstance();\n const path = [\"documentStyle\", key];\n const action = old === undefined ? jsonX.insertOp(path, value) : jsonX.replaceOp(path, old, value);\n if (!action) return;\n await api.executeCommand(\"doc.mutation.rich-text-editing\", { unitId: doc.getId(), actions: action, textRanges: undefined });\n}\n"]}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure half of the Docs tools: building blocks, bookmarks, paragraph borders, the ruler's
|
|
3
|
+
* geometry and the document language. No Univer import, so each is proven on plain snapshots.
|
|
4
|
+
*/
|
|
5
|
+
interface BuildingBlock {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
description: string;
|
|
9
|
+
markdown: string;
|
|
10
|
+
}
|
|
11
|
+
declare const BUILDING_BLOCKS: BuildingBlock[];
|
|
12
|
+
interface InsertableBody {
|
|
13
|
+
dataStream: string;
|
|
14
|
+
paragraphs: Array<{
|
|
15
|
+
startIndex: number;
|
|
16
|
+
paragraphStyle?: Record<string, unknown>;
|
|
17
|
+
}>;
|
|
18
|
+
textRuns?: Array<{
|
|
19
|
+
st: number;
|
|
20
|
+
ed: number;
|
|
21
|
+
ts?: Record<string, unknown>;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/** Markdown to a body Univer can insert at the caret: the document-closing `\n` is dropped. */
|
|
25
|
+
declare function insertableBody(markdown: string): InsertableBody;
|
|
26
|
+
/**
|
|
27
|
+
* Where a BLOCK (table of contents, building block) goes for a caret: never inside a paragraph's
|
|
28
|
+
* text, so a heading is never split. Caret at the start of a paragraph (or in an empty one) →
|
|
29
|
+
* insert right there; anywhere else → end the caret's paragraph with a new line and insert at the
|
|
30
|
+
* start of that new paragraph. `dataStream` is Univer's body stream (paragraphs end in `\r`).
|
|
31
|
+
*/
|
|
32
|
+
declare function blockInsertPlan(dataStream: string, caret: number): {
|
|
33
|
+
at: number;
|
|
34
|
+
breakAt: number | null;
|
|
35
|
+
};
|
|
36
|
+
/** Univer's CustomRangeType.BOOKMARK. */
|
|
37
|
+
declare const BOOKMARK_RANGE_TYPE = 3;
|
|
38
|
+
/** A bookmark is an invisible anchor: one zero-width character the custom range wraps. */
|
|
39
|
+
declare const BOOKMARK_ANCHOR = "\u200B";
|
|
40
|
+
interface Bookmark {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
offset: number;
|
|
44
|
+
}
|
|
45
|
+
declare function collectBookmarks(snapshot: unknown): Bookmark[];
|
|
46
|
+
declare function bookmarkBody(id: string, name: string): {
|
|
47
|
+
dataStream: string;
|
|
48
|
+
customRanges: {
|
|
49
|
+
startIndex: number;
|
|
50
|
+
endIndex: number;
|
|
51
|
+
rangeId: string;
|
|
52
|
+
rangeType: number;
|
|
53
|
+
properties: {
|
|
54
|
+
name: string;
|
|
55
|
+
};
|
|
56
|
+
wholeEntity: boolean;
|
|
57
|
+
}[];
|
|
58
|
+
};
|
|
59
|
+
declare function cleanBookmarkName(raw: string, existing: readonly Bookmark[]): {
|
|
60
|
+
ok: true;
|
|
61
|
+
name: string;
|
|
62
|
+
} | {
|
|
63
|
+
ok: false;
|
|
64
|
+
why: string;
|
|
65
|
+
};
|
|
66
|
+
/** `#bookmark=<name>` in the page address names a bookmark to jump to on open. */
|
|
67
|
+
declare function bookmarkFromHash(hash: string): string | null;
|
|
68
|
+
declare const bookmarkHash: (name: string) => string;
|
|
69
|
+
type BorderSide = "top" | "bottom" | "both" | "none";
|
|
70
|
+
type BorderDash = "solid" | "dashed" | "dotted";
|
|
71
|
+
interface BorderChoice {
|
|
72
|
+
side: BorderSide;
|
|
73
|
+
color: string;
|
|
74
|
+
width: number;
|
|
75
|
+
dash: BorderDash;
|
|
76
|
+
padding: number;
|
|
77
|
+
}
|
|
78
|
+
/** The `paragraph` argument of `doc-paragraph-setting.command` for a choice (Univer draws top and bottom paragraph borders). */
|
|
79
|
+
declare function paragraphBorderParams(c: BorderChoice): Record<string, unknown>;
|
|
80
|
+
interface RulerGeometry {
|
|
81
|
+
pageLeft: number;
|
|
82
|
+
pageWidth: number;
|
|
83
|
+
marginLeft: number;
|
|
84
|
+
marginRight: number;
|
|
85
|
+
ticks: Array<{
|
|
86
|
+
x: number;
|
|
87
|
+
kind: "inch" | "half" | "eighth";
|
|
88
|
+
label?: string;
|
|
89
|
+
}>;
|
|
90
|
+
}
|
|
91
|
+
/** The ruler above the page: inch ticks from the page's left edge (margins shaded), at the current zoom. */
|
|
92
|
+
declare function rulerGeometry(a: {
|
|
93
|
+
containerWidth: number;
|
|
94
|
+
zoom: number;
|
|
95
|
+
pageWidthPx: number;
|
|
96
|
+
marginLeftPx: number;
|
|
97
|
+
marginRightPx: number;
|
|
98
|
+
}): RulerGeometry;
|
|
99
|
+
/** The key on the document style that carries the language (the slot the paper colour also uses). */
|
|
100
|
+
declare const DOCUMENT_LANGUAGE_KEY = "matrxLanguage";
|
|
101
|
+
declare const DOCUMENT_LANGUAGES: Array<{
|
|
102
|
+
code: string;
|
|
103
|
+
label: string;
|
|
104
|
+
}>;
|
|
105
|
+
declare function readDocumentLanguage(documentStyle: unknown): string;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The Univer-facing half of the Docs tools: insert text, markdown and bookmarks at the caret, move
|
|
109
|
+
* the selection, read the live snapshot, set view-only. Every operation is a real Univer command.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
interface ApiLike {
|
|
113
|
+
executeCommand(id: string, params?: object): Promise<unknown> | unknown;
|
|
114
|
+
getActiveDocument?(): {
|
|
115
|
+
getId(): string;
|
|
116
|
+
save?(): unknown;
|
|
117
|
+
setSelection?(a: number, b: number): void;
|
|
118
|
+
getPermission?(): {
|
|
119
|
+
setReadOnly(): Promise<void>;
|
|
120
|
+
setEditable(editable?: boolean): Promise<void>;
|
|
121
|
+
};
|
|
122
|
+
} | null;
|
|
123
|
+
}
|
|
124
|
+
interface InjectorLike {
|
|
125
|
+
get<T>(token: unknown): T | undefined;
|
|
126
|
+
}
|
|
127
|
+
interface DocEditOps {
|
|
128
|
+
insertText(text: string): Promise<boolean>;
|
|
129
|
+
/** A block (building block) at a new paragraph, never mid-line. */
|
|
130
|
+
insertMarkdown(markdown: string): Promise<boolean>;
|
|
131
|
+
/** Move the caret to where a block goes (`blockInsertPlan`); false when there is no caret. */
|
|
132
|
+
toBlockStart(): Promise<boolean>;
|
|
133
|
+
bookmarks(): Bookmark[];
|
|
134
|
+
addBookmark(name: string): Promise<boolean>;
|
|
135
|
+
deleteBookmark(b: Bookmark): Promise<boolean>;
|
|
136
|
+
goTo(offset: number): void;
|
|
137
|
+
snapshot(): unknown;
|
|
138
|
+
setViewOnly(viewOnly: boolean): Promise<void>;
|
|
139
|
+
/** Calls back when Univer refuses an edit (Viewing mode); returns the unsubscribe. */
|
|
140
|
+
onEditDenied(cb: () => void): Promise<() => void>;
|
|
141
|
+
openImagePanel(): Promise<boolean>;
|
|
142
|
+
}
|
|
143
|
+
declare function createDocEditOps(deps: {
|
|
144
|
+
api: () => ApiLike | null;
|
|
145
|
+
injector: () => InjectorLike | null;
|
|
146
|
+
}): DocEditOps;
|
|
147
|
+
/** Write one plain key onto the document style (it rides the snapshot like the paper colour does). */
|
|
148
|
+
declare function writeDocumentStyleKey(api: ApiLike, key: string, value: string): Promise<void>;
|
|
149
|
+
|
|
150
|
+
export { BOOKMARK_ANCHOR, BOOKMARK_RANGE_TYPE, BUILDING_BLOCKS, type Bookmark, type BorderChoice, type BorderDash, type BorderSide, type BuildingBlock, DOCUMENT_LANGUAGES, DOCUMENT_LANGUAGE_KEY, type DocEditOps, type InsertableBody, type RulerGeometry, blockInsertPlan, bookmarkBody, bookmarkFromHash, bookmarkHash, cleanBookmarkName, collectBookmarks, createDocEditOps, insertableBody, paragraphBorderParams, readDocumentLanguage, rulerGeometry, writeDocumentStyleKey };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure half of the Docs tools: building blocks, bookmarks, paragraph borders, the ruler's
|
|
3
|
+
* geometry and the document language. No Univer import, so each is proven on plain snapshots.
|
|
4
|
+
*/
|
|
5
|
+
interface BuildingBlock {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
description: string;
|
|
9
|
+
markdown: string;
|
|
10
|
+
}
|
|
11
|
+
declare const BUILDING_BLOCKS: BuildingBlock[];
|
|
12
|
+
interface InsertableBody {
|
|
13
|
+
dataStream: string;
|
|
14
|
+
paragraphs: Array<{
|
|
15
|
+
startIndex: number;
|
|
16
|
+
paragraphStyle?: Record<string, unknown>;
|
|
17
|
+
}>;
|
|
18
|
+
textRuns?: Array<{
|
|
19
|
+
st: number;
|
|
20
|
+
ed: number;
|
|
21
|
+
ts?: Record<string, unknown>;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/** Markdown to a body Univer can insert at the caret: the document-closing `\n` is dropped. */
|
|
25
|
+
declare function insertableBody(markdown: string): InsertableBody;
|
|
26
|
+
/**
|
|
27
|
+
* Where a BLOCK (table of contents, building block) goes for a caret: never inside a paragraph's
|
|
28
|
+
* text, so a heading is never split. Caret at the start of a paragraph (or in an empty one) →
|
|
29
|
+
* insert right there; anywhere else → end the caret's paragraph with a new line and insert at the
|
|
30
|
+
* start of that new paragraph. `dataStream` is Univer's body stream (paragraphs end in `\r`).
|
|
31
|
+
*/
|
|
32
|
+
declare function blockInsertPlan(dataStream: string, caret: number): {
|
|
33
|
+
at: number;
|
|
34
|
+
breakAt: number | null;
|
|
35
|
+
};
|
|
36
|
+
/** Univer's CustomRangeType.BOOKMARK. */
|
|
37
|
+
declare const BOOKMARK_RANGE_TYPE = 3;
|
|
38
|
+
/** A bookmark is an invisible anchor: one zero-width character the custom range wraps. */
|
|
39
|
+
declare const BOOKMARK_ANCHOR = "\u200B";
|
|
40
|
+
interface Bookmark {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
offset: number;
|
|
44
|
+
}
|
|
45
|
+
declare function collectBookmarks(snapshot: unknown): Bookmark[];
|
|
46
|
+
declare function bookmarkBody(id: string, name: string): {
|
|
47
|
+
dataStream: string;
|
|
48
|
+
customRanges: {
|
|
49
|
+
startIndex: number;
|
|
50
|
+
endIndex: number;
|
|
51
|
+
rangeId: string;
|
|
52
|
+
rangeType: number;
|
|
53
|
+
properties: {
|
|
54
|
+
name: string;
|
|
55
|
+
};
|
|
56
|
+
wholeEntity: boolean;
|
|
57
|
+
}[];
|
|
58
|
+
};
|
|
59
|
+
declare function cleanBookmarkName(raw: string, existing: readonly Bookmark[]): {
|
|
60
|
+
ok: true;
|
|
61
|
+
name: string;
|
|
62
|
+
} | {
|
|
63
|
+
ok: false;
|
|
64
|
+
why: string;
|
|
65
|
+
};
|
|
66
|
+
/** `#bookmark=<name>` in the page address names a bookmark to jump to on open. */
|
|
67
|
+
declare function bookmarkFromHash(hash: string): string | null;
|
|
68
|
+
declare const bookmarkHash: (name: string) => string;
|
|
69
|
+
type BorderSide = "top" | "bottom" | "both" | "none";
|
|
70
|
+
type BorderDash = "solid" | "dashed" | "dotted";
|
|
71
|
+
interface BorderChoice {
|
|
72
|
+
side: BorderSide;
|
|
73
|
+
color: string;
|
|
74
|
+
width: number;
|
|
75
|
+
dash: BorderDash;
|
|
76
|
+
padding: number;
|
|
77
|
+
}
|
|
78
|
+
/** The `paragraph` argument of `doc-paragraph-setting.command` for a choice (Univer draws top and bottom paragraph borders). */
|
|
79
|
+
declare function paragraphBorderParams(c: BorderChoice): Record<string, unknown>;
|
|
80
|
+
interface RulerGeometry {
|
|
81
|
+
pageLeft: number;
|
|
82
|
+
pageWidth: number;
|
|
83
|
+
marginLeft: number;
|
|
84
|
+
marginRight: number;
|
|
85
|
+
ticks: Array<{
|
|
86
|
+
x: number;
|
|
87
|
+
kind: "inch" | "half" | "eighth";
|
|
88
|
+
label?: string;
|
|
89
|
+
}>;
|
|
90
|
+
}
|
|
91
|
+
/** The ruler above the page: inch ticks from the page's left edge (margins shaded), at the current zoom. */
|
|
92
|
+
declare function rulerGeometry(a: {
|
|
93
|
+
containerWidth: number;
|
|
94
|
+
zoom: number;
|
|
95
|
+
pageWidthPx: number;
|
|
96
|
+
marginLeftPx: number;
|
|
97
|
+
marginRightPx: number;
|
|
98
|
+
}): RulerGeometry;
|
|
99
|
+
/** The key on the document style that carries the language (the slot the paper colour also uses). */
|
|
100
|
+
declare const DOCUMENT_LANGUAGE_KEY = "matrxLanguage";
|
|
101
|
+
declare const DOCUMENT_LANGUAGES: Array<{
|
|
102
|
+
code: string;
|
|
103
|
+
label: string;
|
|
104
|
+
}>;
|
|
105
|
+
declare function readDocumentLanguage(documentStyle: unknown): string;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The Univer-facing half of the Docs tools: insert text, markdown and bookmarks at the caret, move
|
|
109
|
+
* the selection, read the live snapshot, set view-only. Every operation is a real Univer command.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
interface ApiLike {
|
|
113
|
+
executeCommand(id: string, params?: object): Promise<unknown> | unknown;
|
|
114
|
+
getActiveDocument?(): {
|
|
115
|
+
getId(): string;
|
|
116
|
+
save?(): unknown;
|
|
117
|
+
setSelection?(a: number, b: number): void;
|
|
118
|
+
getPermission?(): {
|
|
119
|
+
setReadOnly(): Promise<void>;
|
|
120
|
+
setEditable(editable?: boolean): Promise<void>;
|
|
121
|
+
};
|
|
122
|
+
} | null;
|
|
123
|
+
}
|
|
124
|
+
interface InjectorLike {
|
|
125
|
+
get<T>(token: unknown): T | undefined;
|
|
126
|
+
}
|
|
127
|
+
interface DocEditOps {
|
|
128
|
+
insertText(text: string): Promise<boolean>;
|
|
129
|
+
/** A block (building block) at a new paragraph, never mid-line. */
|
|
130
|
+
insertMarkdown(markdown: string): Promise<boolean>;
|
|
131
|
+
/** Move the caret to where a block goes (`blockInsertPlan`); false when there is no caret. */
|
|
132
|
+
toBlockStart(): Promise<boolean>;
|
|
133
|
+
bookmarks(): Bookmark[];
|
|
134
|
+
addBookmark(name: string): Promise<boolean>;
|
|
135
|
+
deleteBookmark(b: Bookmark): Promise<boolean>;
|
|
136
|
+
goTo(offset: number): void;
|
|
137
|
+
snapshot(): unknown;
|
|
138
|
+
setViewOnly(viewOnly: boolean): Promise<void>;
|
|
139
|
+
/** Calls back when Univer refuses an edit (Viewing mode); returns the unsubscribe. */
|
|
140
|
+
onEditDenied(cb: () => void): Promise<() => void>;
|
|
141
|
+
openImagePanel(): Promise<boolean>;
|
|
142
|
+
}
|
|
143
|
+
declare function createDocEditOps(deps: {
|
|
144
|
+
api: () => ApiLike | null;
|
|
145
|
+
injector: () => InjectorLike | null;
|
|
146
|
+
}): DocEditOps;
|
|
147
|
+
/** Write one plain key onto the document style (it rides the snapshot like the paper colour does). */
|
|
148
|
+
declare function writeDocumentStyleKey(api: ApiLike, key: string, value: string): Promise<void>;
|
|
149
|
+
|
|
150
|
+
export { BOOKMARK_ANCHOR, BOOKMARK_RANGE_TYPE, BUILDING_BLOCKS, type Bookmark, type BorderChoice, type BorderDash, type BorderSide, type BuildingBlock, DOCUMENT_LANGUAGES, DOCUMENT_LANGUAGE_KEY, type DocEditOps, type InsertableBody, type RulerGeometry, blockInsertPlan, bookmarkBody, bookmarkFromHash, bookmarkHash, cleanBookmarkName, collectBookmarks, createDocEditOps, insertableBody, paragraphBorderParams, readDocumentLanguage, rulerGeometry, writeDocumentStyleKey };
|