@selfcommunity/react-ui 0.7.0-alpha.357 → 0.7.0-alpha.358

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,7 +16,7 @@ export interface AttributesProps extends Omit<BoxProps, 'value' | 'onChange' | '
16
16
  * @param value
17
17
  * @default empty object
18
18
  */
19
- onClick?: (attribute: 'categories' | 'addressing') => void;
19
+ onClick?: (attribute: 'categories' | 'addressing' | 'location') => void;
20
20
  }
21
21
  declare const _default: (props: AttributesProps) => JSX.Element;
22
22
  export default _default;
@@ -32,10 +32,16 @@ exports.default = (props) => {
32
32
  const handleClickTag = (0, react_1.useCallback)(() => {
33
33
  onClick && onClick('addressing');
34
34
  }, [onClick]);
35
+ const handleDeleteLocation = (0, react_1.useCallback)(() => {
36
+ onChange && onChange(Object.assign(Object.assign({}, value), { location: null }));
37
+ }, [value, onChange]);
38
+ const handleClickLocation = (0, react_1.useCallback)(() => {
39
+ onClick && onClick('location');
40
+ }, [onClick]);
35
41
  return (react_1.default.createElement(Root, { className: (0, classnames_1.default)(classes.root, className) },
36
42
  ((_a = value === null || value === void 0 ? void 0 : value.categories) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
37
43
  (value === null || value === void 0 ? void 0 : value.categories.map((c) => (react_1.default.createElement(material_1.Chip, { key: c.id, label: c.name, onDelete: handleDeleteCategory(c.id), icon: react_1.default.createElement(Icon_1.default, null, "category"), onClick: handleClickCategory })))),
38
44
  ((_b = value === null || value === void 0 ? void 0 : value.addressing) === null || _b === void 0 ? void 0 : _b.length) > 0 &&
39
45
  (value === null || value === void 0 ? void 0 : value.addressing.map((t) => (react_1.default.createElement(TagChip_1.default, { key: t.id, tag: t, onDelete: handleDeleteTag(t.id), icon: react_1.default.createElement(Icon_1.default, null, "label"), onClick: handleClickTag })))),
40
- (value === null || value === void 0 ? void 0 : value.location) && (react_1.default.createElement(material_1.Chip, { icon: react_1.default.createElement(Icon_1.default, null, "add_location_alt"), label: value === null || value === void 0 ? void 0 : value.location.location, onDelete: () => null, onClick: () => null }))));
46
+ (value === null || value === void 0 ? void 0 : value.location) && (react_1.default.createElement(material_1.Chip, { icon: react_1.default.createElement(Icon_1.default, null, "add_location_alt"), label: value === null || value === void 0 ? void 0 : value.location.location, onDelete: handleDeleteLocation, onClick: handleClickLocation }))));
41
47
  };
@@ -342,8 +342,11 @@ function Composer(inProps) {
342
342
  case 'addressing':
343
343
  handleAddAudienceLayer();
344
344
  break;
345
+ case 'location':
346
+ handleAddLocationLayer();
347
+ break;
345
348
  }
346
- }, [handleAddCategoryLayer, handleAddAudienceLayer]);
349
+ }, [handleAddCategoryLayer, handleAddAudienceLayer, handleAddLocationLayer]);
347
350
  const handleSubmit = (0, react_1.useCallback)((event) => {
348
351
  event.preventDefault();
349
352
  event.stopPropagation();
@@ -476,7 +479,7 @@ function Composer(inProps) {
476
479
  react_1.default.createElement(material_1.IconButton, { disabled: isSubmitting, onClick: handleAddCategoryLayer },
477
480
  react_1.default.createElement(Icon_1.default, null, "category")),
478
481
  react_1.default.createElement(material_1.IconButton, { disabled: isSubmitting || !features.includes(types_1.SCFeatureName.TAGGING), onClick: handleAddAudienceLayer }, addressing === null || addressing.length === 0 ? react_1.default.createElement(Icon_1.default, null, "public") : react_1.default.createElement(Icon_1.default, null, "label")),
479
- preferences[react_core_1.SCPreferences.ADDONS_POST_GEOLOCATION_ENABLED] && (react_1.default.createElement(material_1.IconButton, { disabled: isSubmitting, onClick: handleAddLocationLayer, color: location !== null ? 'primary' : 'default' },
482
+ preferences[react_core_1.SCPreferences.ADDONS_POST_GEOLOCATION_ENABLED].value && (react_1.default.createElement(material_1.IconButton, { disabled: isSubmitting, onClick: handleAddLocationLayer, color: location !== null ? 'primary' : 'default' },
480
483
  react_1.default.createElement(Icon_1.default, null, "add_location_alt"))))),
481
484
  layer && react_1.default.createElement(LayerTransitionRoot, { className: classes.layerTransitionRoot, in: true, container: dialogRef.current, direction: "left" },
482
485
  react_1.default.createElement(layer.Component, Object.assign({}, layer.ComponentProps)))));
@@ -88,16 +88,22 @@ function LocationAutocomplete(inProps) {
88
88
  }, [value]);
89
89
  // Handlers
90
90
  const handleChange = (event, value) => {
91
- setValue({ location: value.full_address, lat: value.lat, lon: value.lng });
91
+ setValue(value ? { location: value.full_address, lat: value.lat, lon: value.lng } : null);
92
92
  onChange && onChange(value);
93
93
  };
94
94
  const handleSearch = (event, _search) => {
95
95
  setSearch(_search);
96
96
  };
97
97
  // Render
98
- return (react_1.default.createElement(Root, Object.assign({ className: classes.root, options: locations || [],
98
+ const options = (0, react_1.useMemo)(() => {
99
+ if (!value || typeof value === 'string' || locations.find((loc) => value.lat === loc.lat && value.lon === loc.lng)) {
100
+ return locations;
101
+ }
102
+ return [...locations, { lat: value.lat, lng: value.lon, full_address: value.location }];
103
+ }, [value, locations]);
104
+ return (react_1.default.createElement(Root, Object.assign({ className: classes.root, options: options || [],
99
105
  // @ts-ignore
100
- getOptionLabel: (option) => (option === null || option === void 0 ? void 0 : option.full_address) || (option === null || option === void 0 ? void 0 : option.location) || '', filterOptions: (x) => x, autoComplete: true, includeInputInList: true, filterSelectedOptions: true, value: value, selectOnFocus: true, handleHomeEndKeys: true, disabled: disabled, noOptionsText: react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.locationAutocomplete.empty", defaultMessage: "ui.locationAutocomplete.empty" }), onChange: handleChange, onInputChange: handleSearch, isOptionEqualToValue: (option, value) => value.lat === option.lat && value.lon === option.lng, renderInput: (params) => {
106
+ getOptionLabel: (option) => (option === null || option === void 0 ? void 0 : option.full_address) || (option === null || option === void 0 ? void 0 : option.location) || '', filterOptions: (x) => x, autoComplete: true, includeInputInList: true, value: value || null, selectOnFocus: true, handleHomeEndKeys: true, disabled: disabled, noOptionsText: react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.locationAutocomplete.empty", defaultMessage: "ui.locationAutocomplete.empty" }), onChange: handleChange, onInputChange: handleSearch, isOptionEqualToValue: (option, value) => value.lat === option.lat && value.lon === option.lng, renderInput: (params) => {
101
107
  return (react_1.default.createElement(TextField_1.default, Object.assign({}, params, TextFieldProps, { margin: "dense", InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'location', endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
102
108
  isLoading ? react_1.default.createElement(CircularProgress_1.default, { color: "inherit", size: 20 }) : null,
103
109
  params.InputProps.endAdornment)) }) })));
@@ -10,9 +10,11 @@ const react_sortablejs_1 = require("react-sortablejs");
10
10
  const DisplayComponent_1 = tslib_1.__importDefault(require("./DisplayComponent"));
11
11
  const constants_1 = require("./constants");
12
12
  const filter_1 = tslib_1.__importDefault(require("./filter"));
13
+ const Media_1 = require("../../../constants/Media");
13
14
  const classes = {
14
15
  previewRoot: `${constants_1.PREFIX}-preview-root`,
15
16
  media: `${constants_1.PREFIX}-media`,
17
+ video: `${constants_1.PREFIX}-media-video`,
16
18
  delete: `${constants_1.PREFIX}-delete`
17
19
  };
18
20
  const Root = (0, styles_1.styled)(material_1.Box, {
@@ -29,7 +31,7 @@ const PreviewComponent = react_1.default.forwardRef((props, ref) => {
29
31
  onChange && onChange([...value.filter((media) => medias.findIndex((m) => m.id === media.id) === -1), ...medias]);
30
32
  }, [onChange, value]);
31
33
  const handleDelete = (0, react_1.useCallback)((id) => () => onChange && onChange(value.filter((media) => media.id !== id)), [onChange, value]);
32
- return react_1.default.createElement(Root, Object.assign({ ref: ref, className: (0, classnames_1.default)(className, classes.previewRoot) }, rest), medias.length > 0 && (react_1.default.createElement(react_sortablejs_1.ReactSortable, { list: medias, setList: handleSort }, medias.map((media) => (react_1.default.createElement(material_1.Box, { key: media.id, className: classes.media },
34
+ return react_1.default.createElement(Root, Object.assign({ ref: ref, className: (0, classnames_1.default)(className, classes.previewRoot) }, rest), medias.length > 0 && (react_1.default.createElement(react_sortablejs_1.ReactSortable, { list: medias, setList: handleSort }, medias.map((media) => (react_1.default.createElement(material_1.Box, { key: media.id, className: (0, classnames_1.default)(classes.media, { [classes.video]: media.embed.metadata && media.embed.metadata.type === Media_1.MEDIA_TYPE_VIDEO }) },
33
35
  react_1.default.createElement(DisplayComponent_1.default, { medias: [media] }),
34
36
  react_1.default.createElement(material_1.IconButton, { className: classes.delete, onClick: handleDelete(media.id), size: "small" },
35
37
  react_1.default.createElement(Icon_1.default, null, "delete"))))))));
@@ -16,7 +16,7 @@ export interface AttributesProps extends Omit<BoxProps, 'value' | 'onChange' | '
16
16
  * @param value
17
17
  * @default empty object
18
18
  */
19
- onClick?: (attribute: 'categories' | 'addressing') => void;
19
+ onClick?: (attribute: 'categories' | 'addressing' | 'location') => void;
20
20
  }
21
21
  declare const _default: (props: AttributesProps) => JSX.Element;
22
22
  export default _default;
@@ -29,10 +29,16 @@ export default (props) => {
29
29
  const handleClickTag = useCallback(() => {
30
30
  onClick && onClick('addressing');
31
31
  }, [onClick]);
32
+ const handleDeleteLocation = useCallback(() => {
33
+ onChange && onChange(Object.assign(Object.assign({}, value), { location: null }));
34
+ }, [value, onChange]);
35
+ const handleClickLocation = useCallback(() => {
36
+ onClick && onClick('location');
37
+ }, [onClick]);
32
38
  return (React.createElement(Root, { className: classNames(classes.root, className) },
33
39
  ((_a = value === null || value === void 0 ? void 0 : value.categories) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
34
40
  (value === null || value === void 0 ? void 0 : value.categories.map((c) => (React.createElement(Chip, { key: c.id, label: c.name, onDelete: handleDeleteCategory(c.id), icon: React.createElement(Icon, null, "category"), onClick: handleClickCategory })))),
35
41
  ((_b = value === null || value === void 0 ? void 0 : value.addressing) === null || _b === void 0 ? void 0 : _b.length) > 0 &&
36
42
  (value === null || value === void 0 ? void 0 : value.addressing.map((t) => (React.createElement(TagChip, { key: t.id, tag: t, onDelete: handleDeleteTag(t.id), icon: React.createElement(Icon, null, "label"), onClick: handleClickTag })))),
37
- (value === null || value === void 0 ? void 0 : value.location) && (React.createElement(Chip, { icon: React.createElement(Icon, null, "add_location_alt"), label: value === null || value === void 0 ? void 0 : value.location.location, onDelete: () => null, onClick: () => null }))));
43
+ (value === null || value === void 0 ? void 0 : value.location) && (React.createElement(Chip, { icon: React.createElement(Icon, null, "add_location_alt"), label: value === null || value === void 0 ? void 0 : value.location.location, onDelete: handleDeleteLocation, onClick: handleClickLocation }))));
38
44
  };
@@ -340,8 +340,11 @@ export default function Composer(inProps) {
340
340
  case 'addressing':
341
341
  handleAddAudienceLayer();
342
342
  break;
343
+ case 'location':
344
+ handleAddLocationLayer();
345
+ break;
343
346
  }
344
- }, [handleAddCategoryLayer, handleAddAudienceLayer]);
347
+ }, [handleAddCategoryLayer, handleAddAudienceLayer, handleAddLocationLayer]);
345
348
  const handleSubmit = useCallback((event) => {
346
349
  event.preventDefault();
347
350
  event.stopPropagation();
@@ -474,7 +477,7 @@ export default function Composer(inProps) {
474
477
  React.createElement(IconButton, { disabled: isSubmitting, onClick: handleAddCategoryLayer },
475
478
  React.createElement(Icon, null, "category")),
476
479
  React.createElement(IconButton, { disabled: isSubmitting || !features.includes(SCFeatureName.TAGGING), onClick: handleAddAudienceLayer }, addressing === null || addressing.length === 0 ? React.createElement(Icon, null, "public") : React.createElement(Icon, null, "label")),
477
- preferences[SCPreferences.ADDONS_POST_GEOLOCATION_ENABLED] && (React.createElement(IconButton, { disabled: isSubmitting, onClick: handleAddLocationLayer, color: location !== null ? 'primary' : 'default' },
480
+ preferences[SCPreferences.ADDONS_POST_GEOLOCATION_ENABLED].value && (React.createElement(IconButton, { disabled: isSubmitting, onClick: handleAddLocationLayer, color: location !== null ? 'primary' : 'default' },
478
481
  React.createElement(Icon, null, "add_location_alt"))))),
479
482
  layer && React.createElement(LayerTransitionRoot, { className: classes.layerTransitionRoot, in: true, container: dialogRef.current, direction: "left" },
480
483
  React.createElement(layer.Component, Object.assign({}, layer.ComponentProps)))));
@@ -1,5 +1,5 @@
1
1
  import { __rest } from "tslib";
2
- import React, { useEffect, useState } from 'react';
2
+ import React, { useEffect, useMemo, useState } from 'react';
3
3
  import { FormattedMessage } from 'react-intl';
4
4
  import TextField from '@mui/material/TextField';
5
5
  import CircularProgress from '@mui/material/CircularProgress';
@@ -86,16 +86,22 @@ export default function LocationAutocomplete(inProps) {
86
86
  }, [value]);
87
87
  // Handlers
88
88
  const handleChange = (event, value) => {
89
- setValue({ location: value.full_address, lat: value.lat, lon: value.lng });
89
+ setValue(value ? { location: value.full_address, lat: value.lat, lon: value.lng } : null);
90
90
  onChange && onChange(value);
91
91
  };
92
92
  const handleSearch = (event, _search) => {
93
93
  setSearch(_search);
94
94
  };
95
95
  // Render
96
- return (React.createElement(Root, Object.assign({ className: classes.root, options: locations || [],
96
+ const options = useMemo(() => {
97
+ if (!value || typeof value === 'string' || locations.find((loc) => value.lat === loc.lat && value.lon === loc.lng)) {
98
+ return locations;
99
+ }
100
+ return [...locations, { lat: value.lat, lng: value.lon, full_address: value.location }];
101
+ }, [value, locations]);
102
+ return (React.createElement(Root, Object.assign({ className: classes.root, options: options || [],
97
103
  // @ts-ignore
98
- getOptionLabel: (option) => (option === null || option === void 0 ? void 0 : option.full_address) || (option === null || option === void 0 ? void 0 : option.location) || '', filterOptions: (x) => x, autoComplete: true, includeInputInList: true, filterSelectedOptions: true, value: value, selectOnFocus: true, handleHomeEndKeys: true, disabled: disabled, noOptionsText: React.createElement(FormattedMessage, { id: "ui.locationAutocomplete.empty", defaultMessage: "ui.locationAutocomplete.empty" }), onChange: handleChange, onInputChange: handleSearch, isOptionEqualToValue: (option, value) => value.lat === option.lat && value.lon === option.lng, renderInput: (params) => {
104
+ getOptionLabel: (option) => (option === null || option === void 0 ? void 0 : option.full_address) || (option === null || option === void 0 ? void 0 : option.location) || '', filterOptions: (x) => x, autoComplete: true, includeInputInList: true, value: value || null, selectOnFocus: true, handleHomeEndKeys: true, disabled: disabled, noOptionsText: React.createElement(FormattedMessage, { id: "ui.locationAutocomplete.empty", defaultMessage: "ui.locationAutocomplete.empty" }), onChange: handleChange, onInputChange: handleSearch, isOptionEqualToValue: (option, value) => value.lat === option.lat && value.lon === option.lng, renderInput: (params) => {
99
105
  return (React.createElement(TextField, Object.assign({}, params, TextFieldProps, { margin: "dense", InputProps: Object.assign(Object.assign({}, params.InputProps), { autoComplete: 'location', endAdornment: (React.createElement(React.Fragment, null,
100
106
  isLoading ? React.createElement(CircularProgress, { color: "inherit", size: 20 }) : null,
101
107
  params.InputProps.endAdornment)) }) })));
@@ -8,9 +8,11 @@ import { ReactSortable } from 'react-sortablejs';
8
8
  import DisplayComponent from './DisplayComponent';
9
9
  import { PREFIX } from './constants';
10
10
  import filter from './filter';
11
+ import { MEDIA_TYPE_VIDEO } from '../../../constants/Media';
11
12
  const classes = {
12
13
  previewRoot: `${PREFIX}-preview-root`,
13
14
  media: `${PREFIX}-media`,
15
+ video: `${PREFIX}-media-video`,
14
16
  delete: `${PREFIX}-delete`
15
17
  };
16
18
  const Root = styled(Box, {
@@ -27,7 +29,7 @@ const PreviewComponent = React.forwardRef((props, ref) => {
27
29
  onChange && onChange([...value.filter((media) => medias.findIndex((m) => m.id === media.id) === -1), ...medias]);
28
30
  }, [onChange, value]);
29
31
  const handleDelete = useCallback((id) => () => onChange && onChange(value.filter((media) => media.id !== id)), [onChange, value]);
30
- return React.createElement(Root, Object.assign({ ref: ref, className: classNames(className, classes.previewRoot) }, rest), medias.length > 0 && (React.createElement(ReactSortable, { list: medias, setList: handleSort }, medias.map((media) => (React.createElement(Box, { key: media.id, className: classes.media },
32
+ return React.createElement(Root, Object.assign({ ref: ref, className: classNames(className, classes.previewRoot) }, rest), medias.length > 0 && (React.createElement(ReactSortable, { list: medias, setList: handleSort }, medias.map((media) => (React.createElement(Box, { key: media.id, className: classNames(classes.media, { [classes.video]: media.embed.metadata && media.embed.metadata.type === MEDIA_TYPE_VIDEO }) },
31
33
  React.createElement(DisplayComponent, { medias: [media] }),
32
34
  React.createElement(IconButton, { className: classes.delete, onClick: handleDelete(media.id), size: "small" },
33
35
  React.createElement(Icon, null, "delete"))))))));