@luomus/laji-form 15.1.102 → 15.1.104

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.
package/dist/styles.css CHANGED
@@ -3231,6 +3231,16 @@ body .laji-form {
3231
3231
  .laji-form .shortcut-help {
3232
3232
  bottom: 5px;
3233
3233
  }
3234
+ .laji-form-shortcut-keycombo-container {
3235
+ display: inline-flex;
3236
+ gap: 2px;
3237
+ }
3238
+ .laji-form-shortcut-keycombo-container span {
3239
+ background: #efefef;
3240
+ border: 1px solid #b1b1b3;
3241
+ border-radius: 2px;
3242
+ padding: 0px 3px;
3243
+ }
3234
3244
  .laji-form .hidden {
3235
3245
  display: none;
3236
3246
  }
@@ -1,6 +1,6 @@
1
1
  import { Translations } from "./components/LajiForm";
2
2
  import { Lang } from "./types";
3
- import type { paths } from "generated/api";
3
+ import type { paths } from "./generated/api";
4
4
  export declare class LajiApiError extends Error {
5
5
  statusCode: number;
6
6
  constructor(message: string, statusCode: number);
@@ -32,17 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __rest = (this && this.__rest) || function (s, e) {
36
- var t = {};
37
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
- t[p] = s[p];
39
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
- t[p[i]] = s[p[i]];
43
- }
44
- return t;
45
- };
46
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
47
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
48
37
  };
@@ -509,10 +498,6 @@ class LajiForm extends React.Component {
509
498
  const uiSchema = Object.assign(Object.assign({}, this.props.uiSchema), { "ui:submitButtonOptions": {
510
499
  norender: true
511
500
  } });
512
- const { Panel, Table } = this.getContext(this.props, this.context).theme;
513
- const panelHeader = (React.createElement("h3", null,
514
- translations.Shortcuts,
515
- React.createElement("button", { type: "button", className: "close pull-right", onClick: this.dismissHelp }, "\u00D7")));
516
501
  return (React.createElement(ReactContext_1.default.Provider, { value: this.getContext(this.props, this.context) },
517
502
  React.createElement("div", { className: "laji-form" },
518
503
  showShortcutsButton && this.props.showShortcutButton !== false && shortcuts && (React.createElement(components_1.TooltipComponent, { tooltip: this.getShorcutButtonTooltip() },
@@ -521,24 +506,7 @@ class LajiForm extends React.Component {
521
506
  React.createElement(core_1.default, Object.assign({}, this.props, { formData: this.state.formData, uiSchema: uiSchema, ref: this.formRef, onChange: this.onChange, onSubmit: this.onSubmit, fields: this.getFields(this.props.fields), widgets: this.getWidgets(this.props.widgets), templates: this.getTemplates(this.props.templates), formContext: this.state.formContext, validator: validator_ajv6_1.default, noValidate: true, extraErrors: this.state.extraErrors || {}, noHtml5Validate: true, liveValidate: true, autoComplete: "off", tagName: "div", readonly: readonly, disabled: disabled }), this.props.children),
522
507
  (!this.props.children && this.props.renderSubmit !== false) ? (React.createElement(components_1.Button, { id: "submit", onClick: this.submit, disabled: readonly || disabled }, this.props.submitText || translations.Submit)) : null,
523
508
  shortcuts &&
524
- React.createElement(Panel, { ref: this.shortcutHelpRef, className: "shortcut-help laji-form-popped z-depth-3 hidden", style: { top: (this.props.topOffset || 0) + 5, bottom: (this.props.bottomOffset || 0) + 5 }, variant: "info" },
525
- React.createElement(Panel.Heading, null, panelHeader),
526
- React.createElement(Table, null,
527
- React.createElement("tbody", { className: "well" }, Object.keys(shortcuts).map((keyCombo, idx) => {
528
- const _a = shortcuts[keyCombo], { fn, targetLabel, label } = _a, rest = __rest(_a, ["fn", "targetLabel", "label"]);
529
- if (["help", "autosuggestToggle"].includes(fn) || fn === "navigateSection" && rest.goOverRow)
530
- return;
531
- let translation = "";
532
- if (translation)
533
- translation = label;
534
- else
535
- translation = translations[[fn, ...Object.keys(rest)].map(utils_1.capitalizeFirstLetter).join("")];
536
- if (targetLabel)
537
- translation = `${translation} ${targetLabel}`;
538
- return (React.createElement("tr", { key: idx },
539
- React.createElement("td", null, (0, utils_1.stringifyKeyCombo)(keyCombo)),
540
- React.createElement("td", null, translation)));
541
- })))),
509
+ React.createElement(components_1.ShortcutsPanel, { ref: this.shortcutHelpRef, shortcuts: shortcuts, formContext: this.state.formContext, onClose: this.dismissHelp }),
542
510
  this.renderSubmitHooks())));
543
511
  }
544
512
  getSettings() {
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { ButtonProps as ThemedButtonProps } from "src/themes/theme";
2
+ import { ButtonProps as ThemedButtonProps } from "../../themes/theme";
3
3
  export type ButtonProps = ThemedButtonProps & {
4
4
  tooltip?: string;
5
5
  tooltipPlacement?: string;
@@ -0,0 +1,17 @@
1
+ import * as React from "react";
2
+ import { FormContext } from "../LajiForm";
3
+ type Action = {
4
+ fn: string;
5
+ targetLabel: string;
6
+ label: string;
7
+ goOverRow?: boolean;
8
+ };
9
+ type Props = {
10
+ formContext: FormContext;
11
+ onClose: (e: Event | React.SyntheticEvent) => void;
12
+ shortcuts: {
13
+ [keyCombo: string]: Action;
14
+ };
15
+ };
16
+ export declare const ShortcutsPanel: React.ForwardRefExoticComponent<Props & React.RefAttributes<unknown>>;
17
+ export {};
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __rest = (this && this.__rest) || function (s, e) {
36
+ var t = {};
37
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
+ t[p] = s[p];
39
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
+ t[p[i]] = s[p[i]];
43
+ }
44
+ return t;
45
+ };
46
+ var __importDefault = (this && this.__importDefault) || function (mod) {
47
+ return (mod && mod.__esModule) ? mod : { "default": mod };
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.ShortcutsPanel = void 0;
51
+ const React = __importStar(require("react"));
52
+ const utils_1 = require("../../utils");
53
+ const ReactContext_1 = __importDefault(require("../../ReactContext"));
54
+ const hash = (action) => JSON.stringify(action);
55
+ exports.ShortcutsPanel = React.forwardRef(({ formContext, onClose, shortcuts }, ref) => {
56
+ const { translations, topOffset = 0, bottomOffset = 0 } = formContext;
57
+ const { Panel, Table } = React.useContext(ReactContext_1.default).theme;
58
+ const actionsToShortcuts = Object.keys(shortcuts).reduce((actionsToShortcuts, keyCombo) => {
59
+ const action = shortcuts[keyCombo];
60
+ const hashedAction = hash(action);
61
+ const existing = actionsToShortcuts.find(item => hash(item.action) === hashedAction);
62
+ if (existing) {
63
+ existing.keyCombos.push(keyCombo);
64
+ }
65
+ actionsToShortcuts.push({ action, keyCombos: [keyCombo] });
66
+ return actionsToShortcuts;
67
+ }, []);
68
+ return (React.createElement(Panel, { ref: ref, className: "shortcut-help laji-form-popped z-depth-3 hidden", style: { top: topOffset + 5, bottom: bottomOffset + 5 }, variant: "info" },
69
+ React.createElement(Panel.Heading, null,
70
+ React.createElement("h3", null,
71
+ translations.Shortcuts,
72
+ React.createElement("button", { type: "button", className: "close pull-right", onClick: onClose }, "\u00D7"))),
73
+ React.createElement(Table, null,
74
+ React.createElement("tbody", { className: "well" }, actionsToShortcuts.map((props, i) => React.createElement(ShortcutVisualization, Object.assign({}, props, { key: i, translations: translations })))))));
75
+ });
76
+ const ShortcutVisualization = ({ action, keyCombos, translations }) => {
77
+ const { fn, targetLabel, label } = action, rest = __rest(action, ["fn", "targetLabel", "label"]);
78
+ if (["help", "autosuggestToggle"].includes(fn) || fn === "navigateSection" && rest.goOverRow) {
79
+ return null;
80
+ }
81
+ let translation = "";
82
+ if (translation) {
83
+ translation = label;
84
+ }
85
+ else {
86
+ translation = translations[[fn, ...Object.keys(rest)].map(utils_1.capitalizeFirstLetter).join("")];
87
+ }
88
+ if (targetLabel) {
89
+ translation = `${translation} ${targetLabel}`;
90
+ }
91
+ return (React.createElement("tr", null,
92
+ React.createElement("td", { className: "laji-form-shortcut-keycombo-container" }, keyCombos.map(keyCombo => React.createElement("span", null, (0, utils_1.stringifyKeyCombo)(keyCombo)))),
93
+ React.createElement("td", null, translation)));
94
+ };
@@ -11,3 +11,4 @@ export * from "./FetcherInput";
11
11
  export * from "./OverlayTrigger";
12
12
  export * from "./Fullscreen";
13
13
  export * from "./FailedBackgroundJobsPanel";
14
+ export * from "./ShortcutsPanel";
@@ -27,3 +27,4 @@ __exportStar(require("./FetcherInput"), exports);
27
27
  __exportStar(require("./OverlayTrigger"), exports);
28
28
  __exportStar(require("./Fullscreen"), exports);
29
29
  __exportStar(require("./FailedBackgroundJobsPanel"), exports);
30
+ __exportStar(require("./ShortcutsPanel"), exports);
@@ -1,5 +1,5 @@
1
1
  import * as PropTypes from "prop-types";
2
- import { FieldProps } from "src/types";
2
+ import { FieldProps } from "../../types";
3
3
  declare const _anyToBoolean: {
4
4
  (props: FieldProps): JSX.Element;
5
5
  propTypes: {
@@ -643,9 +643,9 @@ let LineTransectMapArrayField = class LineTransectMapArrayField extends React.Co
643
643
  formData = syncLineTransectStartEnd(formData);
644
644
  this.props.onChange(addOrDelete ? (0, ArrayField_1.onArrayFieldChange)(formData, this.props) : formData);
645
645
  }
646
- if ("activeIdx" in state) {
647
- this.afterActiveChange(state.activeIdx);
648
- }
646
+ // if ("activeIdx" in state) {
647
+ // this.afterActiveChange(state.activeIdx);
648
+ // }
649
649
  };
650
650
  Object.keys(state).length ? this.setState(state, afterState()) : afterState();
651
651
  };
@@ -672,18 +672,30 @@ let LineTransectMapArrayField = class LineTransectMapArrayField extends React.Co
672
672
  content = `${content}<br/>${translations.LineTransectSegmentNotCounted}`;
673
673
  return content;
674
674
  };
675
- this.focusOnMap = (idx) => {
675
+ this.focusOnMap = (idx, initialCall) => {
676
676
  if (!this.hasLineTransectFeature(this.props)) {
677
677
  setTimeout(() => this.map.zoomToData({ paddingInMeters: 200 }));
678
678
  return;
679
679
  }
680
680
  this.props.formContext.setTimeout(() => {
681
- this.map && this.map.fitBounds(L.featureGroup(this.map._corridorLayers[idx]).getBounds(), { paddingInMeters: 100 });
681
+ if (!this.map) {
682
+ return;
683
+ }
684
+ const bounds = L.featureGroup(this.map._corridorLayers[idx]).getBounds();
685
+ if (initialCall) {
686
+ this.map.fitBounds(bounds, { paddingInMeters: 100 });
687
+ }
688
+ else if (bounds.isValid()) {
689
+ this.map.map.panTo(bounds.getCenter());
690
+ }
682
691
  });
683
692
  };
684
693
  this.state = { showLTTools: false };
685
694
  this.props.onChange(syncLineTransectStartEnd(this.props.formData));
686
695
  }
696
+ componentDidMount() {
697
+ this.focusOnMap(this.state.idx);
698
+ }
687
699
  getOptions() {
688
700
  const { formData, disabled, readonly } = this.props;
689
701
  const { geometryField, placeholderGeometry } = (0, utils_2.getUiOptions)(this.props.uiSchema);
@@ -736,8 +748,8 @@ let LineTransectMapArrayField = class LineTransectMapArrayField extends React.Co
736
748
  }]
737
749
  };
738
750
  }
739
- afterActiveChange(idx) {
740
- this.focusOnMap(idx);
751
+ afterActiveChange(idx, initialCall) {
752
+ this.focusOnMap(idx, initialCall);
741
753
  }
742
754
  hasLineTransectFeature(props) {
743
755
  const { geometryField } = (0, utils_2.getUiOptions)(props.uiSchema);
@@ -1296,8 +1308,8 @@ function _MapArrayField(ComposedComponent) {
1296
1308
  this.afterActiveChange(this.state.activeIdx, !!"initial call");
1297
1309
  }
1298
1310
  }
1299
- afterActiveChange(idx) {
1300
- super.afterActiveChange && super.afterActiveChange(idx);
1311
+ afterActiveChange(idx, initialCall) {
1312
+ super.afterActiveChange && super.afterActiveChange(idx, initialCall);
1301
1313
  this.onLocateOrAddNew();
1302
1314
  }
1303
1315
  componentWillUnmount() {
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { FieldProps, JSONSchemaObject } from "src/types";
2
+ import { FieldProps, JSONSchemaObject } from "../../types";
3
3
  import * as PropTypes from "prop-types";
4
4
  interface State {
5
5
  activeIdx: number[];
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { ByLang, FormContext } from "../../LajiForm";
3
3
  import memoize from "memoizee";
4
- import type { components } from "generated/api.d";
4
+ import type { components } from "../../../generated/api.d";
5
5
  type NamedPlace = components["schemas"]["store-namedPlace"];
6
6
  type Props = {
7
7
  places: NamedPlace[];
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { FieldProps, JSONSchemaArray, JSONSchemaObject } from "../../../types";
3
- import type { components } from "generated/api.d";
3
+ import type { components } from "../../../generated/api.d";
4
4
  type NamedPlace = components["schemas"]["store-namedPlace"];
5
5
  type Props = FieldProps<NamedPlace, JSONSchemaObject | JSONSchemaArray<JSONSchemaObject>>;
6
6
  type State = {
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { FormContext } from "src/components/LajiForm";
3
- import type { components } from "generated/api.d";
3
+ import type { components } from "../../../generated/api.d";
4
4
  type NamedPlace = components["schemas"]["store-namedPlace"];
5
5
  type Props = {
6
6
  onPlaceSelected: (place: NamedPlace) => void;
@@ -1,5 +1,5 @@
1
1
  import * as PropTypes from "prop-types";
2
- import { FieldProps, WidgetProps } from "src/types";
2
+ import { FieldProps, WidgetProps } from "../../types";
3
3
  export declare const AnyToBoolean: (props: FieldProps | (WidgetProps & {
4
4
  widget: true;
5
5
  })) => JSX.Element;