ooxml-core 1.23.0 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/automation/index.cjs +553 -335
- package/dist/automation/index.d.ts +1 -0
- package/dist/automation/index.d.ts.map +1 -1
- package/dist/automation/index.mjs +552 -336
- package/dist/automation/live.d.ts +89 -0
- package/dist/automation/live.d.ts.map +1 -0
- package/dist/docx/ui/customization.d.ts +30 -0
- package/dist/docx/ui/customization.d.ts.map +1 -0
- package/dist/docx/ui/index.cjs +51 -0
- package/dist/docx/ui/index.d.ts +1 -0
- package/dist/docx/ui/index.d.ts.map +1 -1
- package/dist/docx/ui/index.mjs +46 -1
- package/dist/embedding/backstage.d.ts +48 -0
- package/dist/embedding/backstage.d.ts.map +1 -0
- package/dist/embedding/capabilities.d.ts +60 -0
- package/dist/embedding/capabilities.d.ts.map +1 -0
- package/dist/embedding/customization.d.ts +32 -0
- package/dist/embedding/customization.d.ts.map +1 -0
- package/dist/embedding/index.cjs +229 -0
- package/dist/embedding/index.d.ts +7 -0
- package/dist/embedding/index.d.ts.map +1 -0
- package/dist/embedding/index.mjs +204 -0
- package/dist/embedding/menu-commands.d.ts +66 -0
- package/dist/embedding/menu-commands.d.ts.map +1 -0
- package/dist/embedding/regions.d.ts +58 -0
- package/dist/embedding/regions.d.ts.map +1 -0
- package/dist/embedding/storage.d.ts +111 -0
- package/dist/embedding/storage.d.ts.map +1 -0
- package/dist/index.cjs +233 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +233 -1
- package/dist/visio/collab/compose.d.ts.map +1 -1
- package/dist/visio/collab/fixups.d.ts.map +1 -1
- package/dist/visio/collab/index.cjs +167 -62
- package/dist/visio/collab/index.mjs +167 -62
- package/dist/visio/collab/keys.d.ts +2 -0
- package/dist/visio/collab/keys.d.ts.map +1 -1
- package/dist/visio/collab/pieces.d.ts +7 -0
- package/dist/visio/collab/pieces.d.ts.map +1 -1
- package/dist/visio/collab/read-ids.d.ts +7 -1
- package/dist/visio/collab/read-ids.d.ts.map +1 -1
- package/dist/visio/collab/read-parts.d.ts.map +1 -1
- package/dist/visio/collab/read-shapes.d.ts +0 -1
- package/dist/visio/collab/read-shapes.d.ts.map +1 -1
- package/dist/visio/collab/read.d.ts.map +1 -1
- package/dist/visio/collab/schema.d.ts +1 -1
- package/dist/visio/collab/schema.d.ts.map +1 -1
- package/dist/visio/collab/snapshot-contents.d.ts.map +1 -1
- package/dist/visio/collab/write-shapes.d.ts.map +1 -1
- package/dist/visio/collab/zip-store.d.ts +4 -0
- package/dist/visio/collab/zip-store.d.ts.map +1 -0
- package/dist/visio/document-level.d.ts +57 -0
- package/dist/visio/document-level.d.ts.map +1 -0
- package/dist/visio/index.cjs +543 -444
- package/dist/visio/index.d.ts +1 -0
- package/dist/visio/index.d.ts.map +1 -1
- package/dist/visio/index.mjs +543 -444
- package/dist/visio/layers.d.ts +3 -0
- package/dist/visio/layers.d.ts.map +1 -1
- package/dist/visio/package.d.ts +9 -0
- package/dist/visio/package.d.ts.map +1 -1
- package/dist/visio/parser.d.ts +7 -0
- package/dist/visio/parser.d.ts.map +1 -1
- package/dist/visio/shape-metadata.d.ts +3 -0
- package/dist/visio/shape-metadata.d.ts.map +1 -1
- package/dist/visio/ui/contract.d.ts +27 -2
- package/dist/visio/ui/contract.d.ts.map +1 -1
- package/dist/visio/ui/customization.d.ts +46 -0
- package/dist/visio/ui/customization.d.ts.map +1 -0
- package/dist/visio/ui/index.cjs +454 -316
- package/dist/visio/ui/index.d.ts +1 -0
- package/dist/visio/ui/index.d.ts.map +1 -1
- package/dist/visio/ui/index.mjs +452 -317
- package/dist/xlsx/ui/commands.d.ts +2 -0
- package/dist/xlsx/ui/commands.d.ts.map +1 -1
- package/dist/xlsx/ui/customization.d.ts +49 -0
- package/dist/xlsx/ui/customization.d.ts.map +1 -0
- package/dist/xlsx/ui/index.cjs +39 -1
- package/dist/xlsx/ui/index.d.ts +1 -0
- package/dist/xlsx/ui/index.d.ts.map +1 -1
- package/dist/xlsx/ui/index.mjs +37 -2
- package/package.json +6 -1
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// embedding/storage.ts
|
|
4
|
+
var FILE_COMMAND_EVENT = "file-command";
|
|
5
|
+
function fileCommandDetail(command, fileName) {
|
|
6
|
+
return fileName === void 0 ? { command } : { command, fileName };
|
|
7
|
+
}
|
|
8
|
+
function recoveryStoreOf(storage) {
|
|
9
|
+
if (!storage?.readRecovery || !storage.writeRecovery || !storage.clearRecovery) return void 0;
|
|
10
|
+
return storage;
|
|
11
|
+
}
|
|
12
|
+
function isDocumentStorage(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && typeof value.save === "function";
|
|
14
|
+
}
|
|
15
|
+
var MIME_TYPES = {
|
|
16
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
17
|
+
docm: "application/vnd.ms-word.document.macroEnabled.12",
|
|
18
|
+
dotx: "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
|
|
19
|
+
doc: "application/msword",
|
|
20
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
21
|
+
xlsm: "application/vnd.ms-excel.sheet.macroEnabled.12",
|
|
22
|
+
xltx: "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
|
|
23
|
+
xls: "application/vnd.ms-excel",
|
|
24
|
+
csv: "text/csv",
|
|
25
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
26
|
+
pptm: "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
|
|
27
|
+
ppsx: "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
|
|
28
|
+
potx: "application/vnd.openxmlformats-officedocument.presentationml.template",
|
|
29
|
+
ppt: "application/vnd.ms-powerpoint",
|
|
30
|
+
vsdx: "application/vnd.ms-visio.drawing",
|
|
31
|
+
vsdm: "application/vnd.ms-visio.drawing.macroEnabled.12",
|
|
32
|
+
vsd: "application/vnd.visio",
|
|
33
|
+
txt: "text/plain",
|
|
34
|
+
json: "application/json"
|
|
35
|
+
};
|
|
36
|
+
function documentMimeType(fileName) {
|
|
37
|
+
const extension = /\.([^./\\]+)$/.exec(fileName)?.[1]?.toLowerCase() ?? "";
|
|
38
|
+
return MIME_TYPES[extension] ?? "application/octet-stream";
|
|
39
|
+
}
|
|
40
|
+
function documentSaveMeta(fileName, reason = "save", mimeType = documentMimeType(fileName)) {
|
|
41
|
+
return { fileName, mimeType, reason };
|
|
42
|
+
}
|
|
43
|
+
async function saveToStorage(storage, bytes, meta) {
|
|
44
|
+
const result = await storage.save(bytes, meta);
|
|
45
|
+
const name = result?.fileName?.trim();
|
|
46
|
+
return name ? name : meta.fileName;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// embedding/backstage.ts
|
|
50
|
+
function hostBackstageItemId(id) {
|
|
51
|
+
return `host.${id}`;
|
|
52
|
+
}
|
|
53
|
+
function hostBackstagePageId(itemId) {
|
|
54
|
+
return itemId.startsWith("host.") ? itemId.slice(5) : void 0;
|
|
55
|
+
}
|
|
56
|
+
function acceptedHostBackstagePages(pages) {
|
|
57
|
+
const seen = /* @__PURE__ */ new Set();
|
|
58
|
+
const accepted = [];
|
|
59
|
+
for (const page of pages ?? []) {
|
|
60
|
+
if (!page || typeof page.id !== "string" || !page.id || seen.has(page.id)) continue;
|
|
61
|
+
seen.add(page.id);
|
|
62
|
+
accepted.push({ page, index: accepted.length });
|
|
63
|
+
}
|
|
64
|
+
return accepted.sort((a, b) => (a.page.order ?? 0) - (b.page.order ?? 0) || a.index - b.index).map(({ page }) => page);
|
|
65
|
+
}
|
|
66
|
+
function placeHostBackstagePages(items, pages, toEntry) {
|
|
67
|
+
const entries = [...items];
|
|
68
|
+
for (const page of acceptedHostBackstagePages(pages)) {
|
|
69
|
+
const group = page.group ?? "main";
|
|
70
|
+
let at = entries.length;
|
|
71
|
+
while (at > 0 && (entries[at - 1]?.group ?? "main") !== group) at--;
|
|
72
|
+
entries.splice(at === 0 ? entries.length : at, 0, toEntry(page));
|
|
73
|
+
}
|
|
74
|
+
return entries;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// embedding/capabilities.ts
|
|
78
|
+
var EDITOR_CAPABILITY_IDS = [
|
|
79
|
+
/** Changing the document. `false` opens it read-only, whatever the edit prop says. */
|
|
80
|
+
"edit",
|
|
81
|
+
/** Saving a copy in another format (File > Export, Save As, Download). */
|
|
82
|
+
"export",
|
|
83
|
+
/** Printing (File > Print, the Print commands and Ctrl+P). */
|
|
84
|
+
"print",
|
|
85
|
+
/** Sharing the document with other people (File > Share, Share buttons). */
|
|
86
|
+
"share",
|
|
87
|
+
/** Copying content out (Copy, Cut and their shortcuts). */
|
|
88
|
+
"copy",
|
|
89
|
+
/** Adding and editing comments. */
|
|
90
|
+
"comment",
|
|
91
|
+
/** Tracked changes: turning tracking on, accepting and rejecting. */
|
|
92
|
+
"review",
|
|
93
|
+
/** Find and Replace. */
|
|
94
|
+
"find",
|
|
95
|
+
/** File > New and File > Open. */
|
|
96
|
+
"open",
|
|
97
|
+
/** File > Save. */
|
|
98
|
+
"save",
|
|
99
|
+
/** File > Options and Customize Ribbon. */
|
|
100
|
+
"settings"
|
|
101
|
+
];
|
|
102
|
+
function isCapabilityEnabled(capabilities, id) {
|
|
103
|
+
return capabilities?.[id] !== false;
|
|
104
|
+
}
|
|
105
|
+
function disabledCapabilities(capabilities) {
|
|
106
|
+
if (!capabilities) return [];
|
|
107
|
+
return Object.keys(capabilities).filter((id) => capabilities[id] === false);
|
|
108
|
+
}
|
|
109
|
+
function capabilityHiddenActions(capabilities, map) {
|
|
110
|
+
const hidden = /* @__PURE__ */ new Set();
|
|
111
|
+
for (const id of disabledCapabilities(capabilities))
|
|
112
|
+
for (const action of map[id] ?? []) hidden.add(action);
|
|
113
|
+
return [...hidden];
|
|
114
|
+
}
|
|
115
|
+
function mergeHiddenActions(...lists) {
|
|
116
|
+
const merged = /* @__PURE__ */ new Set();
|
|
117
|
+
for (const list of lists) for (const action of list ?? []) merged.add(action);
|
|
118
|
+
return [...merged];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// embedding/menu-commands.ts
|
|
122
|
+
function hostMenuEntryId(id) {
|
|
123
|
+
return `host:${id}`;
|
|
124
|
+
}
|
|
125
|
+
function isHostMenuEntry(entry) {
|
|
126
|
+
return typeof entry === "object" && entry !== null && entry.host === true;
|
|
127
|
+
}
|
|
128
|
+
function resolveHostMenuCommands(commands, context) {
|
|
129
|
+
const top = [];
|
|
130
|
+
const bottom = [];
|
|
131
|
+
const seen = /* @__PURE__ */ new Set();
|
|
132
|
+
for (const command of commands ?? []) {
|
|
133
|
+
if (!command?.id || seen.has(command.id)) continue;
|
|
134
|
+
seen.add(command.id);
|
|
135
|
+
if (command.when && !command.when(context)) continue;
|
|
136
|
+
const disabled = typeof command.disabled === "function" ? command.disabled(context) : command.disabled === true;
|
|
137
|
+
const entry = {
|
|
138
|
+
id: hostMenuEntryId(command.id),
|
|
139
|
+
host: true,
|
|
140
|
+
label: command.label,
|
|
141
|
+
labelKey: "",
|
|
142
|
+
disabled,
|
|
143
|
+
onSelect: () => {
|
|
144
|
+
if (!disabled) command.onSelect(context);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
if (command.icon) entry.icon = command.icon;
|
|
148
|
+
(command.group === "bottom" ? bottom : top).push(entry);
|
|
149
|
+
}
|
|
150
|
+
return { top, bottom };
|
|
151
|
+
}
|
|
152
|
+
function withHostMenuCommands(entries, commands, context) {
|
|
153
|
+
const { top, bottom } = resolveHostMenuCommands(commands, context);
|
|
154
|
+
const middle = entries.map(
|
|
155
|
+
(entry, index) => index === 0 ? { ...entry, separatorBefore: top.length > 0 } : entry
|
|
156
|
+
);
|
|
157
|
+
const first = bottom[0];
|
|
158
|
+
if (first && top.length + middle.length > 0) first.separatorBefore = true;
|
|
159
|
+
return [...top, ...middle, ...bottom];
|
|
160
|
+
}
|
|
161
|
+
function withoutHiddenEntries(entries, hidden) {
|
|
162
|
+
const kept = [];
|
|
163
|
+
let separator = false;
|
|
164
|
+
for (const entry of entries) {
|
|
165
|
+
separator ||= entry.separatorBefore === true;
|
|
166
|
+
if (hidden(entry)) continue;
|
|
167
|
+
const starts = separator && kept.length > 0;
|
|
168
|
+
kept.push(
|
|
169
|
+
entry.separatorBefore === true === starts ? entry : { ...entry, separatorBefore: starts }
|
|
170
|
+
);
|
|
171
|
+
separator = false;
|
|
172
|
+
}
|
|
173
|
+
return kept;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// embedding/regions.ts
|
|
177
|
+
function hostBackstageRegionId(id) {
|
|
178
|
+
return `backstage.host.${id}`;
|
|
179
|
+
}
|
|
180
|
+
function sameRenderer(a, b) {
|
|
181
|
+
if (a === b) return true;
|
|
182
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object" || a.element !== b.element)
|
|
183
|
+
return false;
|
|
184
|
+
const left = a.properties ?? {};
|
|
185
|
+
const right = b.properties ?? {};
|
|
186
|
+
const keys = Object.keys(left);
|
|
187
|
+
return keys.length === Object.keys(right).length && keys.every((key) => Object.is(left[key], right[key]));
|
|
188
|
+
}
|
|
189
|
+
function sameRegionContext(a, b, callbackKeys = /* @__PURE__ */ new Set(["close"])) {
|
|
190
|
+
const left = a;
|
|
191
|
+
const right = b;
|
|
192
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(left), ...Object.keys(right)])) {
|
|
193
|
+
if (callbackKeys.has(key)) continue;
|
|
194
|
+
const x = left[key];
|
|
195
|
+
const y = right[key];
|
|
196
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
197
|
+
if (!sameItems(x, y)) return false;
|
|
198
|
+
} else if (!Object.is(x, y)) return false;
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
function sameItems(a, b) {
|
|
203
|
+
return a === b || a.length === b.length && a.every((item, index) => Object.is(item, b[index]));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
exports.EDITOR_CAPABILITY_IDS = EDITOR_CAPABILITY_IDS;
|
|
207
|
+
exports.FILE_COMMAND_EVENT = FILE_COMMAND_EVENT;
|
|
208
|
+
exports.acceptedHostBackstagePages = acceptedHostBackstagePages;
|
|
209
|
+
exports.capabilityHiddenActions = capabilityHiddenActions;
|
|
210
|
+
exports.disabledCapabilities = disabledCapabilities;
|
|
211
|
+
exports.documentMimeType = documentMimeType;
|
|
212
|
+
exports.documentSaveMeta = documentSaveMeta;
|
|
213
|
+
exports.fileCommandDetail = fileCommandDetail;
|
|
214
|
+
exports.hostBackstageItemId = hostBackstageItemId;
|
|
215
|
+
exports.hostBackstagePageId = hostBackstagePageId;
|
|
216
|
+
exports.hostBackstageRegionId = hostBackstageRegionId;
|
|
217
|
+
exports.hostMenuEntryId = hostMenuEntryId;
|
|
218
|
+
exports.isCapabilityEnabled = isCapabilityEnabled;
|
|
219
|
+
exports.isDocumentStorage = isDocumentStorage;
|
|
220
|
+
exports.isHostMenuEntry = isHostMenuEntry;
|
|
221
|
+
exports.mergeHiddenActions = mergeHiddenActions;
|
|
222
|
+
exports.placeHostBackstagePages = placeHostBackstagePages;
|
|
223
|
+
exports.recoveryStoreOf = recoveryStoreOf;
|
|
224
|
+
exports.resolveHostMenuCommands = resolveHostMenuCommands;
|
|
225
|
+
exports.sameRegionContext = sameRegionContext;
|
|
226
|
+
exports.sameRenderer = sameRenderer;
|
|
227
|
+
exports.saveToStorage = saveToStorage;
|
|
228
|
+
exports.withHostMenuCommands = withHostMenuCommands;
|
|
229
|
+
exports.withoutHiddenEntries = withoutHiddenEntries;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../embedding/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// embedding/storage.ts
|
|
2
|
+
var FILE_COMMAND_EVENT = "file-command";
|
|
3
|
+
function fileCommandDetail(command, fileName) {
|
|
4
|
+
return fileName === void 0 ? { command } : { command, fileName };
|
|
5
|
+
}
|
|
6
|
+
function recoveryStoreOf(storage) {
|
|
7
|
+
if (!storage?.readRecovery || !storage.writeRecovery || !storage.clearRecovery) return void 0;
|
|
8
|
+
return storage;
|
|
9
|
+
}
|
|
10
|
+
function isDocumentStorage(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && typeof value.save === "function";
|
|
12
|
+
}
|
|
13
|
+
var MIME_TYPES = {
|
|
14
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
15
|
+
docm: "application/vnd.ms-word.document.macroEnabled.12",
|
|
16
|
+
dotx: "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
|
|
17
|
+
doc: "application/msword",
|
|
18
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
19
|
+
xlsm: "application/vnd.ms-excel.sheet.macroEnabled.12",
|
|
20
|
+
xltx: "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
|
|
21
|
+
xls: "application/vnd.ms-excel",
|
|
22
|
+
csv: "text/csv",
|
|
23
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
24
|
+
pptm: "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
|
|
25
|
+
ppsx: "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
|
|
26
|
+
potx: "application/vnd.openxmlformats-officedocument.presentationml.template",
|
|
27
|
+
ppt: "application/vnd.ms-powerpoint",
|
|
28
|
+
vsdx: "application/vnd.ms-visio.drawing",
|
|
29
|
+
vsdm: "application/vnd.ms-visio.drawing.macroEnabled.12",
|
|
30
|
+
vsd: "application/vnd.visio",
|
|
31
|
+
txt: "text/plain",
|
|
32
|
+
json: "application/json"
|
|
33
|
+
};
|
|
34
|
+
function documentMimeType(fileName) {
|
|
35
|
+
const extension = /\.([^./\\]+)$/.exec(fileName)?.[1]?.toLowerCase() ?? "";
|
|
36
|
+
return MIME_TYPES[extension] ?? "application/octet-stream";
|
|
37
|
+
}
|
|
38
|
+
function documentSaveMeta(fileName, reason = "save", mimeType = documentMimeType(fileName)) {
|
|
39
|
+
return { fileName, mimeType, reason };
|
|
40
|
+
}
|
|
41
|
+
async function saveToStorage(storage, bytes, meta) {
|
|
42
|
+
const result = await storage.save(bytes, meta);
|
|
43
|
+
const name = result?.fileName?.trim();
|
|
44
|
+
return name ? name : meta.fileName;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// embedding/backstage.ts
|
|
48
|
+
function hostBackstageItemId(id) {
|
|
49
|
+
return `host.${id}`;
|
|
50
|
+
}
|
|
51
|
+
function hostBackstagePageId(itemId) {
|
|
52
|
+
return itemId.startsWith("host.") ? itemId.slice(5) : void 0;
|
|
53
|
+
}
|
|
54
|
+
function acceptedHostBackstagePages(pages) {
|
|
55
|
+
const seen = /* @__PURE__ */ new Set();
|
|
56
|
+
const accepted = [];
|
|
57
|
+
for (const page of pages ?? []) {
|
|
58
|
+
if (!page || typeof page.id !== "string" || !page.id || seen.has(page.id)) continue;
|
|
59
|
+
seen.add(page.id);
|
|
60
|
+
accepted.push({ page, index: accepted.length });
|
|
61
|
+
}
|
|
62
|
+
return accepted.sort((a, b) => (a.page.order ?? 0) - (b.page.order ?? 0) || a.index - b.index).map(({ page }) => page);
|
|
63
|
+
}
|
|
64
|
+
function placeHostBackstagePages(items, pages, toEntry) {
|
|
65
|
+
const entries = [...items];
|
|
66
|
+
for (const page of acceptedHostBackstagePages(pages)) {
|
|
67
|
+
const group = page.group ?? "main";
|
|
68
|
+
let at = entries.length;
|
|
69
|
+
while (at > 0 && (entries[at - 1]?.group ?? "main") !== group) at--;
|
|
70
|
+
entries.splice(at === 0 ? entries.length : at, 0, toEntry(page));
|
|
71
|
+
}
|
|
72
|
+
return entries;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// embedding/capabilities.ts
|
|
76
|
+
var EDITOR_CAPABILITY_IDS = [
|
|
77
|
+
/** Changing the document. `false` opens it read-only, whatever the edit prop says. */
|
|
78
|
+
"edit",
|
|
79
|
+
/** Saving a copy in another format (File > Export, Save As, Download). */
|
|
80
|
+
"export",
|
|
81
|
+
/** Printing (File > Print, the Print commands and Ctrl+P). */
|
|
82
|
+
"print",
|
|
83
|
+
/** Sharing the document with other people (File > Share, Share buttons). */
|
|
84
|
+
"share",
|
|
85
|
+
/** Copying content out (Copy, Cut and their shortcuts). */
|
|
86
|
+
"copy",
|
|
87
|
+
/** Adding and editing comments. */
|
|
88
|
+
"comment",
|
|
89
|
+
/** Tracked changes: turning tracking on, accepting and rejecting. */
|
|
90
|
+
"review",
|
|
91
|
+
/** Find and Replace. */
|
|
92
|
+
"find",
|
|
93
|
+
/** File > New and File > Open. */
|
|
94
|
+
"open",
|
|
95
|
+
/** File > Save. */
|
|
96
|
+
"save",
|
|
97
|
+
/** File > Options and Customize Ribbon. */
|
|
98
|
+
"settings"
|
|
99
|
+
];
|
|
100
|
+
function isCapabilityEnabled(capabilities, id) {
|
|
101
|
+
return capabilities?.[id] !== false;
|
|
102
|
+
}
|
|
103
|
+
function disabledCapabilities(capabilities) {
|
|
104
|
+
if (!capabilities) return [];
|
|
105
|
+
return Object.keys(capabilities).filter((id) => capabilities[id] === false);
|
|
106
|
+
}
|
|
107
|
+
function capabilityHiddenActions(capabilities, map) {
|
|
108
|
+
const hidden = /* @__PURE__ */ new Set();
|
|
109
|
+
for (const id of disabledCapabilities(capabilities))
|
|
110
|
+
for (const action of map[id] ?? []) hidden.add(action);
|
|
111
|
+
return [...hidden];
|
|
112
|
+
}
|
|
113
|
+
function mergeHiddenActions(...lists) {
|
|
114
|
+
const merged = /* @__PURE__ */ new Set();
|
|
115
|
+
for (const list of lists) for (const action of list ?? []) merged.add(action);
|
|
116
|
+
return [...merged];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// embedding/menu-commands.ts
|
|
120
|
+
function hostMenuEntryId(id) {
|
|
121
|
+
return `host:${id}`;
|
|
122
|
+
}
|
|
123
|
+
function isHostMenuEntry(entry) {
|
|
124
|
+
return typeof entry === "object" && entry !== null && entry.host === true;
|
|
125
|
+
}
|
|
126
|
+
function resolveHostMenuCommands(commands, context) {
|
|
127
|
+
const top = [];
|
|
128
|
+
const bottom = [];
|
|
129
|
+
const seen = /* @__PURE__ */ new Set();
|
|
130
|
+
for (const command of commands ?? []) {
|
|
131
|
+
if (!command?.id || seen.has(command.id)) continue;
|
|
132
|
+
seen.add(command.id);
|
|
133
|
+
if (command.when && !command.when(context)) continue;
|
|
134
|
+
const disabled = typeof command.disabled === "function" ? command.disabled(context) : command.disabled === true;
|
|
135
|
+
const entry = {
|
|
136
|
+
id: hostMenuEntryId(command.id),
|
|
137
|
+
host: true,
|
|
138
|
+
label: command.label,
|
|
139
|
+
labelKey: "",
|
|
140
|
+
disabled,
|
|
141
|
+
onSelect: () => {
|
|
142
|
+
if (!disabled) command.onSelect(context);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
if (command.icon) entry.icon = command.icon;
|
|
146
|
+
(command.group === "bottom" ? bottom : top).push(entry);
|
|
147
|
+
}
|
|
148
|
+
return { top, bottom };
|
|
149
|
+
}
|
|
150
|
+
function withHostMenuCommands(entries, commands, context) {
|
|
151
|
+
const { top, bottom } = resolveHostMenuCommands(commands, context);
|
|
152
|
+
const middle = entries.map(
|
|
153
|
+
(entry, index) => index === 0 ? { ...entry, separatorBefore: top.length > 0 } : entry
|
|
154
|
+
);
|
|
155
|
+
const first = bottom[0];
|
|
156
|
+
if (first && top.length + middle.length > 0) first.separatorBefore = true;
|
|
157
|
+
return [...top, ...middle, ...bottom];
|
|
158
|
+
}
|
|
159
|
+
function withoutHiddenEntries(entries, hidden) {
|
|
160
|
+
const kept = [];
|
|
161
|
+
let separator = false;
|
|
162
|
+
for (const entry of entries) {
|
|
163
|
+
separator ||= entry.separatorBefore === true;
|
|
164
|
+
if (hidden(entry)) continue;
|
|
165
|
+
const starts = separator && kept.length > 0;
|
|
166
|
+
kept.push(
|
|
167
|
+
entry.separatorBefore === true === starts ? entry : { ...entry, separatorBefore: starts }
|
|
168
|
+
);
|
|
169
|
+
separator = false;
|
|
170
|
+
}
|
|
171
|
+
return kept;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// embedding/regions.ts
|
|
175
|
+
function hostBackstageRegionId(id) {
|
|
176
|
+
return `backstage.host.${id}`;
|
|
177
|
+
}
|
|
178
|
+
function sameRenderer(a, b) {
|
|
179
|
+
if (a === b) return true;
|
|
180
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object" || a.element !== b.element)
|
|
181
|
+
return false;
|
|
182
|
+
const left = a.properties ?? {};
|
|
183
|
+
const right = b.properties ?? {};
|
|
184
|
+
const keys = Object.keys(left);
|
|
185
|
+
return keys.length === Object.keys(right).length && keys.every((key) => Object.is(left[key], right[key]));
|
|
186
|
+
}
|
|
187
|
+
function sameRegionContext(a, b, callbackKeys = /* @__PURE__ */ new Set(["close"])) {
|
|
188
|
+
const left = a;
|
|
189
|
+
const right = b;
|
|
190
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(left), ...Object.keys(right)])) {
|
|
191
|
+
if (callbackKeys.has(key)) continue;
|
|
192
|
+
const x = left[key];
|
|
193
|
+
const y = right[key];
|
|
194
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
195
|
+
if (!sameItems(x, y)) return false;
|
|
196
|
+
} else if (!Object.is(x, y)) return false;
|
|
197
|
+
}
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
function sameItems(a, b) {
|
|
201
|
+
return a === b || a.length === b.length && a.every((item, index) => Object.is(item, b[index]));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { EDITOR_CAPABILITY_IDS, FILE_COMMAND_EVENT, acceptedHostBackstagePages, capabilityHiddenActions, disabledCapabilities, documentMimeType, documentSaveMeta, fileCommandDetail, hostBackstageItemId, hostBackstagePageId, hostBackstageRegionId, hostMenuEntryId, isCapabilityEnabled, isDocumentStorage, isHostMenuEntry, mergeHiddenActions, placeHostBackstagePages, recoveryStoreOf, resolveHostMenuCommands, sameRegionContext, sameRenderer, saveToStorage, withHostMenuCommands, withoutHiddenEntries };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host context-menu commands: entries a host adds to an editor's right-click menu. Each command
|
|
3
|
+
* is plain data plus callbacks, so one descriptor works in every editor and framework binding.
|
|
4
|
+
* The context `C` is a product's immutable snapshot of what the menu was opened on (the
|
|
5
|
+
* selection, the slide, the cell range); the product documents its shape.
|
|
6
|
+
*/
|
|
7
|
+
/** One host command. Labels are plain text the host has already localised. */
|
|
8
|
+
export interface HostMenuCommand<C> {
|
|
9
|
+
/** Unique among the host commands of one menu; a repeated or empty id is ignored. */
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
/** A name from the shared icon set, for products whose menus show icons. */
|
|
13
|
+
icon?: string;
|
|
14
|
+
/** `top` (the default) is a group above the built-in entries; `bottom` one below them. */
|
|
15
|
+
group?: 'top' | 'bottom';
|
|
16
|
+
/** Shown only when this returns true (or is omitted). */
|
|
17
|
+
when?: (context: C) => boolean;
|
|
18
|
+
/** A disabled command is shown greyed out and never runs. */
|
|
19
|
+
disabled?: boolean | ((context: C) => boolean);
|
|
20
|
+
/** Runs after the menu closes, with the context the menu was opened on. */
|
|
21
|
+
onSelect: (context: C) => void;
|
|
22
|
+
}
|
|
23
|
+
/** A host command resolved for one opening of a menu. */
|
|
24
|
+
export interface HostMenuEntry {
|
|
25
|
+
/** `host:<id>`, so a host id can never collide with a built-in entry. */
|
|
26
|
+
id: `host:${string}`;
|
|
27
|
+
host: true;
|
|
28
|
+
label: string;
|
|
29
|
+
/** Kept for menus that look labels up by key; always empty for a host entry. */
|
|
30
|
+
labelKey: string;
|
|
31
|
+
icon?: string;
|
|
32
|
+
separatorBefore?: boolean;
|
|
33
|
+
disabled: boolean;
|
|
34
|
+
danger?: boolean;
|
|
35
|
+
checked?: boolean;
|
|
36
|
+
/** Runs the command (a no-op when disabled). */
|
|
37
|
+
onSelect: () => void;
|
|
38
|
+
}
|
|
39
|
+
/** The menu id of host command `id`. */
|
|
40
|
+
export declare function hostMenuEntryId(id: string): `host:${string}`;
|
|
41
|
+
/** True for an entry made from a host command. */
|
|
42
|
+
export declare function isHostMenuEntry(entry: unknown): entry is HostMenuEntry;
|
|
43
|
+
/** The host entries for one opening of a menu, split by group, in the host's order. */
|
|
44
|
+
export declare function resolveHostMenuCommands<C>(commands: readonly HostMenuCommand<C>[] | null | undefined, context: C): {
|
|
45
|
+
top: HostMenuEntry[];
|
|
46
|
+
bottom: HostMenuEntry[];
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* A menu with the host commands placed: the `top` group before the built-in entries and the
|
|
50
|
+
* `bottom` group after them, each separated from its neighbours, with no leading or trailing
|
|
51
|
+
* separator.
|
|
52
|
+
*/
|
|
53
|
+
export declare function withHostMenuCommands<E extends {
|
|
54
|
+
id: string;
|
|
55
|
+
separatorBefore?: boolean;
|
|
56
|
+
}, C>(entries: readonly E[], commands: readonly HostMenuCommand<C>[] | null | undefined, context: C): Array<E | HostMenuEntry>;
|
|
57
|
+
/**
|
|
58
|
+
* A menu without its hidden entries, with its groups intact: a hidden entry that starts a group
|
|
59
|
+
* (`separatorBefore`) passes the separator on to the next kept entry, and the first kept entry
|
|
60
|
+
* never starts with one. So hiding entries never merges two groups, never doubles a separator
|
|
61
|
+
* and never leaves one at the top. `entries` is not changed.
|
|
62
|
+
*/
|
|
63
|
+
export declare function withoutHiddenEntries<E extends {
|
|
64
|
+
separatorBefore?: boolean;
|
|
65
|
+
}>(entries: readonly E[], hidden: (entry: E) => boolean): E[];
|
|
66
|
+
//# sourceMappingURL=menu-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-commands.d.ts","sourceRoot":"","sources":["../../embedding/menu-commands.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8EAA8E;AAC9E,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,qFAAqF;IACrF,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0FAA0F;IAC1F,KAAK,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IACzB,yDAAyD;IACzD,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC;IAC/B,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC;IAC/C,2EAA2E;IAC3E,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;CAC/B;AAED,yDAAyD;AACzD,MAAM,WAAW,aAAa;IAC7B,yEAAyE;IACzE,EAAE,EAAE,QAAQ,MAAM,EAAE,CAAC;IACrB,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,wCAAwC;AACxC,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,MAAM,EAAE,CAE5D;AAED,kDAAkD;AAClD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED,uFAAuF;AACvF,wBAAgB,uBAAuB,CAAC,CAAC,EACxC,QAAQ,EAAE,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,EAC1D,OAAO,EAAE,CAAC,GACR;IAAE,GAAG,EAAE,aAAa,EAAE,CAAC;IAAC,MAAM,EAAE,aAAa,EAAE,CAAA;CAAE,CA0BnD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,EAC1F,OAAO,EAAE,SAAS,CAAC,EAAE,EACrB,QAAQ,EAAE,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,EAC1D,OAAO,EAAE,CAAC,GACR,KAAK,CAAC,CAAC,GAAG,aAAa,CAAC,CAQ1B;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,EAC3E,OAAO,EAAE,SAAS,CAAC,EAAE,EACrB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAC3B,CAAC,EAAE,CAaL"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host regions: places in an editor's layout that a host fills with its own UI (a File tab
|
|
3
|
+
* page, a dialog body, a docked pane). The editor keeps the place and hands it to the host as
|
|
4
|
+
* an empty container; the host fills it in any framework, or none, through ONE of two forms:
|
|
5
|
+
*
|
|
6
|
+
* - a mount function `(container, context) => cleanup | handle`, or
|
|
7
|
+
* - a custom element: its tag name, or `{ element, properties }`. The editor creates it,
|
|
8
|
+
* assigns `properties` once, and keeps its `context` property current.
|
|
9
|
+
*
|
|
10
|
+
* The contract is DOM-free: the container type is a parameter, which every product binds to
|
|
11
|
+
* `HTMLElement` in `ooxml-ui`, where the shared region host mounts it.
|
|
12
|
+
*/
|
|
13
|
+
/** A custom element a region creates (the host registers it). */
|
|
14
|
+
export interface HostRegionElement {
|
|
15
|
+
/** The tag name, for example `acme-policies`. */
|
|
16
|
+
element: string;
|
|
17
|
+
/** Properties assigned to the element once, before it is attached. */
|
|
18
|
+
properties?: Readonly<Record<string, unknown>>;
|
|
19
|
+
}
|
|
20
|
+
/** What a mount function may return to receive context updates and teardown. */
|
|
21
|
+
export interface HostRegionMountResult<Context> {
|
|
22
|
+
/** Called with the new context whenever it changes. */
|
|
23
|
+
update?(context: Context): void;
|
|
24
|
+
/** Called once when the region unmounts. */
|
|
25
|
+
destroy?(): void;
|
|
26
|
+
}
|
|
27
|
+
/** Fills `container` for one region. Returns nothing, a cleanup function or a handle. */
|
|
28
|
+
export type HostRegionMount<Container, Context> = (container: Container, context: Context) => void | (() => void) | HostRegionMountResult<Context>;
|
|
29
|
+
/** Any renderer form a region accepts. A string is a custom element tag name. */
|
|
30
|
+
export type HostRegionRenderer<Container, Context> = HostRegionMount<Container, Context> | HostRegionElement | string;
|
|
31
|
+
/** The context every product's host region receives, at least. */
|
|
32
|
+
export interface HostRegionContextBase {
|
|
33
|
+
/** Which region this renderer fills (for a host File tab page, `backstage.host.<id>`). */
|
|
34
|
+
readonly region: string;
|
|
35
|
+
/** The active UI locale (BCP 47). */
|
|
36
|
+
readonly locale: string;
|
|
37
|
+
/** False when the document is read-only (prop, capability or protection). */
|
|
38
|
+
readonly canEdit: boolean;
|
|
39
|
+
/** Dismisses the region: leaves the File tab, closes a dialog. A no-op where nothing closes. */
|
|
40
|
+
readonly close: () => void;
|
|
41
|
+
}
|
|
42
|
+
/** Region id a host File tab page is mounted under. */
|
|
43
|
+
export type HostBackstageRegionId = `backstage.host.${string}`;
|
|
44
|
+
/** The region id of host File tab page `id`. */
|
|
45
|
+
export declare function hostBackstageRegionId(id: string): HostBackstageRegionId;
|
|
46
|
+
/**
|
|
47
|
+
* True when two renderers are the same: the same function, the same tag, or element specs with
|
|
48
|
+
* the same tag and the same property values (so an inline `{ element, properties }` passed
|
|
49
|
+
* again on every render does not remount).
|
|
50
|
+
*/
|
|
51
|
+
export declare function sameRenderer<Container, Context>(a: HostRegionRenderer<Container, Context> | undefined, b: HostRegionRenderer<Container, Context> | undefined): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Shallow equality over two region contexts. Arrays (a selection) compare by value, and the
|
|
54
|
+
* fields named in `callbackKeys` are skipped: callbacks are recreated on every render and their
|
|
55
|
+
* identity is not a change.
|
|
56
|
+
*/
|
|
57
|
+
export declare function sameRegionContext(a: object, b: object, callbackKeys?: ReadonlySet<string>): boolean;
|
|
58
|
+
//# sourceMappingURL=regions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regions.d.ts","sourceRoot":"","sources":["../../embedding/regions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,iEAAiE;AACjE,MAAM,WAAW,iBAAiB;IACjC,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC/C;AAED,gFAAgF;AAChF,MAAM,WAAW,qBAAqB,CAAC,OAAO;IAC7C,uDAAuD;IACvD,MAAM,CAAC,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,4CAA4C;IAC5C,OAAO,CAAC,IAAI,IAAI,CAAC;CACjB;AAED,yFAAyF;AACzF,MAAM,MAAM,eAAe,CAAC,SAAS,EAAE,OAAO,IAAI,CACjD,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,KACZ,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;AAE1D,iFAAiF;AACjF,MAAM,MAAM,kBAAkB,CAAC,SAAS,EAAE,OAAO,IAC9C,eAAe,CAAC,SAAS,EAAE,OAAO,CAAC,GACnC,iBAAiB,GACjB,MAAM,CAAC;AAEV,kEAAkE;AAClE,MAAM,WAAW,qBAAqB;IACrC,0FAA0F;IAC1F,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,gGAAgG;IAChG,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,uDAAuD;AACvD,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,MAAM,EAAE,CAAC;AAE/D,gDAAgD;AAChD,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,qBAAqB,CAEvE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,OAAO,EAC9C,CAAC,EAAE,kBAAkB,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,SAAS,EACrD,CAAC,EAAE,kBAAkB,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,SAAS,GACnD,OAAO,CAWT;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,YAAY,GAAE,WAAW,CAAC,MAAM,CAAsB,GACpD,OAAO,CAYT"}
|