@deck.gl-community/editable-layers 9.2.0-beta.2 → 9.2.0-beta.3
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/index.cjs +256 -13
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/widgets/edit-mode-tray-widget.d.ts +71 -0
- package/dist/widgets/edit-mode-tray-widget.d.ts.map +1 -0
- package/dist/widgets/edit-mode-tray-widget.js +217 -0
- package/dist/widgets/edit-mode-tray-widget.js.map +1 -0
- package/package.json +3 -2
- package/src/index.ts +8 -0
- package/src/widgets/edit-mode-tray-widget.tsx +342 -0
package/dist/index.cjs
CHANGED
|
@@ -52,6 +52,7 @@ __export(dist_exports, {
|
|
|
52
52
|
DrawSquareFromCenterMode: () => DrawSquareFromCenterMode,
|
|
53
53
|
DrawSquareMode: () => DrawSquareMode,
|
|
54
54
|
DuplicateMode: () => DuplicateMode,
|
|
55
|
+
EditModeTrayWidget: () => EditModeTrayWidget,
|
|
55
56
|
EditableGeoJsonLayer: () => EditableGeoJsonLayer,
|
|
56
57
|
EditableH3ClusterLayer: () => EditableH3ClusterLayer,
|
|
57
58
|
ElevatedEditHandleLayer: () => ElevatedEditHandleLayer,
|
|
@@ -778,6 +779,22 @@ var VS_CODE = ` outline_setUV(gl_Position);
|
|
|
778
779
|
`;
|
|
779
780
|
var FS_CODE = ` fragColor = outline_filterColor(fragColor);
|
|
780
781
|
`;
|
|
782
|
+
var OUTLINE_SHADOWMAP_PARAMETERS = {
|
|
783
|
+
blend: true,
|
|
784
|
+
blendColorSrcFactor: "one",
|
|
785
|
+
blendColorDstFactor: "one",
|
|
786
|
+
blendColorOperation: "max",
|
|
787
|
+
blendAlphaSrcFactor: "one",
|
|
788
|
+
blendAlphaDstFactor: "one",
|
|
789
|
+
blendAlphaOperation: "max",
|
|
790
|
+
depthWriteEnabled: false,
|
|
791
|
+
depthCompare: "always"
|
|
792
|
+
};
|
|
793
|
+
var OUTLINE_RENDER_PARAMETERS = {
|
|
794
|
+
blend: false,
|
|
795
|
+
depthWriteEnabled: false,
|
|
796
|
+
depthCompare: "always"
|
|
797
|
+
};
|
|
781
798
|
var defaultProps = {
|
|
782
799
|
getZLevel: () => 0
|
|
783
800
|
};
|
|
@@ -795,9 +812,11 @@ var PathOutlineLayer = class extends import_layers4.PathLayer {
|
|
|
795
812
|
// @ts-expect-error PathLayer is missing LayerContext arg
|
|
796
813
|
initializeState(context) {
|
|
797
814
|
super.initializeState();
|
|
815
|
+
const outlineFramebuffer = context.device.createFramebuffer({
|
|
816
|
+
colorAttachments: ["rgba8unorm"]
|
|
817
|
+
});
|
|
798
818
|
this.setState({
|
|
799
|
-
outlineFramebuffer
|
|
800
|
-
dummyTexture: context.device.createTexture({ width: 1, height: 1 })
|
|
819
|
+
outlineFramebuffer
|
|
801
820
|
});
|
|
802
821
|
this.state.attributeManager.addInstanced({
|
|
803
822
|
instanceZLevel: {
|
|
@@ -809,6 +828,7 @@ var PathOutlineLayer = class extends import_layers4.PathLayer {
|
|
|
809
828
|
}
|
|
810
829
|
// Override draw to add render module
|
|
811
830
|
draw({ moduleParameters = {}, parameters, uniforms, context }) {
|
|
831
|
+
var _a;
|
|
812
832
|
const {
|
|
813
833
|
jointRounded,
|
|
814
834
|
capRounded,
|
|
@@ -829,28 +849,35 @@ var PathOutlineLayer = class extends import_layers4.PathLayer {
|
|
|
829
849
|
widthMinPixels,
|
|
830
850
|
widthMaxPixels
|
|
831
851
|
});
|
|
832
|
-
const { outlineFramebuffer
|
|
852
|
+
const { outlineFramebuffer } = this.state;
|
|
853
|
+
if (context == null ? void 0 : context.viewport) {
|
|
854
|
+
const viewportWidth = Math.max(1, Math.ceil(context.viewport.width));
|
|
855
|
+
const viewportHeight = Math.max(1, Math.ceil(context.viewport.height));
|
|
856
|
+
outlineFramebuffer.resize({ width: viewportWidth, height: viewportHeight });
|
|
857
|
+
} else {
|
|
858
|
+
outlineFramebuffer.resize();
|
|
859
|
+
}
|
|
860
|
+
const shadowmapTexture = (_a = outlineFramebuffer.colorAttachments[0]) == null ? void 0 : _a.texture;
|
|
861
|
+
if (!shadowmapTexture) {
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
833
864
|
this.state.model.updateModuleSettings({
|
|
834
865
|
outlineEnabled: true,
|
|
835
866
|
outlineRenderShadowmap: true,
|
|
836
|
-
outlineShadowmap:
|
|
867
|
+
outlineShadowmap: shadowmapTexture
|
|
837
868
|
});
|
|
838
869
|
this.state.model.draw({
|
|
839
870
|
uniforms: Object.assign({}, uniforms, {
|
|
840
871
|
jointType: 0,
|
|
841
872
|
widthScale: this.props.widthScale * 1.3
|
|
842
873
|
}),
|
|
843
|
-
parameters:
|
|
844
|
-
depthTest: false,
|
|
845
|
-
// Biggest value needs to go into buffer
|
|
846
|
-
blendEquation: import_constants2.GL.MAX
|
|
847
|
-
},
|
|
874
|
+
parameters: OUTLINE_SHADOWMAP_PARAMETERS,
|
|
848
875
|
framebuffer: outlineFramebuffer
|
|
849
876
|
});
|
|
850
877
|
this.state.model.updateModuleSettings({
|
|
851
878
|
outlineEnabled: true,
|
|
852
879
|
outlineRenderShadowmap: false,
|
|
853
|
-
outlineShadowmap:
|
|
880
|
+
outlineShadowmap: shadowmapTexture
|
|
854
881
|
});
|
|
855
882
|
this.state.model.draw({
|
|
856
883
|
uniforms: Object.assign({}, uniforms, {
|
|
@@ -858,9 +885,7 @@ var PathOutlineLayer = class extends import_layers4.PathLayer {
|
|
|
858
885
|
capType: Number(capRounded),
|
|
859
886
|
widthScale: this.props.widthScale
|
|
860
887
|
}),
|
|
861
|
-
parameters:
|
|
862
|
-
depthTest: false
|
|
863
|
-
}
|
|
888
|
+
parameters: OUTLINE_RENDER_PARAMETERS
|
|
864
889
|
});
|
|
865
890
|
}
|
|
866
891
|
};
|
|
@@ -5469,6 +5494,224 @@ var ElevatedEditHandleLayer = class extends import_core8.CompositeLayer {
|
|
|
5469
5494
|
__publicField(ElevatedEditHandleLayer, "layerName", "ElevatedEditHandleLayer");
|
|
5470
5495
|
__publicField(ElevatedEditHandleLayer, "defaultProps", defaultProps7);
|
|
5471
5496
|
|
|
5497
|
+
// dist/widgets/edit-mode-tray-widget.js
|
|
5498
|
+
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
5499
|
+
var import_preact = require("preact");
|
|
5500
|
+
var import_core9 = require("@deck.gl/core");
|
|
5501
|
+
var ROOT_STYLE = {
|
|
5502
|
+
position: "absolute",
|
|
5503
|
+
display: "flex",
|
|
5504
|
+
pointerEvents: "auto",
|
|
5505
|
+
userSelect: "none",
|
|
5506
|
+
zIndex: "99"
|
|
5507
|
+
};
|
|
5508
|
+
var TRAY_BASE_STYLE = {
|
|
5509
|
+
display: "flex",
|
|
5510
|
+
gap: "6px",
|
|
5511
|
+
background: "rgba(36, 40, 41, 0.88)",
|
|
5512
|
+
borderRadius: "999px",
|
|
5513
|
+
padding: "6px",
|
|
5514
|
+
alignItems: "center",
|
|
5515
|
+
justifyContent: "center",
|
|
5516
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.25)"
|
|
5517
|
+
};
|
|
5518
|
+
var BUTTON_BASE_STYLE = {
|
|
5519
|
+
appearance: "none",
|
|
5520
|
+
background: "transparent",
|
|
5521
|
+
border: "none",
|
|
5522
|
+
color: "#f0f0f0",
|
|
5523
|
+
width: "34px",
|
|
5524
|
+
height: "34px",
|
|
5525
|
+
display: "flex",
|
|
5526
|
+
flexDirection: "column",
|
|
5527
|
+
alignItems: "center",
|
|
5528
|
+
justifyContent: "center",
|
|
5529
|
+
borderRadius: "50%",
|
|
5530
|
+
cursor: "pointer",
|
|
5531
|
+
padding: "0",
|
|
5532
|
+
transition: "background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease"
|
|
5533
|
+
};
|
|
5534
|
+
var BUTTON_ACTIVE_STYLE = {
|
|
5535
|
+
background: "#0071e3",
|
|
5536
|
+
color: "#ffffff",
|
|
5537
|
+
boxShadow: "0 0 0 2px rgba(255, 255, 255, 0.35)"
|
|
5538
|
+
};
|
|
5539
|
+
var BUTTON_LABEL_STYLE = {
|
|
5540
|
+
fontSize: "10px",
|
|
5541
|
+
marginTop: "2px",
|
|
5542
|
+
lineHeight: "12px"
|
|
5543
|
+
};
|
|
5544
|
+
var _EditModeTrayWidget = class extends import_core9.Widget {
|
|
5545
|
+
placement = "top-left";
|
|
5546
|
+
className = "deck-widget-edit-mode-tray";
|
|
5547
|
+
layout = "vertical";
|
|
5548
|
+
selectedModeId = null;
|
|
5549
|
+
deck = null;
|
|
5550
|
+
appliedCustomClassName = null;
|
|
5551
|
+
constructor(props = {}) {
|
|
5552
|
+
super({ ..._EditModeTrayWidget.defaultProps, ...props });
|
|
5553
|
+
this.placement = props.placement ?? _EditModeTrayWidget.defaultProps.placement;
|
|
5554
|
+
this.layout = props.layout ?? _EditModeTrayWidget.defaultProps.layout;
|
|
5555
|
+
this.selectedModeId = this.resolveSelectedModeId(props.modes ?? [], props);
|
|
5556
|
+
}
|
|
5557
|
+
setProps(props) {
|
|
5558
|
+
if (props.placement !== void 0) {
|
|
5559
|
+
this.placement = props.placement;
|
|
5560
|
+
}
|
|
5561
|
+
if (props.layout !== void 0) {
|
|
5562
|
+
this.layout = props.layout;
|
|
5563
|
+
}
|
|
5564
|
+
const modes = props.modes ?? this.props.modes ?? [];
|
|
5565
|
+
this.selectedModeId = this.resolveSelectedModeId(modes, props);
|
|
5566
|
+
super.setProps(props);
|
|
5567
|
+
this.renderTray();
|
|
5568
|
+
}
|
|
5569
|
+
onAdd({ deck }) {
|
|
5570
|
+
this.deck = deck;
|
|
5571
|
+
}
|
|
5572
|
+
onRemove() {
|
|
5573
|
+
this.deck = null;
|
|
5574
|
+
const root = this.rootElement;
|
|
5575
|
+
if (root) {
|
|
5576
|
+
(0, import_preact.render)(null, root);
|
|
5577
|
+
}
|
|
5578
|
+
this.rootElement = null;
|
|
5579
|
+
}
|
|
5580
|
+
onRenderHTML(rootElement) {
|
|
5581
|
+
const style = { ...ROOT_STYLE, ...this.props.style };
|
|
5582
|
+
Object.assign(rootElement.style, style);
|
|
5583
|
+
if (this.appliedCustomClassName && this.appliedCustomClassName !== this.props.className) {
|
|
5584
|
+
rootElement.classList.remove(this.appliedCustomClassName);
|
|
5585
|
+
this.appliedCustomClassName = null;
|
|
5586
|
+
}
|
|
5587
|
+
if (this.props.className) {
|
|
5588
|
+
rootElement.classList.add(this.props.className);
|
|
5589
|
+
this.appliedCustomClassName = this.props.className;
|
|
5590
|
+
}
|
|
5591
|
+
rootElement.classList.add(this.className);
|
|
5592
|
+
this.renderTray();
|
|
5593
|
+
}
|
|
5594
|
+
renderTray() {
|
|
5595
|
+
const root = this.rootElement;
|
|
5596
|
+
if (!root) {
|
|
5597
|
+
return;
|
|
5598
|
+
}
|
|
5599
|
+
const modes = this.props.modes ?? [];
|
|
5600
|
+
const selectedId = this.selectedModeId;
|
|
5601
|
+
const direction = this.layout === "horizontal" ? "row" : "column";
|
|
5602
|
+
const trayStyle = {
|
|
5603
|
+
...TRAY_BASE_STYLE,
|
|
5604
|
+
flexDirection: direction
|
|
5605
|
+
};
|
|
5606
|
+
const stopEvent = (event) => {
|
|
5607
|
+
event.stopPropagation();
|
|
5608
|
+
if (typeof event.stopImmediatePropagation === "function") {
|
|
5609
|
+
event.stopImmediatePropagation();
|
|
5610
|
+
}
|
|
5611
|
+
};
|
|
5612
|
+
const ui = (0, import_jsx_runtime.jsx)("div", { style: trayStyle, onPointerDown: stopEvent, onPointerMove: stopEvent, onPointerUp: stopEvent, onMouseDown: stopEvent, onMouseMove: stopEvent, onMouseUp: stopEvent, onTouchStart: stopEvent, onTouchMove: stopEvent, onTouchEnd: stopEvent, children: modes.map((option, index) => {
|
|
5613
|
+
const id = this.getModeId(option, index);
|
|
5614
|
+
const active = id === selectedId;
|
|
5615
|
+
const label = option.label ?? "";
|
|
5616
|
+
const title = option.title ?? label;
|
|
5617
|
+
const buttonStyle = {
|
|
5618
|
+
...BUTTON_BASE_STYLE,
|
|
5619
|
+
...active ? BUTTON_ACTIVE_STYLE : {}
|
|
5620
|
+
};
|
|
5621
|
+
return (0, import_jsx_runtime.jsxs)("button", { type: "button", title: title || void 0, "aria-pressed": active, style: buttonStyle, onClick: (event) => {
|
|
5622
|
+
stopEvent(event);
|
|
5623
|
+
this.handleSelect(option, id);
|
|
5624
|
+
}, children: [option.icon, label ? (0, import_jsx_runtime.jsx)("span", { style: BUTTON_LABEL_STYLE, children: label }) : null] }, id);
|
|
5625
|
+
}) });
|
|
5626
|
+
(0, import_preact.render)(ui, root);
|
|
5627
|
+
}
|
|
5628
|
+
handleSelect(option, id) {
|
|
5629
|
+
var _a, _b;
|
|
5630
|
+
if (this.selectedModeId !== id) {
|
|
5631
|
+
this.selectedModeId = id;
|
|
5632
|
+
this.renderTray();
|
|
5633
|
+
}
|
|
5634
|
+
(_b = (_a = this.props).onSelectMode) == null ? void 0 : _b.call(_a, {
|
|
5635
|
+
id,
|
|
5636
|
+
mode: option.mode,
|
|
5637
|
+
option
|
|
5638
|
+
});
|
|
5639
|
+
}
|
|
5640
|
+
resolveSelectedModeId(modes, props) {
|
|
5641
|
+
var _a;
|
|
5642
|
+
if (props.selectedModeId !== void 0) {
|
|
5643
|
+
return props.selectedModeId;
|
|
5644
|
+
}
|
|
5645
|
+
const activeMode = props.activeMode ?? ((_a = this.props) == null ? void 0 : _a.activeMode) ?? null;
|
|
5646
|
+
if (activeMode) {
|
|
5647
|
+
const match = this.findOptionByMode(modes, activeMode);
|
|
5648
|
+
if (match) {
|
|
5649
|
+
return this.getModeId(match.option, match.index);
|
|
5650
|
+
}
|
|
5651
|
+
}
|
|
5652
|
+
if (this.selectedModeId) {
|
|
5653
|
+
const existing = this.findOptionById(modes, this.selectedModeId);
|
|
5654
|
+
if (existing) {
|
|
5655
|
+
return this.selectedModeId;
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
5658
|
+
const first = modes[0];
|
|
5659
|
+
return first ? this.getModeId(first, 0) : null;
|
|
5660
|
+
}
|
|
5661
|
+
findOptionByMode(modes, activeMode) {
|
|
5662
|
+
for (let index = 0; index < modes.length; index++) {
|
|
5663
|
+
const option = modes[index];
|
|
5664
|
+
if (option.mode === activeMode) {
|
|
5665
|
+
return { option, index };
|
|
5666
|
+
}
|
|
5667
|
+
if (this.isSameMode(option.mode, activeMode)) {
|
|
5668
|
+
return { option, index };
|
|
5669
|
+
}
|
|
5670
|
+
}
|
|
5671
|
+
return null;
|
|
5672
|
+
}
|
|
5673
|
+
findOptionById(modes, id) {
|
|
5674
|
+
for (let index = 0; index < modes.length; index++) {
|
|
5675
|
+
if (this.getModeId(modes[index], index) === id) {
|
|
5676
|
+
return { option: modes[index], index };
|
|
5677
|
+
}
|
|
5678
|
+
}
|
|
5679
|
+
return null;
|
|
5680
|
+
}
|
|
5681
|
+
getModeId(option, index) {
|
|
5682
|
+
if (option.id) {
|
|
5683
|
+
return option.id;
|
|
5684
|
+
}
|
|
5685
|
+
const mode = option.mode;
|
|
5686
|
+
if (mode) {
|
|
5687
|
+
if (typeof mode === "function" && mode.name) {
|
|
5688
|
+
return mode.name;
|
|
5689
|
+
}
|
|
5690
|
+
if (mode && mode.constructor && mode.constructor.name) {
|
|
5691
|
+
return mode.constructor.name;
|
|
5692
|
+
}
|
|
5693
|
+
}
|
|
5694
|
+
return `mode-${index}`;
|
|
5695
|
+
}
|
|
5696
|
+
isSameMode(modeA, modeB) {
|
|
5697
|
+
if (modeA === modeB) {
|
|
5698
|
+
return true;
|
|
5699
|
+
}
|
|
5700
|
+
const constructorA = modeA == null ? void 0 : modeA.constructor;
|
|
5701
|
+
const constructorB = modeB == null ? void 0 : modeB.constructor;
|
|
5702
|
+
return Boolean(constructorA && constructorB && constructorA === constructorB);
|
|
5703
|
+
}
|
|
5704
|
+
};
|
|
5705
|
+
var EditModeTrayWidget = _EditModeTrayWidget;
|
|
5706
|
+
__publicField(EditModeTrayWidget, "defaultProps", {
|
|
5707
|
+
id: "edit-mode-tray",
|
|
5708
|
+
placement: "top-left",
|
|
5709
|
+
layout: "vertical",
|
|
5710
|
+
modes: [],
|
|
5711
|
+
style: {},
|
|
5712
|
+
className: ""
|
|
5713
|
+
});
|
|
5714
|
+
|
|
5472
5715
|
// dist/edit-modes/resize-circle-mode.js
|
|
5473
5716
|
var import_nearest_point_on_line2 = __toESM(require("@turf/nearest-point-on-line"), 1);
|
|
5474
5717
|
var import_helpers17 = require("@turf/helpers");
|