@entryscape/rdforms 10.11.1 → 10.12.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.
@@ -16,15 +16,21 @@ const choicify = func => (fieldDiv, binding, context) => {
16
16
  return;
17
17
  }
18
18
 
19
+ const locale = context.view.getLocale();
20
+
19
21
  if (isEditor && choice.editdescription) {
20
- desc = utils.getLocalizedValue(choice.editdescription).value;
22
+ desc = utils.getLocalizedValue(choice.editdescription, locale).value;
21
23
  } else if (choice.description) {
22
- desc = utils.getLocalizedValue(choice.description).value;
24
+ desc = utils.getLocalizedValue(choice.description, locale).value;
23
25
  }
24
26
 
25
- func(fieldDiv, binding, choice, desc, isEditor);
27
+ func(fieldDiv, binding, choice, desc, isEditor, locale);
26
28
  };
27
29
 
30
+ const getLocalizedLabel = (choice, isEditor, locale) =>
31
+ utils.getLocalizedValue(isEditor ? choice.editlabel || choice.label : choice.label, locale);
32
+
33
+
28
34
  // Presenter for image.
29
35
  presenters.itemtype('choice').style('image').register(choicify(
30
36
  (fieldDiv, binding, choice, desc) => {
@@ -40,27 +46,24 @@ presenters.itemtype('choice').style('stars').register(choicify(
40
46
  }
41
47
  }));
42
48
 
43
- const getLocalizedLabel = (choice, isEditor) =>
44
- utils.getLocalizedValue(isEditor ? choice.editlabel || choice.label : choice.label);
45
-
46
49
  // Presenter for choices.
47
50
  presenters.itemtype('choice').register(choicify(
48
- (fieldDiv, binding, choice, desc, isEditor) => {
51
+ (fieldDiv, binding, choice, desc, isEditor, locale) => {
49
52
  const item = binding.getItem();
50
53
  const title = desc || choice.seeAlso || choice.value;
51
54
  if ((item.hasStaticChoices() && !item.hasStyle('externalLink')) || item.hasStyle('noLink')) {
52
55
  fieldDiv.appendChild(React.createElement(() => {
53
- const [locValue, setLocValue] = useState(getLocalizedLabel(choice, isEditor));
56
+ const [locValue, setLocValue] = useState(getLocalizedLabel(choice, isEditor, locale));
54
57
  useEffect(() => {
55
58
  if (choice.load != null) {
56
59
  choice.load(() => {
57
- setLocValue(getLocalizedLabel(choice, isEditor));
60
+ setLocValue(getLocalizedLabel(choice, isEditor, locale));
58
61
  });
59
62
  }
60
63
  }, []);
61
64
  const langAttr = locValue.lang ? {lang: locValue.lang} : {};
62
65
  return <div key={binding.getHash()} {...langAttr} title={title}>{locValue.value}</div>
63
- }));
66
+ }, {key: binding.getHash()}));
64
67
  } else {
65
68
  let attrs;
66
69
  if (item.hasStyle('externalLink')) {
@@ -72,11 +75,11 @@ presenters.itemtype('choice').register(choicify(
72
75
  delete attrs.component;
73
76
 
74
77
  fieldDiv.appendChild(React.createElement(() => {
75
- const [locValue, setLocValue] = useState(getLocalizedLabel(choice, isEditor));
78
+ const [locValue, setLocValue] = useState(getLocalizedLabel(choice, isEditor, locale));
76
79
  useEffect(() => {
77
80
  if (choice.load != null) {
78
81
  choice.load(() => {
79
- setLocValue(getLocalizedLabel(choice, isEditor));
82
+ setLocValue(getLocalizedLabel(choice, isEditor, locale));
80
83
  });
81
84
  }
82
85
  }, []);
@@ -49,7 +49,7 @@ export default (props) => {
49
49
  }
50
50
  globalChoiceQueryThrottle = setTimeout(() => {
51
51
  globalChoiceQueryThrottle = undefined;
52
- props.context.chooser.search(binding.getItem(), inputValue.trimStart()).then((results) => {
52
+ props.context.chooser.search(binding, inputValue.trimStart()).then((results) => {
53
53
  if (active) {
54
54
  setOptions(results.map(editLocalizedChoice));
55
55
  }
@@ -5,6 +5,7 @@ import RadioGroup from '@mui/material/RadioGroup';
5
5
  import FormControlLabel from '@mui/material/FormControlLabel';
6
6
  import FormControl from '@mui/material/FormControl';
7
7
  import { useLocalizedSortedChoices, useName, useNamedGraphId } from '../hooks';
8
+ import utils from '../../../utils';
8
9
 
9
10
  const ChoiceOption = props => <FormControlLabel
10
11
  disabled={props.disabled}
@@ -48,13 +49,15 @@ export default function RadioButtonsEditor(props) {
48
49
  }, []);
49
50
 
50
51
  const ngId = useNamedGraphId(binding, props.context);
52
+ let labelMap = item.getEditLabelMap() || item.getLabelMap();
53
+ let label = utils.getLocalizedValue(labelMap, props.context.view.getLocale()).value
51
54
  return (
52
55
  <>
53
56
  <FormControl component="fieldset">
54
57
  <RadioGroup
55
58
  {...row}
56
59
  key="radio"
57
- aria-label={item.getEditLabel() || item.getLabel()}
60
+ aria-label={label}
58
61
  name={name}
59
62
  value={value}
60
63
  onChange={handleChange}
@@ -32,7 +32,7 @@ const getDatatypeFromBinding = (binding, alternatives) => {
32
32
 
33
33
  const datePresenter = (fieldDiv, binding, context) => {
34
34
  try {
35
- const pres = getDatePresentation(binding);
35
+ const pres = getDatePresentation(binding, context.view.getLocale());
36
36
  fieldDiv.appendChild(<div key={binding.getHash()} >{pres}</div>);
37
37
  } catch (e) {
38
38
  console.warn(`Could not present date, expected ISO8601 format in the form 2001-01-01
@@ -4,6 +4,7 @@ import Tooltip, { tooltipClasses } from '@mui/material/Tooltip';
4
4
  import { styled } from '@mui/material/styles';
5
5
  import ClickAwayListener from '@mui/material/ClickAwayListener';
6
6
  import renderingContext from '../renderingContext';
7
+ import utils from '../../utils';
7
8
  import { Editor } from './Wrappers';
8
9
  import CODES from '../../model/CODES';
9
10
 
@@ -38,9 +39,10 @@ const ItemTooltip = (props) => {
38
39
  if (property) {
39
40
  propinfo = <div className="rdformsProperty"><a target="_blank" href={property}>{property}</a></div>;
40
41
  }
41
- const description = props.context.view instanceof Editor ?
42
- props.item.getEditDescription() || props.item.getDescription() : props.item.getDescription()
42
+ const descriptionMap = props.context.view instanceof Editor ?
43
+ props.item.getEditDescriptionMap() || props.item.getDescriptionMap() : props.item.getDescriptionMap()
43
44
  || (property ? '' : props.context.view.messages.info_missing || '');
45
+ const description = utils.getLocalizedValue(descriptionMap, props.context.view.getLocale()).value
44
46
 
45
47
  return (
46
48
  <ClickAwayListener onClickAway={handleTooltipClose}>
@@ -67,8 +69,9 @@ const ItemTooltip = (props) => {
67
69
  };
68
70
 
69
71
  renderingContext.renderPresenterLabel = (rowNode, binding, item, context) => {
70
- let label = context.view instanceof Editor ?
71
- item.getEditLabel() || item.getLabel() : item.getLabel();
72
+ let labelMap = context.view instanceof Editor ?
73
+ item.getEditLabelMap() || item.getLabelMap() : item.getLabelMap();
74
+ let label = utils.getLocalizedValue(labelMap, context.view.getLocale()).value
72
75
  if (label != null && label !== '') {
73
76
  label = label.charAt(0).toUpperCase() + label.slice(1);
74
77
  } else {
@@ -85,8 +88,9 @@ renderingContext.renderPresenterLabel = (rowNode, binding, item, context) => {
85
88
  (view.compact && !item.hasStyle('nonCompact') && (
86
89
  (view.topLevel && item.getType() !== 'group') ||
87
90
  (view.parentView && view.parentView.topLevel && view.binding.getItem().hasStyle('heading'))));
88
- const desc = view instanceof Editor ? item.getEditDescription() || item.getDescription() :
89
- item.getDescription();
91
+ const descMap = view instanceof Editor ? item.getEditDescriptionMap() || item.getDescriptionMap() :
92
+ item.getDescriptionMap();
93
+ const desc = utils.getLocalizedValue(descMap, context.view.getLocale()).value;
90
94
  if (!compactField && desc) {
91
95
  description = <div className="rdformsDescription" tabIndex="0">{desc}</div>;
92
96
  }
@@ -104,7 +108,8 @@ renderingContext.renderEditorLabel = (rowNode, binding, item, context) => {
104
108
  if (item.hasStyle('nonEditable') || item.hasStyle('heading')) {
105
109
  renderingContext.renderPresenterLabel(rowNode, binding, item, context, true);
106
110
  } else {
107
- let label = item.getEditLabel() || item.getLabel();
111
+ let labelMap = item.getEditLabelMap() || item.getLabelMap();
112
+ let label = utils.getLocalizedValue(labelMap, context.view.getLocale()).value
108
113
  if (label != null && label !== '') {
109
114
  label = label.charAt(0).toUpperCase() + label.slice(1);
110
115
  } else {
@@ -147,8 +152,10 @@ renderingContext.renderEditorLabel = (rowNode, binding, item, context) => {
147
152
  (view.compact && !item.hasStyle('nonCompact') && (
148
153
  (view.topLevel && item.getType() !== 'group') ||
149
154
  (view.parentView && view.parentView.topLevel && view.binding.getItem().hasStyle('heading'))));
150
- const desc = view instanceof Editor ? item.getEditDescription() || item.getDescription() :
151
- item.getDescription();
155
+ const descMap = view instanceof Editor ? item.getEditDescriptionMap() || item.getDescriptionMap() :
156
+ item.getDescriptionMap();
157
+ const desc = utils.getLocalizedValue(descMap, context.view.getLocale()).value
158
+
152
159
  if (!compactField && desc) {
153
160
  description = <div className="rdformsDescription" tabIndex="0">{desc}</div>;
154
161
  }
@@ -1,4 +1,5 @@
1
1
  import renderingContext from '../renderingContext';
2
+ import utils from '../../utils';
2
3
  import jquery from 'jquery';
3
4
 
4
5
  renderingContext.addPresenterTable = (newRow, firstBinding, context) => {
@@ -9,7 +10,8 @@ renderingContext.addPresenterTable = (newRow, firstBinding, context) => {
9
10
  const $tHeadRow = jquery('<tr>').appendTo($table);
10
11
  for (let colInd = 0; colInd < childItems.length; colInd++) {
11
12
  const $th = jquery('<th>').appendTo($tHeadRow);
12
- renderingContext.attachItemInfo(item, jquery('<span>').text(childItems[colInd].getLabel()).appendTo($th), context);
13
+ let label = utils.getLocalizedValue(childItems[colInd].getLabelMap(), context.view.getLocale()).value
14
+ renderingContext.attachItemInfo(item, jquery('<span>').text(label).appendTo($th), context);
13
15
  }
14
16
  return $table[0];
15
17
  };
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable no-unused-vars */
2
2
  import React, { useState, useEffect, useMemo } from 'react';
3
- import moment from 'moment';
4
3
  import system from '../../model/system';
5
4
  import renderingContext from '../renderingContext';
6
5
  import { fromDuration } from '../viewUtils';
@@ -41,12 +40,12 @@ presenters.itemtype('group').nodetype('URI').style('linkWithLabel').register((fi
41
40
  delete attrs.component;
42
41
  const labelItem = binding.getItem().getChildren().find(i => i.hasStyle('label'));
43
42
  const labelBindings = labelItem ?
44
- renderingContext.filterTranslations(binding.getChildBindingsFor(labelItem), moment.locale(),
43
+ renderingContext.filterTranslations(binding.getChildBindingsFor(labelItem), context.view.getLocale(),
45
44
  context.view.defaultLanguage) : [];
46
45
 
47
46
  const tooltipItem = binding.getItem().getChildren().find(i => i.hasStyle('tooltip'));
48
47
  const tooltipBindings = tooltipItem ?
49
- renderingContext.filterTranslations(binding.getChildBindingsFor(tooltipItem), moment.locale(),
48
+ renderingContext.filterTranslations(binding.getChildBindingsFor(tooltipItem), context.view.getLocale(),
50
49
  context.view.defaultLanguage) : [];
51
50
  const tooltip = tooltipBindings.length > 0 ? tooltipBindings[0].getValue() : val;
52
51
 
@@ -7,7 +7,6 @@ import IconButton from '@mui/material/IconButton';
7
7
  import MenuItem from '@mui/material/MenuItem';
8
8
  import FormControl from '@mui/material/FormControl';
9
9
  import Select from '@mui/material/Select';
10
- import moment from 'moment';
11
10
  import renderingContext from '../renderingContext';
12
11
  import utils from '../../utils';
13
12
  import { useNamedGraphId } from './hooks';
@@ -21,7 +20,7 @@ const LanguageControl = (props) => {
21
20
  });
22
21
  useEffect(() => {
23
22
  if (!props.binding.isValid()) {
24
- const defLang = moment.locale();
23
+ const defLang = props.context.view.getDefaultTextLanguage();
25
24
  if (typeof defLang === 'string' && defLang !== '') {
26
25
  setLang(defLang);
27
26
  props.binding.setLanguage(defLang, true);
@@ -142,20 +142,20 @@ export const getDateValue = (value, datatype) => {
142
142
  return '';
143
143
  };
144
144
 
145
- export const getDatePresentationFromDatatype = (datatype, date) => {
145
+ export const getDatePresentationFromDatatype = (datatype, date, locale) => {
146
146
  switch (datatype) {
147
147
  case 'DateTime':
148
- return moment(date).format('lll');
148
+ return moment(date).locale(locale).format('lll');
149
149
  case 'Date':
150
- return moment(date).format('LL');
150
+ return moment(date).locale(locale).format('LL');
151
151
  case 'Time':
152
- return moment(date).format('LT');
152
+ return moment(date).locale(locale).format('LT');
153
153
  case 'Year':
154
- return moment(date).format('YYYY');
154
+ return moment(date).locale(locale).format('YYYY');
155
155
  case 'YearMonth':
156
- return moment(date).format('MMMM YYYY');
156
+ return moment(date).locale(locale).format('MMMM YYYY');
157
157
  case 'MonthDay':
158
- return moment(date).format('D MMMM');
158
+ return moment(date).locale(locale).format('D MMMM');
159
159
  default:
160
160
  return '';
161
161
  }
@@ -174,7 +174,7 @@ export const getAllowedDateAlternatives = (item) => {
174
174
  return dateAllowedDataAlternatives;
175
175
  };
176
176
 
177
- export const getDatePresentation = (binding) => {
177
+ export const getDatePresentation = (binding, locale) => {
178
178
  const data = binding.getValue();
179
179
  if (data != null && data !== '') {
180
180
  const item = binding.getItem();
@@ -195,7 +195,7 @@ export const getDatePresentation = (binding) => {
195
195
  // Rely on the datatype from the item if everything else fails
196
196
  datatype = itemSuggestedDatatype;
197
197
  }
198
- return getDatePresentationFromDatatype(datatype, date);
198
+ return getDatePresentationFromDatatype(datatype, date, locale);
199
199
  }
200
200
  }
201
201
  return undefined;