roosterjs 8.12.0 → 8.13.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/rooster.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for roosterjs (Version 8.12.0)
1
+ // Type definitions for roosterjs (Version 8.13.0)
2
2
  // Generated by dts tool from roosterjs
3
3
  // Project: https://github.com/Microsoft/roosterjs
4
4
 
@@ -771,7 +771,13 @@ const enum GetContentMode {
771
771
  /**
772
772
  * Get plain text content only, all format will be ignored
773
773
  */
774
- PlainText = 3
774
+ PlainText = 3,
775
+ /**
776
+ * A fast way to get plain text content, the line-end positions may not be exactly same with HTML content,
777
+ * but the text content should be the same. This is used for quickly retrieve text content and check
778
+ * text only
779
+ */
780
+ PlainTextFast = 4
775
781
  }
776
782
 
777
783
  /**
@@ -2813,6 +2819,10 @@ interface IEditor {
2813
2819
  * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types
2814
2820
  */
2815
2821
  getTrustedHTMLHandler(): TrustedHTMLHandler;
2822
+ /**
2823
+ * Get a transformer function. It transform the size changes according to current situation.
2824
+ */
2825
+ getSizeTransformer(): SizeTransformer;
2816
2826
  }
2817
2827
 
2818
2828
  /**
@@ -3013,6 +3023,12 @@ interface EditorCore extends PluginState {
3013
3023
  * To override, pass your own trusted HTML handler to EditorOptions.trustedHTMLHandler
3014
3024
  */
3015
3025
  readonly trustedHTMLHandler: TrustedHTMLHandler;
3026
+ /**
3027
+ * A transformer function. It transform the size changes according to current situation.
3028
+ * A typical scenario to use this function is when editor is located under a scaled container, so we need to
3029
+ * calculate the scaled size change according to current zoom rate.
3030
+ */
3031
+ sizeTransformer: SizeTransformer;
3016
3032
  }
3017
3033
 
3018
3034
  /**
@@ -3368,6 +3384,12 @@ interface EditorOptions {
3368
3384
  * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types
3369
3385
  */
3370
3386
  trustedHTMLHandler?: TrustedHTMLHandler;
3387
+ /**
3388
+ * A transformer function. It transform the size changes according to current situation.
3389
+ * A typical scenario to use this function is when editor is located under a scaled container, so we need to
3390
+ * calculate the scaled size change according to current zoom rate.
3391
+ */
3392
+ sizeTransformer?: SizeTransformer;
3371
3393
  }
3372
3394
 
3373
3395
  /**
@@ -4059,6 +4081,15 @@ type DOMEventHandler = PluginEventType | DOMEventHandlerFunction | DOMEventHandl
4059
4081
  */
4060
4082
  type TrustedHTMLHandler = (html: string) => string;
4061
4083
 
4084
+ /**
4085
+ * A transformer function. It transform the size changes according to current situation.
4086
+ * A typical scenario to use this function is when editor is located under a scaled container, so we need to
4087
+ * calculate the scaled size change according to current zoom rate.
4088
+ * @param size Original delta size from mouse event
4089
+ * @returns Calculated delta size. By default it should just return original value
4090
+ */
4091
+ type SizeTransformer = (size: number) => number;
4092
+
4062
4093
  /**
4063
4094
  * This produces a block element from a a node
4064
4095
  * It needs to account for various HTML structure. Examples:
@@ -5938,6 +5969,10 @@ class Editor implements IEditor {
5938
5969
  * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types
5939
5970
  */
5940
5971
  getTrustedHTMLHandler(): TrustedHTMLHandler;
5972
+ /**
5973
+ * Get a transformer function. It transform the size changes according to current situation.
5974
+ */
5975
+ getSizeTransformer(): SizeTransformer;
5941
5976
  }
5942
5977
 
5943
5978
  /**
package/dist/rooster.js CHANGED
@@ -4768,7 +4768,10 @@ var getContent = function (core, mode) {
4768
4768
  // When there is fragment for shadow edit, always use the cached fragment as document since HTML node in editor
4769
4769
  // has been changed by uncommitted shadow edit which should be ignored.
4770
4770
  var root = core.lifecycle.shadowEditFragment || core.contentDiv;
4771
- if (mode == 3 /* PlainText */) {
4771
+ if (mode == 4 /* PlainTextFast */) {
4772
+ content = root.textContent;
4773
+ }
4774
+ else if (mode == 3 /* PlainText */) {
4772
4775
  content = (0, roosterjs_editor_dom_1.getTextContent)(root);
4773
4776
  }
4774
4777
  else if (triggerExtractContentEvent || core.lifecycle.isDarkMode) {
@@ -5511,7 +5514,8 @@ exports.triggerEvent = void 0;
5511
5514
  * @param broadcast Set to true to skip the shouldHandleEventExclusively check
5512
5515
  */
5513
5516
  var triggerEvent = function (core, pluginEvent, broadcast) {
5514
- if (!core.lifecycle.shadowEditFragment &&
5517
+ if ((!core.lifecycle.shadowEditFragment ||
5518
+ pluginEvent.eventType == 12 /* BeforeDispose */) &&
5515
5519
  (broadcast || !core.plugins.some(function (plugin) { return handledExclusively(pluginEvent, plugin); }))) {
5516
5520
  core.plugins.forEach(function (plugin) {
5517
5521
  if (plugin.onPluginEvent) {
@@ -6988,11 +6992,11 @@ function createCorePlugins(contentDiv, options) {
6988
6992
  return {
6989
6993
  typeInContainer: map.typeInContainer || new TypeInContainerPlugin_1.default(),
6990
6994
  edit: map.edit || new EditPlugin_1.default(),
6995
+ pendingFormatState: map.pendingFormatState || new PendingFormatStatePlugin_1.default(),
6991
6996
  _placeholder: null,
6992
6997
  typeAfterLink: null,
6993
6998
  undo: map.undo || new UndoPlugin_1.default(options),
6994
6999
  domEvent: map.domEvent || new DOMEventPlugin_1.default(options, contentDiv),
6995
- pendingFormatState: map.pendingFormatState || new PendingFormatStatePlugin_1.default(),
6996
7000
  mouseUp: map.mouseUp || new MouseUpPlugin_1.default(),
6997
7001
  copyPaste: map.copyPaste || new CopyPastePlugin_1.default(options),
6998
7002
  entity: map.entity || new EntityPlugin_1.default(),
@@ -7073,7 +7077,7 @@ var Editor = /** @class */ (function () {
7073
7077
  plugins.push(corePlugins[name]);
7074
7078
  }
7075
7079
  });
7076
- this.core = __assign(__assign({ contentDiv: contentDiv, api: __assign(__assign({}, coreApiMap_1.coreApiMap), (options.coreApiOverride || {})), plugins: plugins.filter(function (x) { return !!x; }) }, (0, createCorePlugins_1.getPluginState)(corePlugins)), { trustedHTMLHandler: options.trustedHTMLHandler || (function (html) { return html; }) });
7080
+ this.core = __assign(__assign({ contentDiv: contentDiv, api: __assign(__assign({}, coreApiMap_1.coreApiMap), (options.coreApiOverride || {})), plugins: plugins.filter(function (x) { return !!x; }) }, (0, createCorePlugins_1.getPluginState)(corePlugins)), { trustedHTMLHandler: options.trustedHTMLHandler || (function (html) { return html; }), sizeTransformer: options.sizeTransformer });
7077
7081
  // 3. Initialize plugins
7078
7082
  this.core.plugins.forEach(function (plugin) { return plugin.initialize(_this); });
7079
7083
  // 4. Ensure user will type in a container node, not the editor content DIV
@@ -7083,7 +7087,9 @@ var Editor = /** @class */ (function () {
7083
7087
  * Dispose this editor, dispose all plugins and custom data
7084
7088
  */
7085
7089
  Editor.prototype.dispose = function () {
7086
- this.core.plugins.reverse().forEach(function (plugin) { return plugin.dispose(); });
7090
+ for (var i = this.core.plugins.length - 1; i >= 0; i--) {
7091
+ this.core.plugins[i].dispose();
7092
+ }
7087
7093
  this.core = null;
7088
7094
  };
7089
7095
  /**
@@ -7666,6 +7672,12 @@ var Editor = /** @class */ (function () {
7666
7672
  Editor.prototype.getTrustedHTMLHandler = function () {
7667
7673
  return this.core.trustedHTMLHandler;
7668
7674
  };
7675
+ /**
7676
+ * Get a transformer function. It transform the size changes according to current situation.
7677
+ */
7678
+ Editor.prototype.getSizeTransformer = function () {
7679
+ return this.core.sizeTransformer;
7680
+ };
7669
7681
  return Editor;
7670
7682
  }());
7671
7683
  exports.default = Editor;
@@ -15884,6 +15896,9 @@ __exportStar(__webpack_require__(/*! ./Watermark */ "./packages/roosterjs-editor
15884
15896
  "use strict";
15885
15897
 
15886
15898
  Object.defineProperty(exports, "__esModule", { value: true });
15899
+ function defaultTransformer(size) {
15900
+ return size;
15901
+ }
15887
15902
  /**
15888
15903
  * @internal
15889
15904
  * A helper class to help manage drag and drop to an HTML element
@@ -15898,12 +15913,13 @@ var DragAndDropHelper = /** @class */ (function () {
15898
15913
  * @param onSubmit A callback that will be invoked when event handler in handler object returns true
15899
15914
  * @param handler The event handler object, see DragAndDropHandler interface for more information
15900
15915
  */
15901
- function DragAndDropHelper(trigger, context, onSubmit, handler) {
15916
+ function DragAndDropHelper(trigger, context, onSubmit, handler, sizeTransformer) {
15902
15917
  var _this = this;
15903
15918
  this.trigger = trigger;
15904
15919
  this.context = context;
15905
15920
  this.onSubmit = onSubmit;
15906
15921
  this.handler = handler;
15922
+ this.sizeTransformer = sizeTransformer;
15907
15923
  this.onMouseDown = function (e) {
15908
15924
  var _a, _b;
15909
15925
  e.preventDefault();
@@ -15916,8 +15932,9 @@ var DragAndDropHelper = /** @class */ (function () {
15916
15932
  this.onMouseMove = function (e) {
15917
15933
  var _a, _b, _c;
15918
15934
  e.preventDefault();
15919
- var deltaX = e.pageX - _this.initX;
15920
- var deltaY = e.pageY - _this.initY;
15935
+ var sizeTransformer = _this.sizeTransformer || defaultTransformer;
15936
+ var deltaX = sizeTransformer(e.pageX - _this.initX);
15937
+ var deltaY = sizeTransformer(e.pageY - _this.initY);
15921
15938
  if ((_b = (_a = _this.handler).onDragging) === null || _b === void 0 ? void 0 : _b.call(_a, _this.context, e, _this.initValue, deltaX, deltaY)) {
15922
15939
  (_c = _this.onSubmit) === null || _c === void 0 ? void 0 : _c.call(_this, _this.context);
15923
15940
  }
@@ -17204,9 +17221,7 @@ var ContextMenu = /** @class */ (function () {
17204
17221
  ContextMenu.prototype.initContainer = function (x, y) {
17205
17222
  if (!this.container) {
17206
17223
  this.container = (0, roosterjs_editor_dom_1.createElement)(5 /* ContextMenuWrapper */, this.editor.getDocument());
17207
- this.editor.insertNode(this.container, {
17208
- position: 4 /* Outside */,
17209
- });
17224
+ this.editor.getDocument().body.appendChild(this.container);
17210
17225
  }
17211
17226
  this.container.style.left = x + 'px';
17212
17227
  this.container.style.top = y + 'px';
@@ -17305,7 +17320,7 @@ var CustomReplacePlugin = /** @class */ (function () {
17305
17320
  */
17306
17321
  CustomReplacePlugin.prototype.onPluginEvent = function (event) {
17307
17322
  var _this = this;
17308
- if (this.editor.isInIME() || event.eventType != 3 /* Input */) {
17323
+ if (event.eventType != 3 /* Input */ || this.editor.isInIME()) {
17309
17324
  return;
17310
17325
  }
17311
17326
  // Exit early on input events that do not insert a replacement's final character.
@@ -18044,7 +18059,7 @@ var ImageEdit = /** @class */ (function () {
18044
18059
  wrapper.style.verticalAlign = 'bottom';
18045
18060
  wrapper.style.display = roosterjs_editor_dom_1.Browser.isSafari ? 'inline-block' : 'inline-flex';
18046
18061
  // Cache current src so that we can compare it after edit see if src is changed
18047
- this.lastSrc = this.image.src;
18062
+ this.lastSrc = this.image.getAttribute('src');
18048
18063
  // Set image src to original src to help show editing UI, also it will be used when regenerate image dataURL after editing
18049
18064
  this.image.src = this.editInfo.src;
18050
18065
  this.image.style.position = 'absolute';
@@ -18097,7 +18112,7 @@ var ImageEdit = /** @class */ (function () {
18097
18112
  var wrapper = this.getImageWrapper(this.image);
18098
18113
  return wrapper
18099
18114
  ? getEditElements(wrapper, elementClass).map(function (element) {
18100
- return new DragAndDropHelper_1.default(element, __assign(__assign({}, commonContext), { x: element.dataset.x, y: element.dataset.y }), _this.updateWrapper, dragAndDrop);
18115
+ return new DragAndDropHelper_1.default(element, __assign(__assign({}, commonContext), { x: element.dataset.x, y: element.dataset.y }), _this.updateWrapper, dragAndDrop, _this.editor.getSizeTransformer());
18101
18116
  })
18102
18117
  : [];
18103
18118
  };
@@ -18304,7 +18319,7 @@ function resizeByPercentage(editor, image, percentage, minWidth, minHeight) {
18304
18319
  if (!(0, isResizedTo_1.default)(image, percentage)) {
18305
18320
  loadImage(image, editInfo.src, function () {
18306
18321
  if (!editor.isDisposed() && editor.contains(image)) {
18307
- var lastSrc_1 = image.src;
18322
+ var lastSrc_1 = image.getAttribute('src');
18308
18323
  var _a = (0, getTargetSizeByPercentage_1.default)(editInfo, percentage), width = _a.width, height = _a.height;
18309
18324
  editInfo.widthPx = Math.max(width, minWidth);
18310
18325
  editInfo.heightPx = Math.max(height, minHeight);
@@ -18548,7 +18563,7 @@ function getEditInfoFromImage(image) {
18548
18563
  exports.getEditInfoFromImage = getEditInfoFromImage;
18549
18564
  function getInitialEditInfo(image) {
18550
18565
  return {
18551
- src: image.src,
18566
+ src: image.getAttribute('src') || '',
18552
18567
  widthPx: image.clientWidth,
18553
18568
  heightPx: image.clientHeight,
18554
18569
  naturalWidth: image.naturalWidth,