diff --git a/.changeset/empty-camels-pay.md b/.changeset/empty-camels-pay.md new file mode 100644 index 00000000..205d9f63 --- /dev/null +++ b/.changeset/empty-camels-pay.md @@ -0,0 +1,5 @@ +--- +"@feltmaps/js-sdk": minor +--- + +Add feature actions diff --git a/docs/Main/FeltController.md b/docs/Main/FeltController.md index 4133bfd9..4b646247 100644 --- a/docs/Main/FeltController.md +++ b/docs/Main/FeltController.md @@ -1749,6 +1749,96 @@ await felt.deleteActionTrigger("enablePolygonTool"); *** +## createFeatureAction() + +> **createFeatureAction**(`args`: [`CreateFeatureActionParams`](../UI/CreateFeatureActionParams.md)): `Promise`\<[`uiFeatureAction`](../UI/uiFeatureAction.md)> + +Creates a feature contextual action. + +### Parameters + +| Parameter | Type | Description | +| --------- | ----------------------------------------------------------------- | ----------------------------- | +| `args` | [`CreateFeatureActionParams`](../UI/CreateFeatureActionParams.md) | The arguments for the method. | + +### Returns + +`Promise`\<[`uiFeatureAction`](../UI/uiFeatureAction.md)> + +### Example + +```typescript +const myAction = await felt.createFeatureAction({ + action: { + label: "Edit feature", + onTrigger: async ({ featureId, layerId }) => { + console.log(`Editing feature ${featureId} in layer ${layerId}`); + }, + layerIds: ["layer-1", "layer-2"], + }, + placement: { at: "start" }, // optional, defaults to { at: "end" } +}); +``` + +*** + +## updateFeatureAction() + +> **updateFeatureAction**(`args`: [`UpdateFeatureActionParams`](../UI/UpdateFeatureActionParams.md)): `Promise`\<[`uiFeatureAction`](../UI/uiFeatureAction.md)> + +Updates a feature contextual action. + +Feature contextual action to update is identified by the `id` property. + +### Parameters + +| Parameter | Type | Description | +| --------- | ----------------------------------------------------------------- | ---------------------------------------- | +| `args` | [`UpdateFeatureActionParams`](../UI/UpdateFeatureActionParams.md) | The feature contextual action to update. | + +### Returns + +`Promise`\<[`uiFeatureAction`](../UI/uiFeatureAction.md)> + +### Remarks + +Properties provided will override the existing properties. + +### Example + +```typescript +await felt.updateFeatureAction({ + id: "my-action", + label: "Updated action label", // only label changes +}); +``` + +*** + +## deleteFeatureAction() + +> **deleteFeatureAction**(`id`: `string`): `void` + +Deletes a feature contextual action. + +### Parameters + +| Parameter | Type | Description | +| --------- | -------- | -------------------------------------------------- | +| `id` | `string` | The id of the feature contextual action to delete. | + +### Returns + +`void` + +### Example + +```typescript +await felt.deleteFeatureAction("my-action"); +``` + +*** + ## createPanelId() > **createPanelId**(): `Promise`\<`string`> diff --git a/docs/UI/CreateFeatureActionParams.md b/docs/UI/CreateFeatureActionParams.md new file mode 100644 index 00000000..1ac7a1ce --- /dev/null +++ b/docs/UI/CreateFeatureActionParams.md @@ -0,0 +1,13 @@ +*** + +# Properties + +## action + +> **action**: [`uiFeatureActionCreate`](uiFeatureActionCreate.md) + +*** + +## placement? + +> `optional` **placement**: \{ `after`: `string`; } | \{ `before`: `string`; } | \{ `at`: `"start"` | `"end"`; } diff --git a/docs/UI/README.md b/docs/UI/README.md index 420e59e3..7a457afd 100644 --- a/docs/UI/README.md +++ b/docs/UI/README.md @@ -11,6 +11,8 @@ UI features such as the legend and the full screen button. * [CreateActionTriggerParams](CreateActionTriggerParams.md) * [UpdateActionTriggerParams](UpdateActionTriggerParams.md) +* [CreateFeatureActionParams](CreateFeatureActionParams.md) +* [UpdateFeatureActionParams](UpdateFeatureActionParams.md) * [CreateOrUpdatePanelParams](CreateOrUpdatePanelParams.md) * [CreatePanelElementsParams](CreatePanelElementsParams.md) * [UpdatePanelElementsParams](UpdatePanelElementsParams.md) @@ -30,6 +32,7 @@ UI features such as the legend and the full screen button. * [UIDividerElement](UIDividerElement.md) * [UIDividerElementCreate](UIDividerElementCreate.md) * [UIDividerElementUpdate](UIDividerElementUpdate.md) +* [uiFeatureActionCreate](uiFeatureActionCreate.md) * [UIFlexibleSpaceElement](UIFlexibleSpaceElement.md) * [UIFlexibleSpaceElementCreate](UIFlexibleSpaceElementCreate.md) * [UIFlexibleSpaceElementUpdate](UIFlexibleSpaceElementUpdate.md) @@ -60,6 +63,7 @@ UI features such as the legend and the full screen button. # Type Aliases +* [uiFeatureAction](uiFeatureAction.md) * [PlacementForUIElement](PlacementForUIElement.md) * [UIPanelElement](UIPanelElement.md) * [UIPanelElementCreate](UIPanelElementCreate.md) diff --git a/docs/UI/UiController.md b/docs/UI/UiController.md index 2a3f2ea5..6a9f3868 100644 --- a/docs/UI/UiController.md +++ b/docs/UI/UiController.md @@ -107,6 +107,96 @@ await felt.deleteActionTrigger("enablePolygonTool"); *** +## createFeatureAction() + +> **createFeatureAction**(`args`: [`CreateFeatureActionParams`](CreateFeatureActionParams.md)): `Promise`\<[`uiFeatureAction`](uiFeatureAction.md)> + +Creates a feature contextual action. + +### Parameters + +| Parameter | Type | Description | +| --------- | ----------------------------------------------------------- | ----------------------------- | +| `args` | [`CreateFeatureActionParams`](CreateFeatureActionParams.md) | The arguments for the method. | + +### Returns + +`Promise`\<[`uiFeatureAction`](uiFeatureAction.md)> + +### Example + +```typescript +const myAction = await felt.createFeatureAction({ + action: { + label: "Edit feature", + onTrigger: async ({ featureId, layerId }) => { + console.log(`Editing feature ${featureId} in layer ${layerId}`); + }, + layerIds: ["layer-1", "layer-2"], + }, + placement: { at: "start" }, // optional, defaults to { at: "end" } +}); +``` + +*** + +## updateFeatureAction() + +> **updateFeatureAction**(`args`: [`UpdateFeatureActionParams`](UpdateFeatureActionParams.md)): `Promise`\<[`uiFeatureAction`](uiFeatureAction.md)> + +Updates a feature contextual action. + +Feature contextual action to update is identified by the `id` property. + +### Parameters + +| Parameter | Type | Description | +| --------- | ----------------------------------------------------------- | ---------------------------------------- | +| `args` | [`UpdateFeatureActionParams`](UpdateFeatureActionParams.md) | The feature contextual action to update. | + +### Returns + +`Promise`\<[`uiFeatureAction`](uiFeatureAction.md)> + +### Remarks + +Properties provided will override the existing properties. + +### Example + +```typescript +await felt.updateFeatureAction({ + id: "my-action", + label: "Updated action label", // only label changes +}); +``` + +*** + +## deleteFeatureAction() + +> **deleteFeatureAction**(`id`: `string`): `void` + +Deletes a feature contextual action. + +### Parameters + +| Parameter | Type | Description | +| --------- | -------- | -------------------------------------------------- | +| `id` | `string` | The id of the feature contextual action to delete. | + +### Returns + +`void` + +### Example + +```typescript +await felt.deleteFeatureAction("my-action"); +``` + +*** + ## createPanelId() > **createPanelId**(): `Promise`\<`string`> diff --git a/docs/UI/UpdateFeatureActionParams.md b/docs/UI/UpdateFeatureActionParams.md new file mode 100644 index 00000000..af8e1bdf --- /dev/null +++ b/docs/UI/UpdateFeatureActionParams.md @@ -0,0 +1,42 @@ +*** + +# Properties + +## id + +> **id**: `string` + +*** + +## label? + +> `optional` **label**: `string` + +*** + +## layerIds? + +> `optional` **layerIds**: `string`\[] + +*** + +## geometryTypes? + +> `optional` **geometryTypes**: (`"Polygon"` | `"Point"` | `"Line"` | `"Raster"`)\[] + +*** + +## onTrigger()? + +> `optional` **onTrigger**: (`args`: \{ `feature`: [`LayerFeature`](../Layers/LayerFeature.md); }) => `void` + +### Parameters + +| Parameter | Type | +| -------------- | ------------------------------------------------------------ | +| `args` | \{ `feature`: [`LayerFeature`](../Layers/LayerFeature.md); } | +| `args.feature` | [`LayerFeature`](../Layers/LayerFeature.md) | + +### Returns + +`void` diff --git a/docs/UI/uiFeatureAction.md b/docs/UI/uiFeatureAction.md new file mode 100644 index 00000000..5d1258eb --- /dev/null +++ b/docs/UI/uiFeatureAction.md @@ -0,0 +1,38 @@ +*** + +> **uiFeatureAction**: \{ `id`: `string`; `label`: `string`; `onTrigger`: (`args`: \{ `feature`: [`LayerFeature`](../Layers/LayerFeature.md); }) => `void`; `layerIds`: `string`\[]; `geometryTypes`: (`"Polygon"` | `"Point"` | `"Line"` | `"Raster"`)\[]; } + +Represents a feature action after creation (with generated id). + +# Type declaration + +## id + +> **id**: `string` + +## label + +> **label**: `string` + +## onTrigger() + +> **onTrigger**: (`args`: \{ `feature`: [`LayerFeature`](../Layers/LayerFeature.md); }) => `void` + +### Parameters + +| Parameter | Type | +| -------------- | ------------------------------------------------------------ | +| `args` | \{ `feature`: [`LayerFeature`](../Layers/LayerFeature.md); } | +| `args.feature` | [`LayerFeature`](../Layers/LayerFeature.md) | + +### Returns + +`void` + +## layerIds? + +> `optional` **layerIds**: `string`\[] + +## geometryTypes? + +> `optional` **geometryTypes**: (`"Polygon"` | `"Point"` | `"Line"` | `"Raster"`)\[] diff --git a/docs/UI/uiFeatureActionCreate.md b/docs/UI/uiFeatureActionCreate.md new file mode 100644 index 00000000..9318786f --- /dev/null +++ b/docs/UI/uiFeatureActionCreate.md @@ -0,0 +1,97 @@ +*** + +Represents a feature action for creation. +It can be added to the map by using the [UiController.createFeatureAction](UiController.md#createfeatureaction) method. + +# Properties + +## label + +> **label**: `string` + +The label of the feature action. + +*** + +## onTrigger() + +> **onTrigger**: (`args`: \{ `feature`: [`LayerFeature`](../Layers/LayerFeature.md); }) => `void` + +The function to call when the feature action is triggered. + +### Parameters + +| Parameter | Type | Description | +| -------------- | ------------------------------------------------------------ | -------------------------------------- | +| `args` | \{ `feature`: [`LayerFeature`](../Layers/LayerFeature.md); } | The arguments passed to the function. | +| `args.feature` | [`LayerFeature`](../Layers/LayerFeature.md) | The feature that triggered the action. | + +### Returns + +`void` + +*** + +## id? + +> `optional` **id**: `string` + +*** + +## layerIds? + +> `optional` **layerIds**: `string`\[] + +The layers to add the action to. Optional. Defaults to all layers. + +*** + +## geometryTypes? + +> `optional` **geometryTypes**: (`"Polygon"` | `"Point"` | `"Line"` | `"Raster"`)\[] + +The geometry type of the features to add the action to. Optional. Defaults to all geometry types. + +*** + +## type? + +> `optional` **type**: `undefined` + +*** + +## onCreate()? + +> `optional` **onCreate**: (`args`: \{ `id`: `string`; }) => `void` + +A function to call when the element is created. + +### Parameters + +| Parameter | Type | Description | +| --------- | -------------------- | ------------------------------------- | +| `args` | \{ `id`: `string`; } | The arguments passed to the function. | +| `args.id` | `string` | The id of the element. | + +### Returns + +`void` + +*** + +## onDestroy()? + +> `optional` **onDestroy**: (`args`: \{ `id`: `string`; }) => `void` + +A function to call when the element is destroyed. + +### Parameters + +| Parameter | Type | Description | +| --------- | -------------------- | ------------------------------------- | +| `args` | \{ `id`: `string`; } | The arguments passed to the function. | +| `args.id` | `string` | The id of the element. | + +### Returns + +`void` diff --git a/etc/js-sdk.api.md b/etc/js-sdk.api.md index fc434b97..5d02e792 100644 --- a/etc/js-sdk.api.md +++ b/etc/js-sdk.api.md @@ -4,207 +4,211 @@ ```ts -import { av as AggregatedGridConfig } from './controller-DItYvwe0.js'; -import { aw as AggregationConfig } from './controller-DItYvwe0.js'; -import { ax as AggregationMethod } from './controller-DItYvwe0.js'; -import { C as CircleElementCreate } from './controller-DItYvwe0.js'; -import { a as CircleElementRead } from './controller-DItYvwe0.js'; -import { b as CircleElementUpdate } from './controller-DItYvwe0.js'; -import { b9 as CircleToolSettings } from './controller-DItYvwe0.js'; -import { ba as ConfigurableToolType } from './controller-DItYvwe0.js'; -import { ay as CountGridConfig } from './controller-DItYvwe0.js'; -import { bq as CreateActionTriggerParams } from './controller-DItYvwe0.js'; -import { K as CreateLayersFromGeoJsonParams } from './controller-DItYvwe0.js'; -import { br as CreateOrUpdatePanelParams } from './controller-DItYvwe0.js'; -import { bs as CreatePanelElementsParams } from './controller-DItYvwe0.js'; -import { O as DataOnlyLayer } from './controller-DItYvwe0.js'; -import { bt as DeletePanelElementsParams } from './controller-DItYvwe0.js'; -import { E as Element_2 } from './controller-DItYvwe0.js'; -import { c as ElementChangeCallbackParams } from './controller-DItYvwe0.js'; -import { d as ElementCreate } from './controller-DItYvwe0.js'; -import { e as ElementGroup } from './controller-DItYvwe0.js'; -import { f as ElementGroupChangeCallbackParams } from './controller-DItYvwe0.js'; -import { aN as ElementGroupNode } from './controller-DItYvwe0.js'; -import { aO as ElementNode } from './controller-DItYvwe0.js'; -import { B as ElementsController } from './controller-DItYvwe0.js'; -import { g as ElementUpdate } from './controller-DItYvwe0.js'; -import { aP as EntityNode } from './controller-DItYvwe0.js'; -import { aQ as FeatureNode } from './controller-DItYvwe0.js'; -import { aR as FeatureSelection } from './controller-DItYvwe0.js'; -import { aV as FeltBoundary } from './controller-DItYvwe0.js'; -import { F as FeltController } from './controller-DItYvwe0.js'; -import { Q as FeltTiledVectorSource } from './controller-DItYvwe0.js'; -import { aW as FeltZoom } from './controller-DItYvwe0.js'; -import { ao as FilterExpression } from './controller-DItYvwe0.js'; -import { ap as FilterLogicGate } from './controller-DItYvwe0.js'; -import { ar as Filters } from './controller-DItYvwe0.js'; -import { aq as FilterTernary } from './controller-DItYvwe0.js'; -import { R as GeoJsonDataVectorSource } from './controller-DItYvwe0.js'; -import { aX as GeoJsonFeature } from './controller-DItYvwe0.js'; -import { S as GeoJsonFileVectorSource } from './controller-DItYvwe0.js'; -import { aY as GeoJsonGeometry } from './controller-DItYvwe0.js'; -import { aZ as GeoJsonProperties } from './controller-DItYvwe0.js'; -import { W as GeoJsonUrlVectorSource } from './controller-DItYvwe0.js'; -import { as as GeometryFilter } from './controller-DItYvwe0.js'; -import { G as GetElementGroupsConstraint } from './controller-DItYvwe0.js'; -import { h as GetElementsConstraint } from './controller-DItYvwe0.js'; -import { az as GetLayerCalculationParams } from './controller-DItYvwe0.js'; -import { aA as GetLayerCategoriesGroup } from './controller-DItYvwe0.js'; -import { aB as GetLayerCategoriesParams } from './controller-DItYvwe0.js'; -import { X as GetLayerGroupsConstraint } from './controller-DItYvwe0.js'; -import { aC as GetLayerHistogramBin } from './controller-DItYvwe0.js'; -import { aD as GetLayerHistogramParams } from './controller-DItYvwe0.js'; -import { aE as GetLayerPrecomputedCalculationParams } from './controller-DItYvwe0.js'; -import { Y as GetLayersConstraint } from './controller-DItYvwe0.js'; -import { Z as GetRenderedFeaturesConstraint } from './controller-DItYvwe0.js'; -import { aF as GridConfig } from './controller-DItYvwe0.js'; -import { aG as GridType } from './controller-DItYvwe0.js'; -import { H as HighlighterElementCreate } from './controller-DItYvwe0.js'; -import { i as HighlighterElementRead } from './controller-DItYvwe0.js'; -import { j as HighlighterElementUpdate } from './controller-DItYvwe0.js'; -import { bb as HighlighterToolSettings } from './controller-DItYvwe0.js'; -import { I as ImageElementCreate } from './controller-DItYvwe0.js'; -import { k as ImageElementRead } from './controller-DItYvwe0.js'; -import { l as ImageElementUpdate } from './controller-DItYvwe0.js'; -import { bc as InputToolSettings } from './controller-DItYvwe0.js'; -import { J as InteractionsController } from './controller-DItYvwe0.js'; -import { a_ as LatLng } from './controller-DItYvwe0.js'; -import { _ as Layer } from './controller-DItYvwe0.js'; -import { at as LayerBoundaries } from './controller-DItYvwe0.js'; -import { $ as LayerChangeCallbackParams } from './controller-DItYvwe0.js'; -import { a0 as LayerCommon } from './controller-DItYvwe0.js'; -import { ae as LayerFeature } from './controller-DItYvwe0.js'; -import { au as LayerFilters } from './controller-DItYvwe0.js'; -import { a1 as LayerGroup } from './controller-DItYvwe0.js'; -import { a2 as LayerGroupChangeCallbackParams } from './controller-DItYvwe0.js'; -import { aS as LayerGroupNode } from './controller-DItYvwe0.js'; -import { aT as LayerNode } from './controller-DItYvwe0.js'; -import { a3 as LayerProcessingStatus } from './controller-DItYvwe0.js'; -import { ag as LayerSchema } from './controller-DItYvwe0.js'; -import { ah as LayerSchemaAttribute } from './controller-DItYvwe0.js'; -import { ai as LayerSchemaBooleanAttribute } from './controller-DItYvwe0.js'; -import { aj as LayerSchemaCommonAttribute } from './controller-DItYvwe0.js'; -import { ak as LayerSchemaDateAttribute } from './controller-DItYvwe0.js'; -import { al as LayerSchemaDateTimeAttribute } from './controller-DItYvwe0.js'; -import { am as LayerSchemaNumericAttribute } from './controller-DItYvwe0.js'; -import { an as LayerSchemaTextAttribute } from './controller-DItYvwe0.js'; -import { aK as LayersController } from './controller-DItYvwe0.js'; -import { a4 as LegendDisplay } from './controller-DItYvwe0.js'; -import { a5 as LegendItem } from './controller-DItYvwe0.js'; -import { a6 as LegendItemChangeCallbackParams } from './controller-DItYvwe0.js'; -import { a7 as LegendItemIdentifier } from './controller-DItYvwe0.js'; -import { a8 as LegendItemsConstraint } from './controller-DItYvwe0.js'; -import { a$ as LineStringGeometry } from './controller-DItYvwe0.js'; -import { bd as LineToolSettings } from './controller-DItYvwe0.js'; -import { L as LinkElementRead } from './controller-DItYvwe0.js'; -import { b0 as LngLatTuple } from './controller-DItYvwe0.js'; -import { aL as MapDetails } from './controller-DItYvwe0.js'; -import { D as MapInteractionEvent } from './controller-DItYvwe0.js'; -import { M as MarkerElementCreate } from './controller-DItYvwe0.js'; -import { m as MarkerElementRead } from './controller-DItYvwe0.js'; -import { n as MarkerElementUpdate } from './controller-DItYvwe0.js'; -import { be as MarkerToolSettings } from './controller-DItYvwe0.js'; -import { aM as MiscController } from './controller-DItYvwe0.js'; -import { aH as MultiAggregationConfig } from './controller-DItYvwe0.js'; -import { b1 as MultiLineStringGeometry } from './controller-DItYvwe0.js'; -import { b2 as MultiPointGeometry } from './controller-DItYvwe0.js'; -import { b3 as MultiPolygonGeometry } from './controller-DItYvwe0.js'; -import { N as NoteElementCreate } from './controller-DItYvwe0.js'; -import { o as NoteElementRead } from './controller-DItYvwe0.js'; -import { p as NoteElementUpdate } from './controller-DItYvwe0.js'; -import { bf as NoteToolSettings } from './controller-DItYvwe0.js'; -import { bu as OnMapInteractionsOptions } from './controller-DItYvwe0.js'; -import { P as PathElementCreate } from './controller-DItYvwe0.js'; -import { q as PathElementRead } from './controller-DItYvwe0.js'; -import { r as PathElementUpdate } from './controller-DItYvwe0.js'; -import { bg as PinToolSettings } from './controller-DItYvwe0.js'; -import { s as PlaceElementCreate } from './controller-DItYvwe0.js'; -import { t as PlaceElementRead } from './controller-DItYvwe0.js'; -import { u as PlaceElementUpdate } from './controller-DItYvwe0.js'; -import { bh as PlaceFrame } from './controller-DItYvwe0.js'; -import { bx as PlacementForUIElement } from './controller-DItYvwe0.js'; -import { bi as PlaceSymbol } from './controller-DItYvwe0.js'; -import { b4 as PointGeometry } from './controller-DItYvwe0.js'; -import { v as PolygonElementCreate } from './controller-DItYvwe0.js'; -import { w as PolygonElementRead } from './controller-DItYvwe0.js'; -import { x as PolygonElementUpdate } from './controller-DItYvwe0.js'; -import { b5 as PolygonGeometry } from './controller-DItYvwe0.js'; -import { bj as PolygonToolSettings } from './controller-DItYvwe0.js'; -import { aI as PrecomputedAggregationMethod } from './controller-DItYvwe0.js'; -import { a9 as RasterBand } from './controller-DItYvwe0.js'; -import { aa as RasterLayer } from './controller-DItYvwe0.js'; -import { ab as RasterLayerSource } from './controller-DItYvwe0.js'; -import { af as RasterValue } from './controller-DItYvwe0.js'; -import { bk as RouteToolSettings } from './controller-DItYvwe0.js'; -import { aU as SelectionController } from './controller-DItYvwe0.js'; -import { ce as SetViewportCenterZoomParams } from './controller-DItYvwe0.js'; -import { b6 as SetVisibilityRequest } from './controller-DItYvwe0.js'; -import { b7 as SortConfig } from './controller-DItYvwe0.js'; -import { b8 as SortDirection } from './controller-DItYvwe0.js'; -import { T as TextElementCreate } from './controller-DItYvwe0.js'; -import { y as TextElementRead } from './controller-DItYvwe0.js'; -import { A as TextElementUpdate } from './controller-DItYvwe0.js'; -import { bl as TextToolSettings } from './controller-DItYvwe0.js'; -import { bp as ToolsController } from './controller-DItYvwe0.js'; -import { bm as ToolSettingsChangeEvent } from './controller-DItYvwe0.js'; -import { bn as ToolSettingsMap } from './controller-DItYvwe0.js'; -import { bo as ToolType } from './controller-DItYvwe0.js'; -import { cc as UIActionTriggerCreate } from './controller-DItYvwe0.js'; -import { bA as UIButtonElement } from './controller-DItYvwe0.js'; -import { bB as UIButtonElementCreate } from './controller-DItYvwe0.js'; -import { bC as UIButtonElementUpdate } from './controller-DItYvwe0.js'; -import { bY as UIButtonRowElement } from './controller-DItYvwe0.js'; -import { bZ as UIButtonRowElementCreate } from './controller-DItYvwe0.js'; -import { b_ as UIButtonRowElementUpdate } from './controller-DItYvwe0.js'; -import { b$ as UICheckboxGroupElement } from './controller-DItYvwe0.js'; -import { c0 as UICheckboxGroupElementCreate } from './controller-DItYvwe0.js'; -import { c1 as UICheckboxGroupElementUpdate } from './controller-DItYvwe0.js'; -import { cb as UIControlElementOption } from './controller-DItYvwe0.js'; -import { cd as UiController } from './controller-DItYvwe0.js'; -import { U as UiControlsOptions } from './controller-DItYvwe0.js'; -import { bJ as UIDividerElement } from './controller-DItYvwe0.js'; -import { bK as UIDividerElementCreate } from './controller-DItYvwe0.js'; -import { bL as UIDividerElementUpdate } from './controller-DItYvwe0.js'; -import { bG as UIFlexibleSpaceElement } from './controller-DItYvwe0.js'; -import { bH as UIFlexibleSpaceElementCreate } from './controller-DItYvwe0.js'; -import { bI as UIFlexibleSpaceElementUpdate } from './controller-DItYvwe0.js'; -import { bV as UIGridContainerElement } from './controller-DItYvwe0.js'; -import { bW as UIGridContainerElementCreate } from './controller-DItYvwe0.js'; -import { bX as UIGridContainerElementUpdate } from './controller-DItYvwe0.js'; -import { c8 as UIIframeElement } from './controller-DItYvwe0.js'; -import { c9 as UIIframeElementCreate } from './controller-DItYvwe0.js'; -import { ca as UIIframeElementUpdate } from './controller-DItYvwe0.js'; -import { by as UIPanel } from './controller-DItYvwe0.js'; -import { bz as UIPanelCreateOrUpdate } from './controller-DItYvwe0.js'; -import { bS as UIPanelElement } from './controller-DItYvwe0.js'; -import { bT as UIPanelElementCreate } from './controller-DItYvwe0.js'; -import { bU as UIPanelElementUpdate } from './controller-DItYvwe0.js'; -import { c2 as UIRadioGroupElement } from './controller-DItYvwe0.js'; -import { c3 as UIRadioGroupElementCreate } from './controller-DItYvwe0.js'; -import { c4 as UIRadioGroupElementUpdate } from './controller-DItYvwe0.js'; -import { bP as UISelectElement } from './controller-DItYvwe0.js'; -import { bQ as UISelectElementCreate } from './controller-DItYvwe0.js'; -import { bR as UISelectElementUpdate } from './controller-DItYvwe0.js'; -import { bD as UITextElement } from './controller-DItYvwe0.js'; -import { bE as UITextElementCreate } from './controller-DItYvwe0.js'; -import { bF as UITextElementUpdate } from './controller-DItYvwe0.js'; -import { bM as UITextInputElement } from './controller-DItYvwe0.js'; -import { bN as UITextInputElementCreate } from './controller-DItYvwe0.js'; -import { bO as UITextInputElementUpdate } from './controller-DItYvwe0.js'; -import { c5 as UIToggleGroupElement } from './controller-DItYvwe0.js'; -import { c6 as UIToggleGroupElementCreate } from './controller-DItYvwe0.js'; -import { c7 as UIToggleGroupElementUpdate } from './controller-DItYvwe0.js'; -import { bv as UpdateActionTriggerParams } from './controller-DItYvwe0.js'; -import { ac as UpdateLayerParams } from './controller-DItYvwe0.js'; -import { bw as UpdatePanelElementsParams } from './controller-DItYvwe0.js'; -import { aJ as ValueConfiguration } from './controller-DItYvwe0.js'; -import { ad as VectorLayer } from './controller-DItYvwe0.js'; -import { V as ViewportCenterZoom } from './controller-DItYvwe0.js'; -import { cf as ViewportConstraints } from './controller-DItYvwe0.js'; -import { ci as ViewportController } from './controller-DItYvwe0.js'; -import { cg as ViewportFitBoundsParams } from './controller-DItYvwe0.js'; -import { ch as ViewportState } from './controller-DItYvwe0.js'; -import { z } from './controller-DItYvwe0.js'; +import { av as AggregatedGridConfig } from './controller-BcZvbm-Y.js'; +import { aw as AggregationConfig } from './controller-BcZvbm-Y.js'; +import { ax as AggregationMethod } from './controller-BcZvbm-Y.js'; +import { C as CircleElementCreate } from './controller-BcZvbm-Y.js'; +import { a as CircleElementRead } from './controller-BcZvbm-Y.js'; +import { b as CircleElementUpdate } from './controller-BcZvbm-Y.js'; +import { b9 as CircleToolSettings } from './controller-BcZvbm-Y.js'; +import { ba as ConfigurableToolType } from './controller-BcZvbm-Y.js'; +import { ay as CountGridConfig } from './controller-BcZvbm-Y.js'; +import { bq as CreateActionTriggerParams } from './controller-BcZvbm-Y.js'; +import { br as CreateFeatureActionParams } from './controller-BcZvbm-Y.js'; +import { K as CreateLayersFromGeoJsonParams } from './controller-BcZvbm-Y.js'; +import { bs as CreateOrUpdatePanelParams } from './controller-BcZvbm-Y.js'; +import { bt as CreatePanelElementsParams } from './controller-BcZvbm-Y.js'; +import { O as DataOnlyLayer } from './controller-BcZvbm-Y.js'; +import { bu as DeletePanelElementsParams } from './controller-BcZvbm-Y.js'; +import { E as Element_2 } from './controller-BcZvbm-Y.js'; +import { c as ElementChangeCallbackParams } from './controller-BcZvbm-Y.js'; +import { d as ElementCreate } from './controller-BcZvbm-Y.js'; +import { e as ElementGroup } from './controller-BcZvbm-Y.js'; +import { f as ElementGroupChangeCallbackParams } from './controller-BcZvbm-Y.js'; +import { aN as ElementGroupNode } from './controller-BcZvbm-Y.js'; +import { aO as ElementNode } from './controller-BcZvbm-Y.js'; +import { B as ElementsController } from './controller-BcZvbm-Y.js'; +import { g as ElementUpdate } from './controller-BcZvbm-Y.js'; +import { aP as EntityNode } from './controller-BcZvbm-Y.js'; +import { aQ as FeatureNode } from './controller-BcZvbm-Y.js'; +import { aR as FeatureSelection } from './controller-BcZvbm-Y.js'; +import { aV as FeltBoundary } from './controller-BcZvbm-Y.js'; +import { F as FeltController } from './controller-BcZvbm-Y.js'; +import { Q as FeltTiledVectorSource } from './controller-BcZvbm-Y.js'; +import { aW as FeltZoom } from './controller-BcZvbm-Y.js'; +import { ao as FilterExpression } from './controller-BcZvbm-Y.js'; +import { ap as FilterLogicGate } from './controller-BcZvbm-Y.js'; +import { ar as Filters } from './controller-BcZvbm-Y.js'; +import { aq as FilterTernary } from './controller-BcZvbm-Y.js'; +import { R as GeoJsonDataVectorSource } from './controller-BcZvbm-Y.js'; +import { aX as GeoJsonFeature } from './controller-BcZvbm-Y.js'; +import { S as GeoJsonFileVectorSource } from './controller-BcZvbm-Y.js'; +import { aY as GeoJsonGeometry } from './controller-BcZvbm-Y.js'; +import { aZ as GeoJsonProperties } from './controller-BcZvbm-Y.js'; +import { W as GeoJsonUrlVectorSource } from './controller-BcZvbm-Y.js'; +import { as as GeometryFilter } from './controller-BcZvbm-Y.js'; +import { G as GetElementGroupsConstraint } from './controller-BcZvbm-Y.js'; +import { h as GetElementsConstraint } from './controller-BcZvbm-Y.js'; +import { az as GetLayerCalculationParams } from './controller-BcZvbm-Y.js'; +import { aA as GetLayerCategoriesGroup } from './controller-BcZvbm-Y.js'; +import { aB as GetLayerCategoriesParams } from './controller-BcZvbm-Y.js'; +import { X as GetLayerGroupsConstraint } from './controller-BcZvbm-Y.js'; +import { aC as GetLayerHistogramBin } from './controller-BcZvbm-Y.js'; +import { aD as GetLayerHistogramParams } from './controller-BcZvbm-Y.js'; +import { aE as GetLayerPrecomputedCalculationParams } from './controller-BcZvbm-Y.js'; +import { Y as GetLayersConstraint } from './controller-BcZvbm-Y.js'; +import { Z as GetRenderedFeaturesConstraint } from './controller-BcZvbm-Y.js'; +import { aF as GridConfig } from './controller-BcZvbm-Y.js'; +import { aG as GridType } from './controller-BcZvbm-Y.js'; +import { H as HighlighterElementCreate } from './controller-BcZvbm-Y.js'; +import { i as HighlighterElementRead } from './controller-BcZvbm-Y.js'; +import { j as HighlighterElementUpdate } from './controller-BcZvbm-Y.js'; +import { bb as HighlighterToolSettings } from './controller-BcZvbm-Y.js'; +import { I as ImageElementCreate } from './controller-BcZvbm-Y.js'; +import { k as ImageElementRead } from './controller-BcZvbm-Y.js'; +import { l as ImageElementUpdate } from './controller-BcZvbm-Y.js'; +import { bc as InputToolSettings } from './controller-BcZvbm-Y.js'; +import { J as InteractionsController } from './controller-BcZvbm-Y.js'; +import { a_ as LatLng } from './controller-BcZvbm-Y.js'; +import { _ as Layer } from './controller-BcZvbm-Y.js'; +import { at as LayerBoundaries } from './controller-BcZvbm-Y.js'; +import { $ as LayerChangeCallbackParams } from './controller-BcZvbm-Y.js'; +import { a0 as LayerCommon } from './controller-BcZvbm-Y.js'; +import { ae as LayerFeature } from './controller-BcZvbm-Y.js'; +import { au as LayerFilters } from './controller-BcZvbm-Y.js'; +import { a1 as LayerGroup } from './controller-BcZvbm-Y.js'; +import { a2 as LayerGroupChangeCallbackParams } from './controller-BcZvbm-Y.js'; +import { aS as LayerGroupNode } from './controller-BcZvbm-Y.js'; +import { aT as LayerNode } from './controller-BcZvbm-Y.js'; +import { a3 as LayerProcessingStatus } from './controller-BcZvbm-Y.js'; +import { ag as LayerSchema } from './controller-BcZvbm-Y.js'; +import { ah as LayerSchemaAttribute } from './controller-BcZvbm-Y.js'; +import { ai as LayerSchemaBooleanAttribute } from './controller-BcZvbm-Y.js'; +import { aj as LayerSchemaCommonAttribute } from './controller-BcZvbm-Y.js'; +import { ak as LayerSchemaDateAttribute } from './controller-BcZvbm-Y.js'; +import { al as LayerSchemaDateTimeAttribute } from './controller-BcZvbm-Y.js'; +import { am as LayerSchemaNumericAttribute } from './controller-BcZvbm-Y.js'; +import { an as LayerSchemaTextAttribute } from './controller-BcZvbm-Y.js'; +import { aK as LayersController } from './controller-BcZvbm-Y.js'; +import { a4 as LegendDisplay } from './controller-BcZvbm-Y.js'; +import { a5 as LegendItem } from './controller-BcZvbm-Y.js'; +import { a6 as LegendItemChangeCallbackParams } from './controller-BcZvbm-Y.js'; +import { a7 as LegendItemIdentifier } from './controller-BcZvbm-Y.js'; +import { a8 as LegendItemsConstraint } from './controller-BcZvbm-Y.js'; +import { a$ as LineStringGeometry } from './controller-BcZvbm-Y.js'; +import { bd as LineToolSettings } from './controller-BcZvbm-Y.js'; +import { L as LinkElementRead } from './controller-BcZvbm-Y.js'; +import { b0 as LngLatTuple } from './controller-BcZvbm-Y.js'; +import { aL as MapDetails } from './controller-BcZvbm-Y.js'; +import { D as MapInteractionEvent } from './controller-BcZvbm-Y.js'; +import { M as MarkerElementCreate } from './controller-BcZvbm-Y.js'; +import { m as MarkerElementRead } from './controller-BcZvbm-Y.js'; +import { n as MarkerElementUpdate } from './controller-BcZvbm-Y.js'; +import { be as MarkerToolSettings } from './controller-BcZvbm-Y.js'; +import { aM as MiscController } from './controller-BcZvbm-Y.js'; +import { aH as MultiAggregationConfig } from './controller-BcZvbm-Y.js'; +import { b1 as MultiLineStringGeometry } from './controller-BcZvbm-Y.js'; +import { b2 as MultiPointGeometry } from './controller-BcZvbm-Y.js'; +import { b3 as MultiPolygonGeometry } from './controller-BcZvbm-Y.js'; +import { N as NoteElementCreate } from './controller-BcZvbm-Y.js'; +import { o as NoteElementRead } from './controller-BcZvbm-Y.js'; +import { p as NoteElementUpdate } from './controller-BcZvbm-Y.js'; +import { bf as NoteToolSettings } from './controller-BcZvbm-Y.js'; +import { bv as OnMapInteractionsOptions } from './controller-BcZvbm-Y.js'; +import { P as PathElementCreate } from './controller-BcZvbm-Y.js'; +import { q as PathElementRead } from './controller-BcZvbm-Y.js'; +import { r as PathElementUpdate } from './controller-BcZvbm-Y.js'; +import { bg as PinToolSettings } from './controller-BcZvbm-Y.js'; +import { s as PlaceElementCreate } from './controller-BcZvbm-Y.js'; +import { t as PlaceElementRead } from './controller-BcZvbm-Y.js'; +import { u as PlaceElementUpdate } from './controller-BcZvbm-Y.js'; +import { bh as PlaceFrame } from './controller-BcZvbm-Y.js'; +import { bz as PlacementForUIElement } from './controller-BcZvbm-Y.js'; +import { bi as PlaceSymbol } from './controller-BcZvbm-Y.js'; +import { b4 as PointGeometry } from './controller-BcZvbm-Y.js'; +import { v as PolygonElementCreate } from './controller-BcZvbm-Y.js'; +import { w as PolygonElementRead } from './controller-BcZvbm-Y.js'; +import { x as PolygonElementUpdate } from './controller-BcZvbm-Y.js'; +import { b5 as PolygonGeometry } from './controller-BcZvbm-Y.js'; +import { bj as PolygonToolSettings } from './controller-BcZvbm-Y.js'; +import { aI as PrecomputedAggregationMethod } from './controller-BcZvbm-Y.js'; +import { a9 as RasterBand } from './controller-BcZvbm-Y.js'; +import { aa as RasterLayer } from './controller-BcZvbm-Y.js'; +import { ab as RasterLayerSource } from './controller-BcZvbm-Y.js'; +import { af as RasterValue } from './controller-BcZvbm-Y.js'; +import { bk as RouteToolSettings } from './controller-BcZvbm-Y.js'; +import { aU as SelectionController } from './controller-BcZvbm-Y.js'; +import { ci as SetViewportCenterZoomParams } from './controller-BcZvbm-Y.js'; +import { b6 as SetVisibilityRequest } from './controller-BcZvbm-Y.js'; +import { b7 as SortConfig } from './controller-BcZvbm-Y.js'; +import { b8 as SortDirection } from './controller-BcZvbm-Y.js'; +import { T as TextElementCreate } from './controller-BcZvbm-Y.js'; +import { y as TextElementRead } from './controller-BcZvbm-Y.js'; +import { A as TextElementUpdate } from './controller-BcZvbm-Y.js'; +import { bl as TextToolSettings } from './controller-BcZvbm-Y.js'; +import { bp as ToolsController } from './controller-BcZvbm-Y.js'; +import { bm as ToolSettingsChangeEvent } from './controller-BcZvbm-Y.js'; +import { bn as ToolSettingsMap } from './controller-BcZvbm-Y.js'; +import { bo as ToolType } from './controller-BcZvbm-Y.js'; +import { ce as UIActionTriggerCreate } from './controller-BcZvbm-Y.js'; +import { bC as UIButtonElement } from './controller-BcZvbm-Y.js'; +import { bD as UIButtonElementCreate } from './controller-BcZvbm-Y.js'; +import { bE as UIButtonElementUpdate } from './controller-BcZvbm-Y.js'; +import { b_ as UIButtonRowElement } from './controller-BcZvbm-Y.js'; +import { b$ as UIButtonRowElementCreate } from './controller-BcZvbm-Y.js'; +import { c0 as UIButtonRowElementUpdate } from './controller-BcZvbm-Y.js'; +import { c1 as UICheckboxGroupElement } from './controller-BcZvbm-Y.js'; +import { c2 as UICheckboxGroupElementCreate } from './controller-BcZvbm-Y.js'; +import { c3 as UICheckboxGroupElementUpdate } from './controller-BcZvbm-Y.js'; +import { cd as UIControlElementOption } from './controller-BcZvbm-Y.js'; +import { ch as UiController } from './controller-BcZvbm-Y.js'; +import { U as UiControlsOptions } from './controller-BcZvbm-Y.js'; +import { bL as UIDividerElement } from './controller-BcZvbm-Y.js'; +import { bM as UIDividerElementCreate } from './controller-BcZvbm-Y.js'; +import { bN as UIDividerElementUpdate } from './controller-BcZvbm-Y.js'; +import { cf as uiFeatureAction } from './controller-BcZvbm-Y.js'; +import { cg as uiFeatureActionCreate } from './controller-BcZvbm-Y.js'; +import { bI as UIFlexibleSpaceElement } from './controller-BcZvbm-Y.js'; +import { bJ as UIFlexibleSpaceElementCreate } from './controller-BcZvbm-Y.js'; +import { bK as UIFlexibleSpaceElementUpdate } from './controller-BcZvbm-Y.js'; +import { bX as UIGridContainerElement } from './controller-BcZvbm-Y.js'; +import { bY as UIGridContainerElementCreate } from './controller-BcZvbm-Y.js'; +import { bZ as UIGridContainerElementUpdate } from './controller-BcZvbm-Y.js'; +import { ca as UIIframeElement } from './controller-BcZvbm-Y.js'; +import { cb as UIIframeElementCreate } from './controller-BcZvbm-Y.js'; +import { cc as UIIframeElementUpdate } from './controller-BcZvbm-Y.js'; +import { bA as UIPanel } from './controller-BcZvbm-Y.js'; +import { bB as UIPanelCreateOrUpdate } from './controller-BcZvbm-Y.js'; +import { bU as UIPanelElement } from './controller-BcZvbm-Y.js'; +import { bV as UIPanelElementCreate } from './controller-BcZvbm-Y.js'; +import { bW as UIPanelElementUpdate } from './controller-BcZvbm-Y.js'; +import { c4 as UIRadioGroupElement } from './controller-BcZvbm-Y.js'; +import { c5 as UIRadioGroupElementCreate } from './controller-BcZvbm-Y.js'; +import { c6 as UIRadioGroupElementUpdate } from './controller-BcZvbm-Y.js'; +import { bR as UISelectElement } from './controller-BcZvbm-Y.js'; +import { bS as UISelectElementCreate } from './controller-BcZvbm-Y.js'; +import { bT as UISelectElementUpdate } from './controller-BcZvbm-Y.js'; +import { bF as UITextElement } from './controller-BcZvbm-Y.js'; +import { bG as UITextElementCreate } from './controller-BcZvbm-Y.js'; +import { bH as UITextElementUpdate } from './controller-BcZvbm-Y.js'; +import { bO as UITextInputElement } from './controller-BcZvbm-Y.js'; +import { bP as UITextInputElementCreate } from './controller-BcZvbm-Y.js'; +import { bQ as UITextInputElementUpdate } from './controller-BcZvbm-Y.js'; +import { c7 as UIToggleGroupElement } from './controller-BcZvbm-Y.js'; +import { c8 as UIToggleGroupElementCreate } from './controller-BcZvbm-Y.js'; +import { c9 as UIToggleGroupElementUpdate } from './controller-BcZvbm-Y.js'; +import { bw as UpdateActionTriggerParams } from './controller-BcZvbm-Y.js'; +import { bx as UpdateFeatureActionParams } from './controller-BcZvbm-Y.js'; +import { ac as UpdateLayerParams } from './controller-BcZvbm-Y.js'; +import { by as UpdatePanelElementsParams } from './controller-BcZvbm-Y.js'; +import { aJ as ValueConfiguration } from './controller-BcZvbm-Y.js'; +import { ad as VectorLayer } from './controller-BcZvbm-Y.js'; +import { V as ViewportCenterZoom } from './controller-BcZvbm-Y.js'; +import { cj as ViewportConstraints } from './controller-BcZvbm-Y.js'; +import { cm as ViewportController } from './controller-BcZvbm-Y.js'; +import { ck as ViewportFitBoundsParams } from './controller-BcZvbm-Y.js'; +import { cl as ViewportState } from './controller-BcZvbm-Y.js'; +import { z } from './controller-BcZvbm-Y.js'; import { z as z_2 } from 'zod'; export { AggregatedGridConfig } @@ -227,6 +231,8 @@ export { CountGridConfig } export { CreateActionTriggerParams } +export { CreateFeatureActionParams } + export { CreateLayersFromGeoJsonParams } export { CreateOrUpdatePanelParams } @@ -634,6 +640,10 @@ export { UIDividerElementCreate } export { UIDividerElementUpdate } +export { uiFeatureAction } + +export { uiFeatureActionCreate } + export { UIFlexibleSpaceElement } export { UIFlexibleSpaceElementCreate } @@ -694,6 +704,8 @@ export { UIToggleGroupElementUpdate } export { UpdateActionTriggerParams } +export { UpdateFeatureActionParams } + export { UpdateLayerParams } export { UpdatePanelElementsParams } diff --git a/src/modules/ui/controller.ts b/src/modules/ui/controller.ts index 209ab499..c98e4730 100644 --- a/src/modules/ui/controller.ts +++ b/src/modules/ui/controller.ts @@ -2,15 +2,18 @@ import { method, methodWithListeners } from "~/lib/interface"; import type { SortConfig } from "~/modules/shared/types"; import type { CreateActionTriggerParams, + CreateFeatureActionParams, CreateOrUpdatePanelParams, CreatePanelElementsParams, DeletePanelElementsParams, UiControlsOptions, UiOnMapInteractionsOptions, UpdateActionTriggerParams, + UpdateFeatureActionParams, UpdatePanelElementsParams, } from "./types"; import type { UIActionTriggerCreate } from "./uiElements/UIActionTrigger"; +import type { UIFeatureAction } from "./uiElements/UIFeatureAction"; import type { UIPanel } from "./uiElements/UIPanel"; /** @@ -57,6 +60,18 @@ export const uiController = ( UIActionTriggerCreate >(feltWindow, "updateActionTrigger"), deleteActionTrigger: method(feltWindow, "deleteActionTrigger"), + + createFeatureAction: methodWithListeners< + "createFeatureAction", + CreateFeatureActionParams, + UIFeatureAction + >(feltWindow, "createFeatureAction"), + updateFeatureAction: methodWithListeners< + "updateFeatureAction", + UpdateFeatureActionParams, + UIFeatureAction + >(feltWindow, "updateFeatureAction"), + deleteFeatureAction: method(feltWindow, "deleteFeatureAction"), }); /** @@ -138,6 +153,65 @@ export interface UiController { */ deleteActionTrigger(id: string): void; + /** + * Creates a feature contextual action. + * + * @param args - The arguments for the method. + * @param args.action - The action to create. + * @param args.placement - The placement of the action. Optional. Defaults to `{ at: "end" }`. + * + * @example + * ```typescript + * const myAction = await felt.createFeatureAction({ + * action: { + * label: "Edit feature", + * onTrigger: async ({ featureId, layerId }) => { + * console.log(`Editing feature ${featureId} in layer ${layerId}`); + * }, + * layerIds: ["layer-1", "layer-2"], + * }, + * placement: { at: "start" }, // optional, defaults to { at: "end" } + * }); + * ``` + */ + createFeatureAction( + args: CreateFeatureActionParams, + ): Promise; + + /** + * Updates a feature contextual action. + * + * Feature contextual action to update is identified by the `id` property. + * + * @remarks + * Properties provided will override the existing properties. + * + * @param args - The feature contextual action to update. + * + * @example + * ```typescript + * await felt.updateFeatureAction({ + * id: "my-action", + * label: "Updated action label", // only label changes + * }); + * ``` + */ + updateFeatureAction( + args: UpdateFeatureActionParams, + ): Promise; + + /** + * Deletes a feature contextual action. + * + * @param id - The id of the feature contextual action to delete. + * + * @example + * ```typescript + * await felt.deleteFeatureAction("my-action"); + * ``` + */ + deleteFeatureAction(id: string): void; + /** * Creates a panel ID. * diff --git a/src/modules/ui/index.ts b/src/modules/ui/index.ts index 7603f0f6..02f178d2 100644 --- a/src/modules/ui/index.ts +++ b/src/modules/ui/index.ts @@ -6,12 +6,14 @@ */ export type { CreateActionTriggerParams, + CreateFeatureActionParams, CreateOrUpdatePanelParams, CreatePanelElementsParams, DeletePanelElementsParams, UiOnMapInteractionsOptions as OnMapInteractionsOptions, UiControlsOptions, UpdateActionTriggerParams, + UpdateFeatureActionParams, UpdatePanelElementsParams, } from "./types"; @@ -101,4 +103,9 @@ export type { UIControlElementOption } from "./uiElements/base"; export type { UIActionTriggerCreate } from "./uiElements/UIActionTrigger"; +export type { + UIFeatureAction as uiFeatureAction, + UIFeatureActionCreate as uiFeatureActionCreate, +} from "./uiElements/UIFeatureAction"; + export type { UiController } from "./controller"; diff --git a/src/modules/ui/schema.ts b/src/modules/ui/schema.ts index 1641d4ce..9f6d0705 100644 --- a/src/modules/ui/schema.ts +++ b/src/modules/ui/schema.ts @@ -5,15 +5,18 @@ import type { zInfer } from "~/lib/utils"; import { SortConfigSchema } from "../shared/types"; import { CreateActionTriggerParamsClonableSchema, + CreateFeatureActionParamsClonableSchema, CreateOrUpdatePanelParamsClonableSchema, CreatePanelElementsClonableSchema, DeletePanelElementsParamsSchema, UiControlsOptionsSchema, UiOnMapInteractionsOptionsSchema, UpdateActionTriggerParamsClonableSchema, + UpdateFeatureActionParamsClonableSchema, UpdatePanelElementsParamsClonableSchema, } from "./types"; import type { uiActionTriggerSchema } from "./uiElements/UIActionTrigger"; +import type { uiFeatureActionSchema } from "./uiElements/UIFeatureAction"; import type { uiPanelCreateSchema } from "./uiElements/UIPanel"; const CreateActionTriggerMessage = methodMessage( @@ -31,6 +34,21 @@ const DeleteActionTriggerMessage = methodMessage( z.string(), ); +const CreateFeatureActionMessage = methodMessage( + "createFeatureAction", + CreateFeatureActionParamsClonableSchema, +); + +const UpdateFeatureActionMessage = methodMessage( + "updateFeatureAction", + UpdateFeatureActionParamsClonableSchema, +); + +const DeleteFeatureActionMessage = methodMessage( + "deleteFeatureAction", + z.string(), +); + const CreatePanelIdMessage = methodMessage("createPanelId", z.void()); const CreateOrUpdatePanelMessage = methodMessage( @@ -86,6 +104,10 @@ export const uiSchema = { UpdateActionTriggerMessage, DeleteActionTriggerMessage, + CreateFeatureActionMessage, + UpdateFeatureActionMessage, + DeleteFeatureActionMessage, + CreatePanelIdMessage, CreateOrUpdatePanelMessage, DeletePanelMessage, @@ -115,6 +137,16 @@ export type UiSchema = { >; deleteActionTrigger: Method>; + createFeatureAction: Method< + zInfer, + zInfer + >; + updateFeatureAction: Method< + zInfer, + zInfer + >; + deleteFeatureAction: Method>; + createPanelId: Method>; createOrUpdatePanel: Method< zInfer, diff --git a/src/modules/ui/types.ts b/src/modules/ui/types.ts index 2af942ef..f8509548 100644 --- a/src/modules/ui/types.ts +++ b/src/modules/ui/types.ts @@ -7,6 +7,11 @@ import { uiActionTriggerSchema, type UIActionTriggerCreate, } from "./uiElements/UIActionTrigger"; +import { + uiFeatureActionSchema, + type UIFeatureAction, + type UIFeatureActionCreate, +} from "./uiElements/UIFeatureAction"; import { type UIFlexibleSpaceElementCreate } from "./uiElements/UIFlexibleSpaceElement"; import { uiPanelCreateSchema, @@ -50,6 +55,38 @@ export interface UpdateActionTriggerParams id: zInfer["id"]; } +const CreateFeatureActionParamsSchema = z.object({ + action: uiFeatureActionSchema.create, + placement: placementForUiElementSchema.optional(), +}); + +export const CreateFeatureActionParamsClonableSchema = z.object({ + action: uiFeatureActionSchema.clonable, + placement: placementForUiElementSchema.optional(), +}); + +/** + * @public + */ +export interface CreateFeatureActionParams + extends zInfer { + action: UIFeatureActionCreate; + placement?: PlacementForUIElement; +} + +const UpdateFeatureActionParamsSchema = uiFeatureActionSchema.update; + +export const UpdateFeatureActionParamsClonableSchema = + uiFeatureActionSchema.clonable.partial().required({ id: true }); + +/** + * @public + */ +export interface UpdateFeatureActionParams + extends Omit, "id"> { + id: zInfer["id"]; +} + const CreateOrUpdatePanelParamsSchema = z.object({ panel: uiPanelCreateSchema.params, placement: placementForUiElementSchema.optional(), diff --git a/src/modules/ui/uiElements/UIFeatureAction.ts b/src/modules/ui/uiElements/UIFeatureAction.ts new file mode 100644 index 00000000..81430cc3 --- /dev/null +++ b/src/modules/ui/uiElements/UIFeatureAction.ts @@ -0,0 +1,88 @@ +import { z } from "zod"; +import type { zInfer } from "~/lib/utils"; +import type { LayerFeature } from "~/modules/layers/features/types"; +import type { UiController } from "../controller"; +import { + makeUpdateSchema, + uiElementBaseCreateSchema, + uiElementBaseSchema, + type UIElementLifecycle, +} from "./base"; + +const uiFeatureActionBaseSchema = z.object({ + type: z.literal("FeatureAction"), + + /** + * The label of the feature action. + */ + label: z.string(), + + /** + * The function to call when the feature action is triggered. + */ + onTrigger: z + .function() + .args(z.object({ feature: z.custom() })) + .returns(z.void()), + + /** + * The layers to add the action to. Optional. Defaults to all layers. + */ + layerIds: z.array(z.string()).optional(), + + /** + * The geometry type of the features to add the action to. Optional. Defaults to all geometry types. + */ + geometryTypes: z + .array(z.enum(["Polygon", "Line", "Point", "Raster"])) + .optional(), +}); + +export const uiFeatureActionSchema = { + read: uiElementBaseSchema + .extend(uiFeatureActionBaseSchema.shape) + .extend({ id: z.string() }), + create: uiElementBaseCreateSchema.params + .extend(uiFeatureActionBaseSchema.shape) + .extend({ type: z.undefined() }), + clonable: uiElementBaseCreateSchema.clonable + .extend(uiFeatureActionBaseSchema.shape) + .extend({ type: z.undefined() }) + .extend({ onTrigger: z.string() }), + // Add the missing update schema + update: makeUpdateSchema( + uiElementBaseCreateSchema.params + .extend(uiFeatureActionBaseSchema.shape) + .extend({ type: z.undefined() }), + ), +}; + +/** + * Represents a feature action for creation. + * It can be added to the map by using the {@link UiController.createFeatureAction} method. + */ +export interface UIFeatureActionCreate + extends UIElementLifecycle, + Omit< + zInfer, + "onCreate" | "onDestroy" + > { + /** + * The function to call when the feature action is triggered. + * + * @param args - The arguments passed to the function. + * @param args.feature - The feature that triggered the action. + */ + onTrigger: (args: { feature: LayerFeature }) => void; +} + +/** + * Represents a feature action after creation (with generated id). + */ +export type UIFeatureAction = { + id: string; + label: string; + layerIds?: string[]; + geometryTypes?: Array<"Polygon" | "Point" | "Line" | "Raster">; + onTrigger: (args: { feature: LayerFeature }) => void; +};