@knotx/plugins-selection 0.3.1 → 0.3.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/index.cjs CHANGED
@@ -73,8 +73,28 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
73
73
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
74
74
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
75
75
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
76
- var _destroy_dec, _clearSelection_dec, _getSelected_dec, _init_dec, _canInteract_dec, _endInteraction_dec, _startInteraction_dec, _registerRules_dec, _selected_dec, _a, _init;
77
- class Selection extends (_a = core.BasePlugin, _selected_dec = [decorators.register("selected")], _registerRules_dec = [decorators.register("registerRules")], _startInteraction_dec = [decorators.inject.startInteraction()], _endInteraction_dec = [decorators.inject.endInteraction()], _canInteract_dec = [decorators.inject.canInteract()], _init_dec = [decorators.OnInit], _getSelected_dec = [decorators.tool("Get selected items", {})], _clearSelection_dec = [decorators.tool("Clear selection", {})], _destroy_dec = [decorators.OnDestroy], _a) {
76
+ var _destroy_dec, _clearSelection_dec, _select_dec, _getSelected_dec, _init_dec, _interaction_dec, _registerRules_dec, _selected_dec, _a, _init;
77
+ class Selection extends (_a = core.BasePlugin, _selected_dec = [decorators.register("selected")], _registerRules_dec = [decorators.register("registerRules")], _interaction_dec = [decorators.inject.interaction()], _init_dec = [decorators.OnInit], _getSelected_dec = [decorators.tool("Get selected items", {})], _select_dec = [decorators.tool("Items that match the registered rules will be selected, manifested as the item showing a selected style.", {
78
+ type: "array",
79
+ items: {
80
+ type: "object",
81
+ properties: {
82
+ type: {
83
+ type: "string",
84
+ description: "item type such as node, group, etc."
85
+ },
86
+ id: {
87
+ type: "string"
88
+ }
89
+ },
90
+ additionalProperties: false,
91
+ required: [
92
+ "id",
93
+ "type"
94
+ ]
95
+ },
96
+ $schema: "http://json-schema.org/draft-07/schema#"
97
+ })], _clearSelection_dec = [decorators.tool("Clear selection", {})], _destroy_dec = [decorators.OnDestroy], _a) {
78
98
  constructor() {
79
99
  super(...arguments);
80
100
  __runInitializers(_init, 5, this);
@@ -99,23 +119,22 @@ class Selection extends (_a = core.BasePlugin, _selected_dec = [decorators.regis
99
119
  });
100
120
  };
101
121
  })), __runInitializers(_init, 15, this);
102
- __publicField(this, "startInteraction", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
103
- __publicField(this, "endInteraction", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
104
- __publicField(this, "canInteract", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
122
+ __publicField(this, "interaction", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
105
123
  __publicField(this, "onBeforeStart", (_) => {
106
124
  });
107
125
  __publicField(this, "onBeforeDrag", () => {
108
126
  this.isDragging = this.enableDrag;
109
- return this.enableDrag && this.canInteract(this.pluginId, "select", core.InteractionPriority.MarqueeSelection);
127
+ return this.enableDrag && this.interaction.canInteract(core.InteractionPriority.MarqueeSelection);
110
128
  });
111
129
  __publicField(this, "onStart", ({ event, store }) => {
112
130
  var _a2;
113
- this.startInteraction(this.pluginId, "select", core.InteractionPriority.MarqueeSelection);
131
+ this.interaction.start(this.pluginId, "select", core.InteractionPriority.MarqueeSelection);
114
132
  if (!(event == null ? void 0 : event.ctrlKey) && !(event == null ? void 0 : event.metaKey) && !(event == null ? void 0 : event.shiftKey)) {
115
133
  store.stored.forEach((element) => {
116
134
  const rule = this.getElementRule(element);
117
135
  if (rule == null ? void 0 : rule.activeClassName) {
118
136
  element.classList.remove(rule.activeClassName);
137
+ element.removeAttribute("data-selected");
119
138
  }
120
139
  });
121
140
  (_a2 = this.selection) == null ? void 0 : _a2.clearSelection(true, true);
@@ -152,6 +171,7 @@ class Selection extends (_a = core.BasePlugin, _selected_dec = [decorators.regis
152
171
  }
153
172
  if (rule.activeClassName) {
154
173
  element.classList.remove(rule.activeClassName);
174
+ element.removeAttribute("data-selected");
155
175
  }
156
176
  });
157
177
  added.forEach((element) => {
@@ -171,20 +191,21 @@ class Selection extends (_a = core.BasePlugin, _selected_dec = [decorators.regis
171
191
  }
172
192
  if (rule.activeClassName) {
173
193
  element.classList.add(rule.activeClassName);
194
+ element.setAttribute("data-selected", "true");
174
195
  }
175
196
  });
176
197
  });
177
198
  __publicField(this, "onStop", ({ event }) => {
178
- this.endInteraction(this.pluginId, "select");
199
+ this.interaction.end(this.pluginId, "select");
179
200
  if (event) {
180
201
  if (this.isDragging) {
181
202
  this.isDragging = false;
182
203
  }
183
204
  }
184
205
  cancelAnimationFrame(this.updateFrameId);
185
- this.updateFrameId = requestAnimationFrame(this.updateSelection);
206
+ this.updateFrameId = requestAnimationFrame(this.updateSelected);
186
207
  });
187
- __publicField(this, "updateSelection", () => {
208
+ __publicField(this, "updateSelected", () => {
188
209
  var _a2;
189
210
  const selected = [];
190
211
  for (const element of ((_a2 = this.selection) == null ? void 0 : _a2.getSelection()) || []) {
@@ -236,6 +257,21 @@ class Selection extends (_a = core.BasePlugin, _selected_dec = [decorators.regis
236
257
  getSelected() {
237
258
  return this.selected;
238
259
  }
260
+ select(items) {
261
+ var _a2;
262
+ const typeToClassName = /* @__PURE__ */ new Map();
263
+ this.ruleMap.forEach((rule, className) => {
264
+ typeToClassName.set(rule.type, className);
265
+ });
266
+ const selectors = [];
267
+ for (const item of items) {
268
+ const className = typeToClassName.get(item.type);
269
+ if (className) {
270
+ selectors.push(`.${className}[data-${item.type}-id="${item.id}"]`);
271
+ }
272
+ }
273
+ (_a2 = this.selection) == null ? void 0 : _a2.select(selectors);
274
+ }
239
275
  clearSelection() {
240
276
  var _a2;
241
277
  (_a2 = this.selection) == null ? void 0 : _a2.clearSelection(true, false);
@@ -249,13 +285,12 @@ class Selection extends (_a = core.BasePlugin, _selected_dec = [decorators.regis
249
285
  _init = __decoratorStart(_a);
250
286
  __decorateElement(_init, 1, "init", _init_dec, Selection);
251
287
  __decorateElement(_init, 1, "getSelected", _getSelected_dec, Selection);
288
+ __decorateElement(_init, 1, "select", _select_dec, Selection);
252
289
  __decorateElement(_init, 1, "clearSelection", _clearSelection_dec, Selection);
253
290
  __decorateElement(_init, 1, "destroy", _destroy_dec, Selection);
254
291
  __decorateElement(_init, 5, "selected", _selected_dec, Selection);
255
292
  __decorateElement(_init, 5, "registerRules", _registerRules_dec, Selection);
256
- __decorateElement(_init, 5, "startInteraction", _startInteraction_dec, Selection);
257
- __decorateElement(_init, 5, "endInteraction", _endInteraction_dec, Selection);
258
- __decorateElement(_init, 5, "canInteract", _canInteract_dec, Selection);
293
+ __decorateElement(_init, 5, "interaction", _interaction_dec, Selection);
259
294
  __decoratorMetadata(_init, Selection);
260
295
 
261
296
  exports.Selection = Selection;
package/dist/index.d.cts CHANGED
@@ -13,6 +13,7 @@ declare module '@knotx/core' {
13
13
  }
14
14
  interface PluginTools {
15
15
  selection: {
16
+ select: (items: SelectionSelectedItem[]) => void;
16
17
  getSelected: () => SelectionSelectedItem[];
17
18
  clearSelection: () => void;
18
19
  };
@@ -70,9 +71,7 @@ declare class Selection extends BasePlugin<'selection', SelectionConfig> {
70
71
  private updateFrameId;
71
72
  selected: SelectionSelectedItem[];
72
73
  registerRules: (rules: SelectionRule[]) => () => void;
73
- private startInteraction;
74
- private endInteraction;
75
- private canInteract;
74
+ private interaction;
76
75
  init(config?: SelectionConfig): void;
77
76
  private createSelection;
78
77
  private onBeforeStart;
@@ -81,8 +80,9 @@ declare class Selection extends BasePlugin<'selection', SelectionConfig> {
81
80
  private onMove;
82
81
  private onStop;
83
82
  private getElementRule;
84
- private updateSelection;
83
+ private updateSelected;
85
84
  getSelected(): SelectionSelectedItem[];
85
+ select(items: SelectionSelectedItem[]): void;
86
86
  clearSelection(): void;
87
87
  destroy(): void;
88
88
  }
package/dist/index.d.mts CHANGED
@@ -13,6 +13,7 @@ declare module '@knotx/core' {
13
13
  }
14
14
  interface PluginTools {
15
15
  selection: {
16
+ select: (items: SelectionSelectedItem[]) => void;
16
17
  getSelected: () => SelectionSelectedItem[];
17
18
  clearSelection: () => void;
18
19
  };
@@ -70,9 +71,7 @@ declare class Selection extends BasePlugin<'selection', SelectionConfig> {
70
71
  private updateFrameId;
71
72
  selected: SelectionSelectedItem[];
72
73
  registerRules: (rules: SelectionRule[]) => () => void;
73
- private startInteraction;
74
- private endInteraction;
75
- private canInteract;
74
+ private interaction;
76
75
  init(config?: SelectionConfig): void;
77
76
  private createSelection;
78
77
  private onBeforeStart;
@@ -81,8 +80,9 @@ declare class Selection extends BasePlugin<'selection', SelectionConfig> {
81
80
  private onMove;
82
81
  private onStop;
83
82
  private getElementRule;
84
- private updateSelection;
83
+ private updateSelected;
85
84
  getSelected(): SelectionSelectedItem[];
85
+ select(items: SelectionSelectedItem[]): void;
86
86
  clearSelection(): void;
87
87
  destroy(): void;
88
88
  }
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ declare module '@knotx/core' {
13
13
  }
14
14
  interface PluginTools {
15
15
  selection: {
16
+ select: (items: SelectionSelectedItem[]) => void;
16
17
  getSelected: () => SelectionSelectedItem[];
17
18
  clearSelection: () => void;
18
19
  };
@@ -70,9 +71,7 @@ declare class Selection extends BasePlugin<'selection', SelectionConfig> {
70
71
  private updateFrameId;
71
72
  selected: SelectionSelectedItem[];
72
73
  registerRules: (rules: SelectionRule[]) => () => void;
73
- private startInteraction;
74
- private endInteraction;
75
- private canInteract;
74
+ private interaction;
76
75
  init(config?: SelectionConfig): void;
77
76
  private createSelection;
78
77
  private onBeforeStart;
@@ -81,8 +80,9 @@ declare class Selection extends BasePlugin<'selection', SelectionConfig> {
81
80
  private onMove;
82
81
  private onStop;
83
82
  private getElementRule;
84
- private updateSelection;
83
+ private updateSelected;
85
84
  getSelected(): SelectionSelectedItem[];
85
+ select(items: SelectionSelectedItem[]): void;
86
86
  clearSelection(): void;
87
87
  destroy(): void;
88
88
  }
package/dist/index.js CHANGED
@@ -67,8 +67,28 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
67
67
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
68
68
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
69
69
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
70
- var _destroy_dec, _clearSelection_dec, _getSelected_dec, _init_dec, _canInteract_dec, _endInteraction_dec, _startInteraction_dec, _registerRules_dec, _selected_dec, _a, _init;
71
- class Selection extends (_a = BasePlugin, _selected_dec = [register("selected")], _registerRules_dec = [register("registerRules")], _startInteraction_dec = [inject.startInteraction()], _endInteraction_dec = [inject.endInteraction()], _canInteract_dec = [inject.canInteract()], _init_dec = [OnInit], _getSelected_dec = [tool("Get selected items", {})], _clearSelection_dec = [tool("Clear selection", {})], _destroy_dec = [OnDestroy], _a) {
70
+ var _destroy_dec, _clearSelection_dec, _select_dec, _getSelected_dec, _init_dec, _interaction_dec, _registerRules_dec, _selected_dec, _a, _init;
71
+ class Selection extends (_a = BasePlugin, _selected_dec = [register("selected")], _registerRules_dec = [register("registerRules")], _interaction_dec = [inject.interaction()], _init_dec = [OnInit], _getSelected_dec = [tool("Get selected items", {})], _select_dec = [tool("Items that match the registered rules will be selected, manifested as the item showing a selected style.", {
72
+ type: "array",
73
+ items: {
74
+ type: "object",
75
+ properties: {
76
+ type: {
77
+ type: "string",
78
+ description: "item type such as node, group, etc."
79
+ },
80
+ id: {
81
+ type: "string"
82
+ }
83
+ },
84
+ additionalProperties: false,
85
+ required: [
86
+ "id",
87
+ "type"
88
+ ]
89
+ },
90
+ $schema: "http://json-schema.org/draft-07/schema#"
91
+ })], _clearSelection_dec = [tool("Clear selection", {})], _destroy_dec = [OnDestroy], _a) {
72
92
  constructor() {
73
93
  super(...arguments);
74
94
  __runInitializers(_init, 5, this);
@@ -93,23 +113,22 @@ class Selection extends (_a = BasePlugin, _selected_dec = [register("selected")]
93
113
  });
94
114
  };
95
115
  })), __runInitializers(_init, 15, this);
96
- __publicField(this, "startInteraction", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
97
- __publicField(this, "endInteraction", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
98
- __publicField(this, "canInteract", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
116
+ __publicField(this, "interaction", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
99
117
  __publicField(this, "onBeforeStart", (_) => {
100
118
  });
101
119
  __publicField(this, "onBeforeDrag", () => {
102
120
  this.isDragging = this.enableDrag;
103
- return this.enableDrag && this.canInteract(this.pluginId, "select", InteractionPriority.MarqueeSelection);
121
+ return this.enableDrag && this.interaction.canInteract(InteractionPriority.MarqueeSelection);
104
122
  });
105
123
  __publicField(this, "onStart", ({ event, store }) => {
106
124
  var _a2;
107
- this.startInteraction(this.pluginId, "select", InteractionPriority.MarqueeSelection);
125
+ this.interaction.start(this.pluginId, "select", InteractionPriority.MarqueeSelection);
108
126
  if (!(event == null ? void 0 : event.ctrlKey) && !(event == null ? void 0 : event.metaKey) && !(event == null ? void 0 : event.shiftKey)) {
109
127
  store.stored.forEach((element) => {
110
128
  const rule = this.getElementRule(element);
111
129
  if (rule == null ? void 0 : rule.activeClassName) {
112
130
  element.classList.remove(rule.activeClassName);
131
+ element.removeAttribute("data-selected");
113
132
  }
114
133
  });
115
134
  (_a2 = this.selection) == null ? void 0 : _a2.clearSelection(true, true);
@@ -146,6 +165,7 @@ class Selection extends (_a = BasePlugin, _selected_dec = [register("selected")]
146
165
  }
147
166
  if (rule.activeClassName) {
148
167
  element.classList.remove(rule.activeClassName);
168
+ element.removeAttribute("data-selected");
149
169
  }
150
170
  });
151
171
  added.forEach((element) => {
@@ -165,20 +185,21 @@ class Selection extends (_a = BasePlugin, _selected_dec = [register("selected")]
165
185
  }
166
186
  if (rule.activeClassName) {
167
187
  element.classList.add(rule.activeClassName);
188
+ element.setAttribute("data-selected", "true");
168
189
  }
169
190
  });
170
191
  });
171
192
  __publicField(this, "onStop", ({ event }) => {
172
- this.endInteraction(this.pluginId, "select");
193
+ this.interaction.end(this.pluginId, "select");
173
194
  if (event) {
174
195
  if (this.isDragging) {
175
196
  this.isDragging = false;
176
197
  }
177
198
  }
178
199
  cancelAnimationFrame(this.updateFrameId);
179
- this.updateFrameId = requestAnimationFrame(this.updateSelection);
200
+ this.updateFrameId = requestAnimationFrame(this.updateSelected);
180
201
  });
181
- __publicField(this, "updateSelection", () => {
202
+ __publicField(this, "updateSelected", () => {
182
203
  var _a2;
183
204
  const selected = [];
184
205
  for (const element of ((_a2 = this.selection) == null ? void 0 : _a2.getSelection()) || []) {
@@ -230,6 +251,21 @@ class Selection extends (_a = BasePlugin, _selected_dec = [register("selected")]
230
251
  getSelected() {
231
252
  return this.selected;
232
253
  }
254
+ select(items) {
255
+ var _a2;
256
+ const typeToClassName = /* @__PURE__ */ new Map();
257
+ this.ruleMap.forEach((rule, className) => {
258
+ typeToClassName.set(rule.type, className);
259
+ });
260
+ const selectors = [];
261
+ for (const item of items) {
262
+ const className = typeToClassName.get(item.type);
263
+ if (className) {
264
+ selectors.push(`.${className}[data-${item.type}-id="${item.id}"]`);
265
+ }
266
+ }
267
+ (_a2 = this.selection) == null ? void 0 : _a2.select(selectors);
268
+ }
233
269
  clearSelection() {
234
270
  var _a2;
235
271
  (_a2 = this.selection) == null ? void 0 : _a2.clearSelection(true, false);
@@ -243,13 +279,12 @@ class Selection extends (_a = BasePlugin, _selected_dec = [register("selected")]
243
279
  _init = __decoratorStart(_a);
244
280
  __decorateElement(_init, 1, "init", _init_dec, Selection);
245
281
  __decorateElement(_init, 1, "getSelected", _getSelected_dec, Selection);
282
+ __decorateElement(_init, 1, "select", _select_dec, Selection);
246
283
  __decorateElement(_init, 1, "clearSelection", _clearSelection_dec, Selection);
247
284
  __decorateElement(_init, 1, "destroy", _destroy_dec, Selection);
248
285
  __decorateElement(_init, 5, "selected", _selected_dec, Selection);
249
286
  __decorateElement(_init, 5, "registerRules", _registerRules_dec, Selection);
250
- __decorateElement(_init, 5, "startInteraction", _startInteraction_dec, Selection);
251
- __decorateElement(_init, 5, "endInteraction", _endInteraction_dec, Selection);
252
- __decorateElement(_init, 5, "canInteract", _canInteract_dec, Selection);
287
+ __decorateElement(_init, 5, "interaction", _interaction_dec, Selection);
253
288
  __decoratorMetadata(_init, Selection);
254
289
 
255
290
  export { Selection };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/plugins-selection",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Selection Plugin for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -30,13 +30,13 @@
30
30
  "dependencies": {
31
31
  "@viselect/vanilla": "^3.9.0",
32
32
  "rxjs": "^7.8.1",
33
- "@knotx/core": "0.3.1",
34
- "@knotx/decorators": "0.3.1"
33
+ "@knotx/core": "0.3.3",
34
+ "@knotx/decorators": "0.3.3"
35
35
  },
36
36
  "devDependencies": {
37
- "@knotx/build-config": "0.3.1",
38
- "@knotx/eslint-config": "0.3.1",
39
- "@knotx/typescript-config": "0.3.1"
37
+ "@knotx/build-config": "0.3.3",
38
+ "@knotx/eslint-config": "0.3.3",
39
+ "@knotx/typescript-config": "0.3.3"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "unbuild",