Skip to content

The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.

JavaScript
4.7 KB
Raw Blame
<script>
  /**
   * The right-click menu on a feature of the layer being edited: what is
   * done to it most, where the pointer already is. It acts on the selection,
   * which the right-click has made sure holds the feature. `point` is where it
   * was opened (a marker's own position, else the spot pressed): its coordinates
   * copy in one press, and `onmore` opens the map's own menu there.
   */
  import Icon from '../../components/Icon.svelte';
  import FloatingMenu from '../../components/FloatingMenu.svelte';
  import LayerSelectionStyle from './LayerSelectionStyle.svelte';
  import { LAYER_HELP, STATUS_CHOICES } from '../../lib/map/layerHelp.js';
  import { copyText } from '../../lib/clipboard.js';
  import { fmtCoords } from '../../lib/state.svelte.js';

  let { controller, at, point = null, onmore = null, onclose } = $props();
  const coords = $derived(point ? fmtCoords(point.lat, point.lon) : '');
  const selection = $derived(controller.selection ?? []);
  const chosen = $derived(controller.features.filter((feature) => selection.includes(feature.properties.key)));
  const only = $derived(chosen.length === 1 ? chosen[0] : null);
  const statuses = $derived(new Set(chosen.map((feature) => feature.properties.status ?? '')));
  const turned = $derived(chosen.some((feature) => feature.geometry.type === 'Point' && feature.properties.bearing !== undefined && feature.properties.bearing !== null));
  const reshapable = $derived(!!only && !only.properties.entity_id
    && ['LineString', 'Polygon', 'MultiLineString', 'MultiPolygon'].includes(only.geometry.type));
  const busy = $derived(controller.pending > 0);

  function act(run) { run(); onclose?.(); }
</script>

{#if chosen.length}
  <FloatingMenu {at} width={232} label="Feature actions" {onclose}>
    <p class="fm-head">{only ? only.properties.name || 'Unnamed feature' : `${chosen.length} selected`}</p>
    <div class="line"><span>Style</span><LayerSelectionStyle {controller} label="Feature style" size={18} disabled={busy} /></div>
    <div class="status" role="group" aria-label="Status" title={LAYER_HELP.status}>
      {#each STATUS_CHOICES as [status, label, said] (status)}
        <button type="button" class:short={!status} aria-pressed={statuses.size === 1 && statuses.has(status)} disabled={busy}
          aria-label={status ? label : said} title={said}
          onclick={() => controller.updateSelection({ status: status || null })}>{label}</button>
      {/each}
    </div>
    <div class="fm-sep"></div>
    {#if coords}
      <button type="button" class="fm-item" title="Copy the position" onclick={() => act(() => copyText(coords))}>
        <Icon name="copy" size={14} /><span class="fm-grow mono">{coords}</span></button>
    {/if}
    {#if onmore}
      <button type="button" class="fm-item" title="Other coordinate formats, other maps, what is here" onclick={onmore}>
        <Icon name="crosshair" size={14} /><span class="fm-grow">More for this point…</span></button>
    {/if}
    {#if coords || onmore}<div class="fm-sep"></div>{/if}
    {#if turned}
      <button type="button" class="fm-item" disabled={busy} onclick={() => act(() => controller.updateSelection({ bearing: null }))}>
        <Icon name="compass" size={14} /><span class="fm-grow">Clear the direction</span></button>
    {/if}
    {#if reshapable}
      <button type="button" class="fm-item" disabled={busy} onclick={() => act(() => controller.editGeometry())}>
        <Icon name="edit" size={14} /><span class="fm-grow">Reshape</span></button>
    {/if}
    {#if only?.geometry.type === 'Point' && !only.properties.entity_id}
      <button type="button" class="fm-item" disabled={busy} onclick={() => act(() => controller.promote(only.properties.key))}>
        <Icon name="pin" size={14} /><span class="fm-grow">Save as case place</span></button>
    {/if}
    <button type="button" class="fm-item danger" disabled={busy} onclick={() => act(() => controller.removeSelection())}>
      <Icon name="trash" size={14} /><span class="fm-grow">{only ? 'Remove from the layer' : `Remove ${chosen.length} from the layer`}</span></button>
  </FloatingMenu>
{/if}

<style>
  .line { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px 0 8px; color: var(--text-2); font-size: var(--fs-sm); }
  .status { display: flex; margin: 5px 6px 3px; border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
  .status button { flex: 1; padding: 4px 3px; color: var(--text-2); font-size: 11px; cursor: pointer; }
  .status button + button { border-left: 1px solid var(--border); }
  .status button.short { flex: 0 0 26px; }
  .status button:hover:not(:disabled) { background: var(--bg-3); }
  .status button[aria-pressed='true'] { background: var(--accent-soft); color: var(--text-1); }
</style>