@qti-editor/interaction-select-point 0.1.0 → 0.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"qti-select-point-interaction.commands.d.ts","sourceRoot":"","sources":["../../../src/components/qti-select-point-interaction/qti-select-point-interaction.commands.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,4BAA4B,EAAE,OA0B1C,CAAC"}
1
+ {"version":3,"file":"qti-select-point-interaction.commands.d.ts","sourceRoot":"","sources":["../../../src/components/qti-select-point-interaction/qti-select-point-interaction.commands.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGjD;;GAEG;AACH,eAAO,MAAM,4BAA4B,EAAE,OA0B1C,CAAC"}
@@ -1,8 +1,9 @@
1
1
  import { createInsertBlockInteractionCommand } from '@qti-editor/interaction-shared/commands/insert.js';
2
+ import { translateQti } from '@qti-editor/interaction-shared';
2
3
  /**
3
4
  * Command to insert a select point interaction at the current selection.
4
5
  */
5
- export const insertSelectPointInteraction = (state, dispatch) => {
6
+ export const insertSelectPointInteraction = (state, dispatch, view) => {
6
7
  return createInsertBlockInteractionCommand({
7
8
  createNode: currentState => {
8
9
  const { schema } = currentState;
@@ -12,7 +13,7 @@ export const insertSelectPointInteraction = (state, dispatch) => {
12
13
  const imgSelectPointType = schema.nodes.imgSelectPoint;
13
14
  if (!interactionType || !promptType || !promptParagraphType || !imgSelectPointType)
14
15
  return null;
15
- const prompt = promptType.create(null, promptParagraphType.create(null, schema.text('Mark the correct point on the image.')));
16
+ const prompt = promptType.create(null, promptParagraphType.create(null, schema.text(translateQti('prompt.selectPoint.default', { target: view?.dom ?? null }))));
16
17
  const imgSelectPoint = imgSelectPointType.create();
17
18
  return interactionType.create({
18
19
  responseIdentifier: `RESPONSE_${crypto.randomUUID()}`,
@@ -20,16 +20,19 @@ export declare class QtiSelectPointInteractionEdit extends Interaction {
20
20
  #private;
21
21
  static styles: CSSResultGroup;
22
22
  areaMappings: string;
23
- protected drawMode: DrawMode;
24
- protected imageReady: boolean;
25
- protected imageSrc: string | null;
26
- protected imageAlt: string | null;
27
- protected imageWidth: number | null;
28
- protected imageHeight: number | null;
29
- protected areaEntries: AreaMappingEntry[];
30
- protected draft: DraftShape | null;
31
- protected sourceError: string | null;
23
+ private _cursorInside;
24
+ drawMode: DrawMode;
25
+ imageReady: boolean;
26
+ imageSrc: string | null;
27
+ imageAlt: string | null;
28
+ imageWidth: number | null;
29
+ imageHeight: number | null;
30
+ areaEntries: AreaMappingEntry[];
31
+ draft: DraftShape | null;
32
+ sourceError: string | null;
33
+ private _onSelectionChange;
32
34
  connectedCallback(): void;
35
+ disconnectedCallback(): void;
33
36
  firstUpdated(): void;
34
37
  updated(changedProperties: Map<string | number | symbol, unknown>): void;
35
38
  render(): TemplateResult<1>;
@@ -1 +1 @@
1
- {"version":3,"file":"qti-select-point-interaction.d.ts","sourceRoot":"","sources":["../../../src/components/qti-select-point-interaction/qti-select-point-interaction.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,0DAA0D,CAAC;AAEvF,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAE1D,KAAK,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAC7C,KAAK,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEnC,KAAK,gBAAgB,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,KAAK,EAAE,SAAS,CAAC;IAC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,gBAAgB,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAsBF,qBAAa,6BAA8B,SAAQ,WAAW;;IAC5D,OAAgB,MAAM,EAAE,cAAc,CAsFpC;IAGF,YAAY,SAAQ;IAGpB,OAAO,CAAC,aAAa,CAAS;IAG9B,QAAQ,EAAE,QAAQ,CAAY;IAG9B,UAAU,UAAS;IAGnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAG/B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAG/B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGjC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGlC,WAAW,EAAE,gBAAgB,EAAE,CAAM;IAGrC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAQ;IAGhC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAQlC,OAAO,CAAC,kBAAkB,CAMxB;IAEO,iBAAiB,IAAI,IAAI;IAMzB,oBAAoB,IAAI,IAAI;IAK5B,YAAY,IAAI,IAAI;IAKpB,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IA8fxE,MAAM;CA+DhB"}
@@ -25,6 +25,7 @@ export class QtiSelectPointInteractionEdit extends Interaction {
25
25
  super(...arguments);
26
26
  _QtiSelectPointInteractionEdit_instances.add(this);
27
27
  this.areaMappings = '[]';
28
+ this._cursorInside = false;
28
29
  this.drawMode = 'select';
29
30
  this.imageReady = false;
30
31
  this.imageSrc = null;
@@ -39,6 +40,13 @@ export class QtiSelectPointInteractionEdit extends Interaction {
39
40
  _QtiSelectPointInteractionEdit_activePointerId.set(this, null);
40
41
  _QtiSelectPointInteractionEdit_shapeDrag.set(this, null);
41
42
  _QtiSelectPointInteractionEdit_fileInputRef.set(this, createRef());
43
+ this._onSelectionChange = () => {
44
+ const sel = document.getSelection();
45
+ const inside = sel ? this.contains(sel.anchorNode) : false;
46
+ if (inside !== this._cursorInside) {
47
+ this._cursorInside = inside;
48
+ }
49
+ };
42
50
  _QtiSelectPointInteractionEdit_onImageLoad.set(this, (event) => {
43
51
  const img = event.currentTarget;
44
52
  __classPrivateFieldSet(this, _QtiSelectPointInteractionEdit_imageElement, img, "f");
@@ -53,6 +61,11 @@ export class QtiSelectPointInteractionEdit extends Interaction {
53
61
  connectedCallback() {
54
62
  super.connectedCallback();
55
63
  __classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_syncAreaEntriesFromAttribute).call(this);
64
+ document.addEventListener('selectionchange', this._onSelectionChange);
65
+ }
66
+ disconnectedCallback() {
67
+ super.disconnectedCallback();
68
+ document.removeEventListener('selectionchange', this._onSelectionChange);
56
69
  }
57
70
  firstUpdated() {
58
71
  __classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_ensureChildSlots).call(this);
@@ -69,41 +82,44 @@ export class QtiSelectPointInteractionEdit extends Interaction {
69
82
  return html `
70
83
  <slot name="prompt"></slot>
71
84
 
72
- <div class="toolbar">
73
- ${this.imageSrc
85
+ ${this._cursorInside ? html `
86
+ <div class="toolbar" @mousedown=${(e) => e.preventDefault()}>
87
+ ${this.imageSrc
74
88
  ? html `
75
- <button
76
- type="button"
77
- aria-pressed=${this.drawMode === 'select'}
78
- @click=${() => __classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_setDrawMode).call(this, 'select')}
79
- >
80
- Select
81
- </button>
82
- <button
83
- type="button"
84
- aria-pressed=${this.drawMode === 'circle'}
85
- @click=${() => __classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_setDrawMode).call(this, 'circle')}
86
- >
87
- Circle
88
- </button>
89
- <button
90
- type="button"
91
- aria-pressed=${this.drawMode === 'rect'}
92
- @click=${() => __classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_setDrawMode).call(this, 'rect')}
93
- >
94
- Rect
95
- </button>
96
- <button type="button" class="danger" @click=${__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_clearMappings)}>Clear mappings</button>
97
- <button type="button" class="danger" @click=${__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_removeImage)}>Remove image</button>
98
- `
89
+ <button
90
+ type="button"
91
+ aria-pressed=${this.drawMode === 'select'}
92
+ @click=${() => __classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_setDrawMode).call(this, 'select')}
93
+ >
94
+ Select
95
+ </button>
96
+ <button
97
+ type="button"
98
+ aria-pressed=${this.drawMode === 'circle'}
99
+ @click=${() => __classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_setDrawMode).call(this, 'circle')}
100
+ >
101
+ Circle
102
+ </button>
103
+ <button
104
+ type="button"
105
+ aria-pressed=${this.drawMode === 'rect'}
106
+ @click=${() => __classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_setDrawMode).call(this, 'rect')}
107
+ >
108
+ Rect
109
+ </button>
110
+ <button type="button" class="danger" @click=${__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_clearMappings)}>Clear mappings</button>
111
+ <button type="button" class="danger" @click=${__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_removeImage)}>Remove image</button>
112
+ `
99
113
  : html `
100
- <button type="button" @click=${__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_pasteImageFromClipboard)}>Paste URL</button>
101
- <button type="button" @click=${__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_openFilePicker)}>Upload image</button>
102
- <input ${ref(__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_fileInputRef, "f"))} type="file" accept="image/*" @change=${__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_onFileChange)} />
103
- `}
104
- </div>
114
+ <button type="button" @click=${__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_pasteImageFromClipboard)}>Paste URL</button>
115
+ <button type="button" @click=${__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_openFilePicker)}>Upload image</button>
116
+ `}
117
+ </div>
118
+ ${this.sourceError ? html `<p class="meta" style="color:#b91c1c; margin-top:0;">${this.sourceError}</p>` : nothing}
119
+ <div class="meta">Mappings: ${this.areaEntries.length} | mode: ${this.drawMode}</div>
120
+ ` : nothing}
105
121
 
106
- ${this.sourceError ? html `<p class="meta" style="color:#b91c1c; margin-top:0;">${this.sourceError}</p>` : nothing}
122
+ <input ${ref(__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_fileInputRef, "f"))} type="file" accept="image/*" @change=${__classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_onFileChange)} />
107
123
 
108
124
  <div
109
125
  class="surface"
@@ -120,8 +136,6 @@ export class QtiSelectPointInteractionEdit extends Interaction {
120
136
  `
121
137
  : nothing}
122
138
  </div>
123
-
124
- <div class="meta">Mappings: ${this.areaEntries.length} | mode: ${this.drawMode}</div>
125
139
  `;
126
140
  }
127
141
  }
@@ -270,6 +284,7 @@ _QtiSelectPointInteractionEdit_imageElement = new WeakMap(), _QtiSelectPointInte
270
284
  y: Math.max(0, Math.min(originalHeight, y)),
271
285
  };
272
286
  }, _QtiSelectPointInteractionEdit_onPointerDown = function _QtiSelectPointInteractionEdit_onPointerDown(event) {
287
+ this._cursorInside = true;
273
288
  if (!this.imageReady || !this.imageSrc)
274
289
  return;
275
290
  const point = __classPrivateFieldGet(this, _QtiSelectPointInteractionEdit_instances, "m", _QtiSelectPointInteractionEdit_toOriginalCoords).call(this, event.clientX, event.clientY);
@@ -618,6 +633,9 @@ QtiSelectPointInteractionEdit.styles = [
618
633
  __decorate([
619
634
  property({ type: String, attribute: 'area-mappings' })
620
635
  ], QtiSelectPointInteractionEdit.prototype, "areaMappings", void 0);
636
+ __decorate([
637
+ state()
638
+ ], QtiSelectPointInteractionEdit.prototype, "_cursorInside", void 0);
621
639
  __decorate([
622
640
  state()
623
641
  ], QtiSelectPointInteractionEdit.prototype, "drawMode", void 0);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qti-editor/interaction-select-point",
3
3
  "description": "QTI select-point interaction schemas, components, commands, and composer",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -17,14 +17,14 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@qti-components/select-point-interaction": "^1.0.1",
20
- "@qti-editor/interfaces": "0.1.0",
21
- "@qti-editor/interaction-shared": "0.1.0"
20
+ "@qti-editor/interaction-shared": "0.2.0",
21
+ "@qti-editor/interfaces": "0.2.0"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "lit": "^3.3.1"
25
25
  },
26
26
  "devDependencies": {
27
- "lit": "^3.3.1",
27
+ "lit": "^3.3.2",
28
28
  "prosemirror-model": "^1.25.4",
29
29
  "prosemirror-state": "^1.4.4"
30
30
  },