@leafer-in/editor 1.5.2 → 1.5.3

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/editor.js CHANGED
@@ -88,9 +88,24 @@ this.LeaferIN.editor = (function (exports, draw, core) {
88
88
  set(value) {
89
89
  const old = this[privateKey];
90
90
  if (old !== value) {
91
- const type = key === 'target' ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
92
- if (this.hasEvent(type))
93
- this.emitEvent(new EditorEvent(type, { editor: this, value: value, oldValue: old }));
91
+ if (this.config) {
92
+ const isSelect = key === 'target';
93
+ if (isSelect) {
94
+ if (value instanceof Array && value.length > 1 && value[0].locked)
95
+ value.splice(0, 1);
96
+ const { beforeSelect } = this.config;
97
+ if (beforeSelect) {
98
+ const check = beforeSelect({ target: value });
99
+ if (typeof check === 'object')
100
+ value = check;
101
+ else if (check === false)
102
+ return;
103
+ }
104
+ }
105
+ const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
106
+ if (this.hasEvent(type))
107
+ this.emitEvent(new EditorEvent(type, { editor: this, value: value, oldValue: old }));
108
+ }
94
109
  this[privateKey] = value, fn(this, old);
95
110
  }
96
111
  }
@@ -1125,11 +1140,7 @@ ${filterStyle}
1125
1140
  function onTarget(editor, oldValue) {
1126
1141
  const { target } = editor;
1127
1142
  if (target) {
1128
- const { list } = editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
1129
- if (!list.every(checkEditable)) {
1130
- editor.target = list.filter(checkEditable);
1131
- return;
1132
- }
1143
+ editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target);
1133
1144
  if (editor.multiple)
1134
1145
  simulate(editor);
1135
1146
  }
@@ -1156,9 +1167,6 @@ ${filterStyle}
1156
1167
  function onHover(editor, oldValue) {
1157
1168
  editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
1158
1169
  }
1159
- function checkEditable(item) {
1160
- return item.editable && !item.locked;
1161
- }
1162
1170
 
1163
1171
  const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
1164
1172
  const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);