mirador-annotation-editor-video 1.0.94 → 1.0.95

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.
@@ -25,9 +25,9 @@ const TEMPLATE = exports.TEMPLATE = {
25
25
  IMAGE_TYPE: 'image',
26
26
  KONVA_TYPE: 'konva',
27
27
  MANIFEST_TYPE: 'manifest',
28
+ MULTIPLE_BODY_TYPE: 'multiple_body',
28
29
  TAGGING_TYPE: 'tagging',
29
- TEXT_TYPE: 'text',
30
- MULTIPLE_BODY_TYPE: 'multiple_body'
30
+ TEXT_TYPE: 'text'
31
31
  };
32
32
  const MEDIA_TYPES = exports.MEDIA_TYPES = {
33
33
  AUDIO: 'Audio',
@@ -43,8 +43,7 @@ const getTemplateType = (t, templateType) => TEMPLATE_TYPES(t).find(type => type
43
43
  */
44
44
  exports.getTemplateType = getTemplateType;
45
45
  const TEMPLATE_TYPES = t => [{
46
- description: t('MultiBodyTemplate'),
47
- // TODO
46
+ description: t('textual_note_with_target'),
48
47
  icon: /*#__PURE__*/_react.default.createElement(_TextFields.default, null),
49
48
  id: TEMPLATE.MULTIPLE_BODY_TYPE,
50
49
  isCompatibleWithTemplate: mediaType => {
@@ -53,14 +52,14 @@ const TEMPLATE_TYPES = t => [{
53
52
  if (mediaType === MEDIA_TYPES.AUDIO) return false;
54
53
  return false;
55
54
  },
56
- label: t('MultiBodyTemplate') // TODO
55
+ label: t('note')
57
56
  }, {
58
57
  description: t('textual_note_with_target'),
59
58
  icon: /*#__PURE__*/_react.default.createElement(_TextFields.default, null),
60
59
  id: TEMPLATE.TEXT_TYPE,
61
60
  isCompatibleWithTemplate: mediaType => {
62
- if (mediaType === MEDIA_TYPES.VIDEO) return true;
63
- if (mediaType === MEDIA_TYPES.IMAGE) return true;
61
+ if (mediaType === MEDIA_TYPES.VIDEO) return false;
62
+ if (mediaType === MEDIA_TYPES.IMAGE) return false;
64
63
  if (mediaType === MEDIA_TYPES.AUDIO) return false;
65
64
  return false;
66
65
  },
@@ -72,9 +71,9 @@ const TEMPLATE_TYPES = t => [{
72
71
  }),
73
72
  id: TEMPLATE.TAGGING_TYPE,
74
73
  isCompatibleWithTemplate: mediaType => {
75
- if (mediaType === MEDIA_TYPES.VIDEO) return true;
76
- if (mediaType === MEDIA_TYPES.IMAGE) return true;
77
- if (mediaType === MEDIA_TYPES.AUDIO) return true;
74
+ if (mediaType === MEDIA_TYPES.VIDEO) return false;
75
+ if (mediaType === MEDIA_TYPES.IMAGE) return false;
76
+ if (mediaType === MEDIA_TYPES.AUDIO) return false;
78
77
  return false;
79
78
  },
80
79
  label: t('tag')
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.MultiTagsInput = MultiTagsInput;
7
- var _react = _interopRequireDefault(require("react"));
7
+ var _react = _interopRequireWildcard(require("react"));
8
8
  var _reactTagInput = require("react-tag-input");
9
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
10
10
  var _material = require("@mui/material");
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
14
  /**
13
15
  * MultiTagsInput component
14
16
  * @param t
@@ -24,6 +26,12 @@ function MultiTagsInput({
24
26
  tags,
25
27
  tagsSuggestions
26
28
  }) {
29
+ const [showSuggestions, setShowSuggestions] = (0, _react.useState)(false);
30
+ const mappedSuggestionsTags = tagsSuggestions.map(suggestion => ({
31
+ id: suggestion,
32
+ text: suggestion
33
+ }));
34
+
27
35
  /**
28
36
  * Handle tag deletion
29
37
  * @param index
@@ -47,8 +55,10 @@ function MultiTagsInput({
47
55
  * Handle tag addition
48
56
  * @param tag
49
57
  */
50
- const handleAddition = tag => {
51
- setTags([...tags, tag]);
58
+ const handleAddition = newTag => {
59
+ if (tags.length === 0 || !tags.find(tag => tag.id === newTag.id)) {
60
+ setTags([...tags, newTag]);
61
+ }
52
62
  };
53
63
 
54
64
  /**
@@ -82,7 +92,32 @@ function MultiTagsInput({
82
92
  };
83
93
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_material.Typography, {
84
94
  variant: "formSectionTitle"
85
- }, t('tags')), /*#__PURE__*/_react.default.createElement(_reactTagInput.WithContext, {
95
+ }, t('tags')), /*#__PURE__*/_react.default.createElement(_material.FormControlLabel, {
96
+ control: /*#__PURE__*/_react.default.createElement(_material.Switch, {
97
+ value: showSuggestions,
98
+ onClick: () => setShowSuggestions(!showSuggestions)
99
+ }),
100
+ label: "Suggestion"
101
+ }), showSuggestions && /*#__PURE__*/_react.default.createElement("div", {
102
+ style: {
103
+ display: 'flex',
104
+ flexWrap: 'wrap',
105
+ gap: '8px'
106
+ }
107
+ }, mappedSuggestionsTags.map(suggestion => /*#__PURE__*/_react.default.createElement("button", {
108
+ key: suggestion.id,
109
+ type: "button",
110
+ onClick: () => handleAddition(suggestion),
111
+ style: {
112
+ padding: '6px 12px',
113
+ borderRadius: '16px',
114
+ border: '1px solid #ccc',
115
+ backgroundColor: '#f1f1f1',
116
+ cursor: 'pointer'
117
+ }
118
+ }, suggestion.text))), /*#__PURE__*/_react.default.createElement(_material.Divider, {
119
+ spacing: 2
120
+ }), /*#__PURE__*/_react.default.createElement(_reactTagInput.WithContext, {
86
121
  placeholder: t('pressEnterToAddTag'),
87
122
  clearAll: true,
88
123
  editable: true,
@@ -94,10 +129,9 @@ function MultiTagsInput({
94
129
  onClearAll: onClearAll,
95
130
  onTagUpdate: onTagUpdate,
96
131
  tags: tags,
97
- suggestions: tagsSuggestions.map(suggestion => ({
98
- id: suggestion,
99
- text: suggestion
100
- }))
132
+ suggestions: mappedSuggestionsTags,
133
+ minQueryLength: 1,
134
+ autocomplete: true
101
135
  }));
102
136
  }
103
137
  MultiTagsInput.propTypes = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mirador-annotation-editor-video",
3
- "version": "1.0.94",
3
+ "version": "1.0.95",
4
4
  "description": "Mirador annotation editor video plugin in a React component. Mirador 4 (Alpha 2) compatible ",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",
@@ -15,9 +15,9 @@ export const TEMPLATE = {
15
15
  IMAGE_TYPE: 'image',
16
16
  KONVA_TYPE: 'konva',
17
17
  MANIFEST_TYPE: 'manifest',
18
+ MULTIPLE_BODY_TYPE: 'multiple_body',
18
19
  TAGGING_TYPE: 'tagging',
19
20
  TEXT_TYPE: 'text',
20
- MULTIPLE_BODY_TYPE: 'multiple_body',
21
21
  };
22
22
 
23
23
  export const MEDIA_TYPES = {
@@ -37,7 +37,7 @@ export const getTemplateType = (t, templateType) => TEMPLATE_TYPES(t)
37
37
  */
38
38
  export const TEMPLATE_TYPES = (t) => [
39
39
  {
40
- description: t('MultiBodyTemplate'), // TODO
40
+ description: t('textual_note_with_target'),
41
41
  icon: <TextFieldsIcon />,
42
42
  id: TEMPLATE.MULTIPLE_BODY_TYPE,
43
43
  isCompatibleWithTemplate: (mediaType) => {
@@ -46,15 +46,15 @@ export const TEMPLATE_TYPES = (t) => [
46
46
  if (mediaType === MEDIA_TYPES.AUDIO) return false;
47
47
  return false;
48
48
  },
49
- label: t('MultiBodyTemplate'), // TODO
49
+ label: t('note'),
50
50
  },
51
51
  {
52
52
  description: t('textual_note_with_target'),
53
53
  icon: <TextFieldsIcon />,
54
54
  id: TEMPLATE.TEXT_TYPE,
55
55
  isCompatibleWithTemplate: (mediaType) => {
56
- if (mediaType === MEDIA_TYPES.VIDEO) return true;
57
- if (mediaType === MEDIA_TYPES.IMAGE) return true;
56
+ if (mediaType === MEDIA_TYPES.VIDEO) return false;
57
+ if (mediaType === MEDIA_TYPES.IMAGE) return false;
58
58
  if (mediaType === MEDIA_TYPES.AUDIO) return false;
59
59
  return false;
60
60
  },
@@ -65,9 +65,9 @@ export const TEMPLATE_TYPES = (t) => [
65
65
  icon: <LocalOfferIcon fontSize="small" />,
66
66
  id: TEMPLATE.TAGGING_TYPE,
67
67
  isCompatibleWithTemplate: (mediaType) => {
68
- if (mediaType === MEDIA_TYPES.VIDEO) return true;
69
- if (mediaType === MEDIA_TYPES.IMAGE) return true;
70
- if (mediaType === MEDIA_TYPES.AUDIO) return true;
68
+ if (mediaType === MEDIA_TYPES.VIDEO) return false;
69
+ if (mediaType === MEDIA_TYPES.IMAGE) return false;
70
+ if (mediaType === MEDIA_TYPES.AUDIO) return false;
71
71
  return false;
72
72
  },
73
73
  label: t('tag'),
@@ -1,7 +1,9 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { WithContext as ReactTags } from 'react-tag-input';
3
3
  import PropTypes from 'prop-types';
4
- import { Typography } from '@mui/material';
4
+ import {
5
+ Divider, FormControlLabel, Switch, Typography,
6
+ } from '@mui/material';
5
7
 
6
8
  /**
7
9
  * MultiTagsInput component
@@ -18,6 +20,13 @@ export function MultiTagsInput({
18
20
  tags,
19
21
  tagsSuggestions,
20
22
  }) {
23
+ const [showSuggestions, setShowSuggestions] = useState(false);
24
+
25
+ const mappedSuggestionsTags = tagsSuggestions.map((suggestion) => ({
26
+ id: suggestion,
27
+ text: suggestion,
28
+ }));
29
+
21
30
  /**
22
31
  * Handle tag deletion
23
32
  * @param index
@@ -41,8 +50,10 @@ export function MultiTagsInput({
41
50
  * Handle tag addition
42
51
  * @param tag
43
52
  */
44
- const handleAddition = (tag) => {
45
- setTags([...tags, tag]);
53
+ const handleAddition = (newTag) => {
54
+ if (tags.length === 0 || !tags.find((tag) => tag.id === newTag.id)) {
55
+ setTags([...tags, newTag]);
56
+ }
46
57
  };
47
58
 
48
59
  /**
@@ -81,6 +92,50 @@ export function MultiTagsInput({
81
92
  <Typography variant="formSectionTitle">
82
93
  {t('tags')}
83
94
  </Typography>
95
+ {/* Show list of suggestions into a clickable tag */}
96
+ {/* add a toggle to show hide suggestions */}
97
+
98
+ <FormControlLabel
99
+ control={(
100
+ <Switch
101
+ value={showSuggestions}
102
+ onClick={() => setShowSuggestions(!showSuggestions)}
103
+ />
104
+ )}
105
+ label="Suggestion"
106
+ />
107
+ {
108
+ showSuggestions
109
+ && (
110
+ <div style={{
111
+ display: 'flex',
112
+ flexWrap: 'wrap',
113
+ gap: '8px',
114
+ }}
115
+ >
116
+ {mappedSuggestionsTags.map((suggestion) => (
117
+ <button
118
+ key={suggestion.id}
119
+ type="button"
120
+ onClick={() => handleAddition(suggestion)}
121
+ style={{
122
+ padding: '6px 12px',
123
+ borderRadius: '16px',
124
+ border: '1px solid #ccc',
125
+ backgroundColor: '#f1f1f1',
126
+ cursor: 'pointer',
127
+ }}
128
+ >
129
+ {suggestion.text}
130
+ </button>
131
+ ))}
132
+ </div>
133
+ )
134
+ }
135
+ <Divider
136
+ spacing={2}
137
+ />
138
+
84
139
  <ReactTags
85
140
  placeholder={t('pressEnterToAddTag')}
86
141
  clearAll
@@ -93,10 +148,9 @@ export function MultiTagsInput({
93
148
  onClearAll={onClearAll}
94
149
  onTagUpdate={onTagUpdate}
95
150
  tags={tags}
96
- suggestions={tagsSuggestions.map((suggestion) => ({
97
- id: suggestion,
98
- text: suggestion,
99
- }))}
151
+ suggestions={mappedSuggestionsTags}
152
+ minQueryLength={1}
153
+ autocomplete
100
154
  />
101
155
  </>
102
156
  );