@jupytergis/base 0.13.0 → 0.13.1

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.
@@ -111,7 +111,7 @@ const Categorized = ({ model, okSignalPromise, layerId, symbologyTab, selectable
111
111
  renderType: 'Categorized',
112
112
  value: selectedAttributeRef.current,
113
113
  colorRamp: (_a = colorRampOptionsRef.current) === null || _a === void 0 ? void 0 : _a.selectedRamp,
114
- symbologyTab,
114
+ method: symbologyTab,
115
115
  reverse: reverseRamp,
116
116
  };
117
117
  saveSymbology({
@@ -68,6 +68,11 @@ export declare class BaseForm extends React.Component<IBaseFormProps, IBaseFormS
68
68
  constructor(props: IBaseFormProps);
69
69
  componentDidUpdate(prevProps: IBaseFormProps, prevState: IBaseFormStates): void;
70
70
  componentDidMount(): void;
71
+ /**
72
+ * Fills null/undefined values in data with schema defaults (mutates data).
73
+ * @returns true if any null/undefined was replaced by a default
74
+ */
75
+ protected applySchemaDefaults(data: IDict<any> | undefined, schema: RJSFSchema): boolean;
71
76
  protected processSchema(data: IDict<any> | undefined, schema: RJSFSchema, uiSchema: UiSchema): void;
72
77
  /**
73
78
  * Remove a specific entry from the form. Can be used in subclasses if needed while under processSchema.
@@ -30,10 +30,17 @@ const WrappedFormComponent = props => {
30
30
  */
31
31
  export class BaseForm extends React.Component {
32
32
  constructor(props) {
33
+ var _a;
33
34
  super(props);
34
35
  /** Skip syncData for the initial onChange (RJSF populating form), only sync on user edits. */
35
36
  this.isInitialLoadRef = true;
36
37
  this.currentFormData = deepCopy(this.props.sourceData);
38
+ if (props.schema) {
39
+ const applied = this.applySchemaDefaults(this.currentFormData, props.schema);
40
+ if (applied) {
41
+ props.syncData((_a = this.currentFormData) !== null && _a !== void 0 ? _a : {});
42
+ }
43
+ }
37
44
  this.state = {
38
45
  schema: props.schema,
39
46
  extraErrors: {},
@@ -42,9 +49,16 @@ export class BaseForm extends React.Component {
42
49
  componentDidUpdate(prevProps, prevState) {
43
50
  if (prevProps.sourceData !== this.props.sourceData) {
44
51
  this.currentFormData = deepCopy(this.props.sourceData);
52
+ // if (this.props.schema) {
53
+ // const applied = this.applySchemaDefaults(
54
+ // this.currentFormData,
55
+ // this.props.schema as RJSFSchema,
56
+ // );
57
+ // if (applied) {
58
+ // this.props.syncData(this.currentFormData ?? {});
59
+ // }
45
60
  const schema = deepCopy(this.props.schema);
46
61
  this.setState(old => (Object.assign(Object.assign({}, old), { schema })));
47
- this.isInitialLoadRef = true;
48
62
  }
49
63
  }
50
64
  componentDidMount() {
@@ -53,6 +67,43 @@ export class BaseForm extends React.Component {
53
67
  this.setState(old => (Object.assign(Object.assign({}, old), this.state.extraErrors)));
54
68
  this.props.formErrorSignal.emit(extraErrors);
55
69
  }
70
+ this.isInitialLoadRef = false;
71
+ }
72
+ /**
73
+ * Fills null/undefined values in data with schema defaults (mutates data).
74
+ * @returns true if any null/undefined was replaced by a default
75
+ */
76
+ applySchemaDefaults(data, schema) {
77
+ if (!data || !schema.properties) {
78
+ return false;
79
+ }
80
+ let applied = false;
81
+ const props = schema.properties;
82
+ for (const [key, propSchema] of Object.entries(props)) {
83
+ if (propSchema === null ||
84
+ propSchema === undefined ||
85
+ typeof propSchema !== 'object') {
86
+ continue;
87
+ }
88
+ const val = data[key];
89
+ if (val === null || val === undefined) {
90
+ if ('default' in propSchema &&
91
+ propSchema.default !== undefined) {
92
+ data[key] = deepCopy(propSchema.default);
93
+ applied = true;
94
+ }
95
+ }
96
+ else if (propSchema.type === 'object' &&
97
+ typeof val === 'object' &&
98
+ val !== null &&
99
+ !Array.isArray(val) &&
100
+ propSchema.properties) {
101
+ if (this.applySchemaDefaults(val, propSchema)) {
102
+ applied = true;
103
+ }
104
+ }
105
+ }
106
+ return applied;
56
107
  }
57
108
  processSchema(data, schema, uiSchema) {
58
109
  if (!schema['properties']) {
@@ -40,7 +40,7 @@ function LayerOverrideItem({ item, formContext }) {
40
40
  return (React.createElement("div", { className: "jGIS-symbology-override-item" },
41
41
  React.createElement("div", { style: { flex: 1 } }, item.children),
42
42
  React.createElement("div", { style: { display: 'flex', gap: '1rem' } },
43
- React.createElement(Button, { title: "Edit symbology override for the target layer", onClick: handleOpenSymbology, style: { width: '100%' }, disabled: !canOpenSymbology },
43
+ React.createElement(Button, { title: "Edit layer override for the target layer", onClick: handleOpenSymbology, style: { width: '100%' }, disabled: !canOpenSymbology },
44
44
  React.createElement("span", { className: "fa fa-brush", style: { marginRight: '4px' } }),
45
45
  "Edit Symbology"),
46
46
  item.hasRemove && (React.createElement(Button, { variant: "destructive", onClick: item.onDropIndexClick(item.index), title: "Remove item" }, "Remove")))));
@@ -55,5 +55,5 @@ export function ArrayFieldTemplate(props) {
55
55
  alignItems: 'center',
56
56
  } },
57
57
  props.items.map(item => (React.createElement(LayerOverrideItem, { key: item.key, item: item, formContext: props.formContext }))),
58
- props.canAdd && (React.createElement(Button, { onClick: props.onAddClick }, "Add Symbology Override")))));
58
+ props.canAdd && (React.createElement(Button, { onClick: props.onAddClick }, "Add Layer Override")))));
59
59
  }
@@ -15,9 +15,7 @@ export class GeoJSONSourcePropertiesForm extends PathBasedSourcePropertiesForm {
15
15
  this._validatePath((_b = (_a = props.sourceData) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : '');
16
16
  }
17
17
  processSchema(data, schema, uiSchema) {
18
- if ((data === null || data === void 0 ? void 0 : data.path) !== '') {
19
- this.removeFormEntry('data', data, schema, uiSchema);
20
- }
18
+ this.removeFormEntry('data', data, schema, uiSchema);
21
19
  if (this.props.formContext === 'create') {
22
20
  schema.properties.path.description =
23
21
  'The local path to a GeoJSON file. (If no path/url is provided, an empty GeoJSON is created.)';
@@ -28,7 +28,7 @@ const StoryViewerPanel = forwardRef(({ model, isSpecta, isMobile = false, classN
28
28
  model.setCurrentSegmentIndex(index);
29
29
  setCurrentIndexDisplayed(index);
30
30
  }, [model]);
31
- /** Layers affected by symbology override
31
+ /** Layers affected by layer override
32
32
  * We want to remove added layers (ie Heatmap)
33
33
  * and Restore the original symbology for modified layers
34
34
  */
@@ -209,7 +209,7 @@ const StoryViewerPanel = forwardRef(({ model, isSpecta, isMobile = false, classN
209
209
  model.sharedModel.awareness.off('change', handleSelectedStorySegmentChange);
210
210
  };
211
211
  }, [model, storyData, setIndex]);
212
- // Apply symbology overrides for the segment at the given index
212
+ // Apply layer overrides for the segment at the given index
213
213
  const overrideSymbology = (index) => {
214
214
  var _a;
215
215
  if (index < 0 || !storySegments[index]) {
@@ -220,7 +220,7 @@ const StoryViewerPanel = forwardRef(({ model, isSpecta, isMobile = false, classN
220
220
  if (!Array.isArray(layerOverrides)) {
221
221
  return;
222
222
  }
223
- // Apply all symbology overrides for this segment
223
+ // Apply all layer overrides for this segment
224
224
  layerOverrides.forEach(override => {
225
225
  const { color, opacity, symbologyState, targetLayer: targetLayerId, visible, } = override;
226
226
  if (!targetLayerId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupytergis/base",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "A JupyterLab extension for 3D modelling.",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -44,7 +44,7 @@
44
44
  "@jupyter/collaboration": "^4",
45
45
  "@jupyter/react-components": "^0.16.6",
46
46
  "@jupyter/ydoc": "^2.0.0 || ^3.0.0",
47
- "@jupytergis/schema": "^0.13.0",
47
+ "@jupytergis/schema": "^0.13.1",
48
48
  "@jupyterlab/application": "^4.3.0",
49
49
  "@jupyterlab/apputils": "^4.3.0",
50
50
  "@jupyterlab/completer": "^4.3.0",