@luomus/laji-form 15.1.17 → 15.1.19

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.
@@ -12,13 +12,13 @@ const ImageArrayField_1 = require("./ImageArrayField");
12
12
  const Spinner = require("react-spinner");
13
13
  const components_1 = require("../components");
14
14
  const ReactContext_1 = require("../../ReactContext");
15
- const FILE_TYPES = ["audio/mp3", "audio/mpeg", "audio/x-wav", "audio/wav", "audio/wave", "audio/vnd.wave"];
15
+ const FILE_TYPES = ["audio/mp3", "audio/mpeg", "audio/x-wav", "audio/wav", "audio/wave", "audio/vnd.wave", "audio/flac"];
16
16
  let AudioArrayField = class AudioArrayField extends React.Component {
17
17
  constructor() {
18
18
  super(...arguments);
19
19
  this.ALLOWED_FILE_TYPES = FILE_TYPES;
20
20
  this.ACCEPT_FILE_TYPES = ["audio/*"];
21
- this.MAX_FILE_SIZE = 20000000;
21
+ this.MAX_FILE_SIZE = 100000000;
22
22
  this.KEY = "AUDIO";
23
23
  this.ENDPOINT = "audio";
24
24
  this.GLYPH = "headphones";
@@ -81,10 +81,12 @@ const AudioButton = React.forwardRef((props, ref) => {
81
81
  const LajiAudio = React.forwardRef((props, ref) => {
82
82
  const [mp3Url, setMp3Url] = useState(null);
83
83
  const [wavUrl, setWavUrl] = useState(null);
84
+ const [flacUrl, setFlacUrl] = useState(null);
84
85
  useEffect(() => {
85
86
  props.apiClient.fetchCached(`/audio/${props.id}`, undefined, { failSilently: true }).then(response => {
86
87
  setMp3Url(response.mp3URL);
87
88
  setWavUrl(response.wavURL);
89
+ setFlacUrl(response.flacURL);
88
90
  props.onLoaded && props.onLoaded(true);
89
91
  });
90
92
  });
@@ -96,5 +98,9 @@ const LajiAudio = React.forwardRef((props, ref) => {
96
98
  wavUrl &&
97
99
  React.createElement(React.Fragment, null,
98
100
  " | ",
99
- React.createElement("a", { href: wavUrl, download: true }, `${props.translations.Download} wav`))))));
101
+ React.createElement("a", { href: wavUrl, download: true }, `${props.translations.Download} wav`)),
102
+ flacUrl &&
103
+ React.createElement(React.Fragment, null,
104
+ " | ",
105
+ React.createElement("a", { href: flacUrl, download: true }, `${props.translations.Download} flac`))))));
100
106
  });
@@ -5,6 +5,7 @@ export default class CombinedValueDisplayField extends React.Component<any, any,
5
5
  combined: PropTypes.Requireable<PropTypes.InferProps<{
6
6
  firstField: PropTypes.Validator<string>;
7
7
  secondField: PropTypes.Validator<string>;
8
+ additionalFields: PropTypes.Requireable<(string | null | undefined)[]>;
8
9
  name: PropTypes.Requireable<string>;
9
10
  title: PropTypes.Requireable<string>;
10
11
  combineType: PropTypes.Requireable<string>;
@@ -12,6 +13,7 @@ export default class CombinedValueDisplayField extends React.Component<any, any,
12
13
  }> | (PropTypes.InferProps<{
13
14
  firstField: PropTypes.Validator<string>;
14
15
  secondField: PropTypes.Validator<string>;
16
+ additionalFields: PropTypes.Requireable<(string | null | undefined)[]>;
15
17
  name: PropTypes.Requireable<string>;
16
18
  title: PropTypes.Requireable<string>;
17
19
  combineType: PropTypes.Requireable<string>;
@@ -34,7 +36,9 @@ export default class CombinedValueDisplayField extends React.Component<any, any,
34
36
  formData: any;
35
37
  onChange: (formData: any) => void;
36
38
  };
39
+ getFieldValue: (formData: any, field: any) => any;
37
40
  toMinutes: (time: any) => number;
41
+ getCount: (value: any) => number;
38
42
  onChange: (formData: any) => void;
39
43
  }
40
44
  import * as React from "react";
@@ -11,14 +11,16 @@ const PropTypes = require("prop-types");
11
11
  const utils_1 = require("../../utils");
12
12
  const VirtualSchemaField_1 = require("../VirtualSchemaField");
13
13
  /**
14
- * Combines values of two fields into one value which can be used for displaying (editing that value doesn't change formData)
14
+ * Combines values of two (or more) fields into one value which can be used for displaying (editing that value doesn't change formData)
15
15
  * Combine types:
16
16
  * timeDifference: combines the values by calculating their time difference
17
+ * totalCount: combines the values by summing their counts together. if the value is an array the count is its length and if it is a number the count is the value
17
18
  * stringJoin (default): combines the values by joining them. delimiter is added between if given
18
19
  */
19
20
  const combinedPropType = PropTypes.shape({
20
21
  firstField: PropTypes.string.isRequired,
21
22
  secondField: PropTypes.string.isRequired,
23
+ additionalFields: PropTypes.arrayOf(PropTypes.string),
22
24
  name: PropTypes.string,
23
25
  title: PropTypes.string,
24
26
  combineType: PropTypes.string,
@@ -27,10 +29,16 @@ const combinedPropType = PropTypes.shape({
27
29
  let CombinedValueDisplayField = class CombinedValueDisplayField extends React.Component {
28
30
  constructor() {
29
31
  super(...arguments);
32
+ this.getFieldValue = (formData, field) => {
33
+ return field[0] === "/" ? utils_1.parseJSONPointer(formData, field, !!"safely") : formData[field];
34
+ };
30
35
  this.toMinutes = (time) => {
31
36
  const parts = time.split(":");
32
37
  return Number(parts[0]) * 60 + Number(parts[1]);
33
38
  };
39
+ this.getCount = (value) => {
40
+ return Array.isArray(value) ? value.length : (typeof value === "number" ? value : 0);
41
+ };
34
42
  this.onChange = (formData) => {
35
43
  const uiOptions = this.getUiOptions();
36
44
  const combined = Array.isArray(uiOptions.combined) ? uiOptions.combined : [uiOptions.combined];
@@ -49,12 +57,14 @@ let CombinedValueDisplayField = class CombinedValueDisplayField extends React.Co
49
57
  let { schema, idSchema, formData } = props;
50
58
  const combined = Array.isArray(uiOptions.combined) ? uiOptions.combined : [uiOptions.combined];
51
59
  combined.forEach(options => {
52
- const { name, title, combineType, firstField, secondField } = options;
60
+ const { name, title, combineType, firstField, secondField, additionalFields = [] } = options;
53
61
  schema = Object.assign(Object.assign({}, schema), { properties: Object.assign(Object.assign({}, schema.properties), { [name || ""]: { title: title || "", type: "string" } }) });
54
62
  idSchema = this.props.registry.schemaUtils.toIdSchema(schema, idSchema.$id);
55
63
  let value = undefined;
56
- const firstValue = firstField[0] === "/" ? utils_1.parseJSONPointer(formData, firstField, !!"safely") : formData[firstField];
57
- const secondValue = secondField[0] === "/" ? utils_1.parseJSONPointer(formData, secondField, !!"safely") : formData[secondField];
64
+ const firstValue = this.getFieldValue(formData, firstField);
65
+ const secondValue = this.getFieldValue(formData, secondField);
66
+ const additionalValues = additionalFields.map(field => this.getFieldValue(formData, field));
67
+ const allValues = [firstValue, secondValue].concat(additionalValues);
58
68
  if (combineType === "timeDifference") {
59
69
  if (firstValue && secondValue) {
60
70
  const difference = this.toMinutes(secondValue) - this.toMinutes(formData[firstField]);
@@ -65,13 +75,17 @@ let CombinedValueDisplayField = class CombinedValueDisplayField extends React.Co
65
75
  }
66
76
  }
67
77
  }
78
+ else if (combineType === "totalCount") {
79
+ value = allValues.reduce((result, current) => result + this.getCount(current), 0);
80
+ }
68
81
  else {
69
82
  const delimiter = options.delimiter || "";
70
- value = [];
71
- if (firstValue)
72
- value.push(firstValue);
73
- if (secondValue)
74
- value.push(secondValue);
83
+ value = allValues.reduce((result, current) => {
84
+ if (current) {
85
+ result.push(current);
86
+ }
87
+ return result;
88
+ }, []);
75
89
  value = value.join(delimiter);
76
90
  }
77
91
  formData = Object.assign(Object.assign({}, formData), { [name]: value });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luomus/laji-form",
3
- "version": "15.1.17",
3
+ "version": "15.1.19",
4
4
  "description": "React module capable of building dynamic forms from Laji form json schemas",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",