@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.
@@ -88,9 +88,24 @@ function targetAttr(fn) {
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 @@ function simulate(editor) {
1125
1140
  function onTarget(editor, oldValue) {
1126
1141
  const { target } = editor;
1127
1142
  if (target) {
1128
- const { list } = editor.leafList = target instanceof LeafList ? target : new 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 LeafList ? target : new LeafList(target);
1133
1144
  if (editor.multiple)
1134
1145
  simulate(editor);
1135
1146
  }
@@ -1156,9 +1167,6 @@ function onTarget(editor, oldValue) {
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);