@innovastudio/contentbuilder 1.5.230 → 1.5.231
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/index.d.ts
CHANGED
|
@@ -689,6 +689,11 @@ interface ContentBuilderAddonApi {
|
|
|
689
689
|
/** ContentBox: fn(box) runs each time the selected box changes (null when none is selected).
|
|
690
690
|
* Never runs in ContentBuilder. Returns a function that stops it. */
|
|
691
691
|
onSelectBox(fn: (box: HTMLElement | null) => void): () => void;
|
|
692
|
+
/** fn(doc) runs with the document the content lives in (ContentBox: its page frame; else the page),
|
|
693
|
+
* also when the page has no content yet: where to listen to the content or add styles for it.
|
|
694
|
+
* The function fn returns, if any, runs when the add-on is removed or the editor destroyed.
|
|
695
|
+
* Returns a function that does that now. */
|
|
696
|
+
onDocument(fn: (doc: Document) => void | (() => void)): () => void;
|
|
692
697
|
/** Change the content as one undo step. Return false from fn when nothing changed. */
|
|
693
698
|
edit<T>(fn: () => T): T;
|
|
694
699
|
};
|
package/package.json
CHANGED
|
@@ -100420,6 +100420,34 @@ class AddonHost {
|
|
|
100420
100420
|
host.boxHandlers = host.boxHandlers.filter(e => e !== entry);
|
|
100421
100421
|
});
|
|
100422
100422
|
},
|
|
100423
|
+
/** fn(doc) runs with the document the content lives in (in
|
|
100424
|
+
ContentBox its page frame, else the page), also when the
|
|
100425
|
+
page has no content yet: the place to listen to the content
|
|
100426
|
+
or add styles for it. The function fn returns, if any, runs
|
|
100427
|
+
when the add-on is removed or the editor destroyed. Returns
|
|
100428
|
+
a function that does that now. */
|
|
100429
|
+
onDocument(fn) {
|
|
100430
|
+
if (typeof fn !== 'function') return () => {};
|
|
100431
|
+
let undo = null;
|
|
100432
|
+
try {
|
|
100433
|
+
const r = fn(builder.doc);
|
|
100434
|
+
if (typeof r === 'function') undo = r;
|
|
100435
|
+
} catch (e) {
|
|
100436
|
+
log(record.name, 'onDocument failed.', e);
|
|
100437
|
+
}
|
|
100438
|
+
let done = false;
|
|
100439
|
+
return track(() => {
|
|
100440
|
+
if (done) return;
|
|
100441
|
+
done = true;
|
|
100442
|
+
if (undo) {
|
|
100443
|
+
try {
|
|
100444
|
+
undo();
|
|
100445
|
+
} catch (e) {
|
|
100446
|
+
log(record.name, 'onDocument cleanup failed.', e);
|
|
100447
|
+
}
|
|
100448
|
+
}
|
|
100449
|
+
});
|
|
100450
|
+
},
|
|
100423
100451
|
/** The SVG drawing the user selected in the text by clicking it (an
|
|
100424
100452
|
inserted icon or equation), or null. */
|
|
100425
100453
|
selectedSvg() {
|