@fieldnotes/core 0.7.0 → 0.7.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.
- package/dist/index.cjs +25 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +25 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -67,6 +67,7 @@ interface ImageElement extends BaseElement {
|
|
|
67
67
|
interface HtmlElement extends BaseElement {
|
|
68
68
|
type: 'html';
|
|
69
69
|
size: Size;
|
|
70
|
+
domId?: string;
|
|
70
71
|
}
|
|
71
72
|
interface TextElement extends BaseElement {
|
|
72
73
|
type: 'text';
|
|
@@ -477,6 +478,7 @@ declare class Viewport {
|
|
|
477
478
|
private hideDomNode;
|
|
478
479
|
private removeDomNode;
|
|
479
480
|
private clearDomNodes;
|
|
481
|
+
private reattachHtmlContent;
|
|
480
482
|
private createWrapper;
|
|
481
483
|
private createCanvas;
|
|
482
484
|
private createDomLayer;
|
|
@@ -564,6 +566,7 @@ interface ImageInput extends BaseDefaults {
|
|
|
564
566
|
interface HtmlInput extends BaseDefaults {
|
|
565
567
|
position: Point;
|
|
566
568
|
size: Size;
|
|
569
|
+
domId?: string;
|
|
567
570
|
}
|
|
568
571
|
interface TextInput extends BaseDefaults {
|
|
569
572
|
position: Point;
|
|
@@ -858,6 +861,6 @@ declare class UpdateLayerCommand implements Command {
|
|
|
858
861
|
undo(_store: ElementStore): void;
|
|
859
862
|
}
|
|
860
863
|
|
|
861
|
-
declare const VERSION = "0.
|
|
864
|
+
declare const VERSION = "0.7.0";
|
|
862
865
|
|
|
863
866
|
export { AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type GridElement, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, type Layer, LayerManager, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, RemoveElementCommand, RemoveLayerCommand, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createText, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, isBindable, isNearBezier, parseState, snapPoint, unbindArrow, updateBoundArrow };
|
package/dist/index.d.ts
CHANGED
|
@@ -67,6 +67,7 @@ interface ImageElement extends BaseElement {
|
|
|
67
67
|
interface HtmlElement extends BaseElement {
|
|
68
68
|
type: 'html';
|
|
69
69
|
size: Size;
|
|
70
|
+
domId?: string;
|
|
70
71
|
}
|
|
71
72
|
interface TextElement extends BaseElement {
|
|
72
73
|
type: 'text';
|
|
@@ -477,6 +478,7 @@ declare class Viewport {
|
|
|
477
478
|
private hideDomNode;
|
|
478
479
|
private removeDomNode;
|
|
479
480
|
private clearDomNodes;
|
|
481
|
+
private reattachHtmlContent;
|
|
480
482
|
private createWrapper;
|
|
481
483
|
private createCanvas;
|
|
482
484
|
private createDomLayer;
|
|
@@ -564,6 +566,7 @@ interface ImageInput extends BaseDefaults {
|
|
|
564
566
|
interface HtmlInput extends BaseDefaults {
|
|
565
567
|
position: Point;
|
|
566
568
|
size: Size;
|
|
569
|
+
domId?: string;
|
|
567
570
|
}
|
|
568
571
|
interface TextInput extends BaseDefaults {
|
|
569
572
|
position: Point;
|
|
@@ -858,6 +861,6 @@ declare class UpdateLayerCommand implements Command {
|
|
|
858
861
|
undo(_store: ElementStore): void;
|
|
859
862
|
}
|
|
860
863
|
|
|
861
|
-
declare const VERSION = "0.
|
|
864
|
+
declare const VERSION = "0.7.0";
|
|
862
865
|
|
|
863
866
|
export { AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Binding, type Bounds, Camera, type CameraOptions, type CanvasElement, type CanvasState, type Command, CreateLayerCommand, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, type GridElement, HandTool, type HexOrientation, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, type Layer, LayerManager, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, RemoveElementCommand, RemoveLayerCommand, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type Size, type StrokeElement, type StrokePoint, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, UpdateLayerCommand, VERSION, Viewport, type ViewportOptions, clearStaleBindings, createArrow, createGrid, createHtmlElement, createId, createImage, createNote, createShape, createStroke, createText, exportState, findBindTarget, findBoundArrows, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getEdgeIntersection, getElementBounds, getElementCenter, isBindable, isNearBezier, parseState, snapPoint, unbindArrow, updateBoundArrow };
|
package/dist/index.js
CHANGED
|
@@ -1687,7 +1687,7 @@ function createImage(input) {
|
|
|
1687
1687
|
};
|
|
1688
1688
|
}
|
|
1689
1689
|
function createHtmlElement(input) {
|
|
1690
|
-
|
|
1690
|
+
const el = {
|
|
1691
1691
|
id: createId("html"),
|
|
1692
1692
|
type: "html",
|
|
1693
1693
|
position: input.position,
|
|
@@ -1696,6 +1696,8 @@ function createHtmlElement(input) {
|
|
|
1696
1696
|
layerId: input.layerId ?? "",
|
|
1697
1697
|
size: input.size
|
|
1698
1698
|
};
|
|
1699
|
+
if (input.domId) el.domId = input.domId;
|
|
1700
|
+
return el;
|
|
1699
1701
|
}
|
|
1700
1702
|
function createShape(input) {
|
|
1701
1703
|
return {
|
|
@@ -2013,6 +2015,7 @@ var Viewport = class {
|
|
|
2013
2015
|
if (state.layers && state.layers.length > 0) {
|
|
2014
2016
|
this.layerManager.loadSnapshot(state.layers);
|
|
2015
2017
|
}
|
|
2018
|
+
this.reattachHtmlContent();
|
|
2016
2019
|
this.history.clear();
|
|
2017
2020
|
this.historyRecorder.resume();
|
|
2018
2021
|
this.camera.moveTo(state.camera.position.x, state.camera.position.y);
|
|
@@ -2044,7 +2047,8 @@ var Viewport = class {
|
|
|
2044
2047
|
return image.id;
|
|
2045
2048
|
}
|
|
2046
2049
|
addHtmlElement(dom, position, size = { w: 200, h: 150 }) {
|
|
2047
|
-
const
|
|
2050
|
+
const domId = dom.id || void 0;
|
|
2051
|
+
const el = createHtmlElement({ position, size, domId, layerId: this.layerManager.activeLayerId });
|
|
2048
2052
|
this.htmlContent.set(el.id, dom);
|
|
2049
2053
|
this.historyRecorder.begin();
|
|
2050
2054
|
this.store.add(el);
|
|
@@ -2413,6 +2417,16 @@ var Viewport = class {
|
|
|
2413
2417
|
this.htmlContent.clear();
|
|
2414
2418
|
this.requestRender();
|
|
2415
2419
|
}
|
|
2420
|
+
reattachHtmlContent() {
|
|
2421
|
+
for (const el of this.store.getElementsByType("html")) {
|
|
2422
|
+
if (el.domId) {
|
|
2423
|
+
const dom = document.getElementById(el.domId);
|
|
2424
|
+
if (dom) {
|
|
2425
|
+
this.htmlContent.set(el.id, dom);
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2416
2430
|
createWrapper() {
|
|
2417
2431
|
const el = document.createElement("div");
|
|
2418
2432
|
Object.assign(el.style, {
|
|
@@ -2671,10 +2685,11 @@ function applyArrowHandleDrag(handle, elementId, world, ctx) {
|
|
|
2671
2685
|
const el = ctx.store.getById(elementId);
|
|
2672
2686
|
if (!el || el.type !== "arrow") return;
|
|
2673
2687
|
const threshold = BIND_THRESHOLD / ctx.camera.zoom;
|
|
2688
|
+
const layerFilter = (candidate) => candidate.layerId === el.layerId;
|
|
2674
2689
|
switch (handle) {
|
|
2675
2690
|
case "start": {
|
|
2676
2691
|
const excludeId = el.toBinding?.elementId;
|
|
2677
|
-
const target = findBindTarget(world, ctx.store, threshold, excludeId);
|
|
2692
|
+
const target = findBindTarget(world, ctx.store, threshold, excludeId, layerFilter);
|
|
2678
2693
|
if (target) {
|
|
2679
2694
|
const center = getElementCenter(target);
|
|
2680
2695
|
ctx.store.update(elementId, {
|
|
@@ -2693,7 +2708,7 @@ function applyArrowHandleDrag(handle, elementId, world, ctx) {
|
|
|
2693
2708
|
}
|
|
2694
2709
|
case "end": {
|
|
2695
2710
|
const excludeId = el.fromBinding?.elementId;
|
|
2696
|
-
const target = findBindTarget(world, ctx.store, threshold, excludeId);
|
|
2711
|
+
const target = findBindTarget(world, ctx.store, threshold, excludeId, layerFilter);
|
|
2697
2712
|
if (target) {
|
|
2698
2713
|
const center = getElementCenter(target);
|
|
2699
2714
|
ctx.store.update(elementId, {
|
|
@@ -2722,7 +2737,8 @@ function getArrowHandleDragTarget(handle, elementId, world, ctx) {
|
|
|
2722
2737
|
if (!el || el.type !== "arrow") return null;
|
|
2723
2738
|
const threshold = BIND_THRESHOLD / ctx.camera.zoom;
|
|
2724
2739
|
const excludeId = handle === "start" ? el.toBinding?.elementId : el.fromBinding?.elementId;
|
|
2725
|
-
const
|
|
2740
|
+
const layerFilter = (candidate) => candidate.layerId === el.layerId;
|
|
2741
|
+
const target = findBindTarget(world, ctx.store, threshold, excludeId, layerFilter);
|
|
2726
2742
|
if (!target) return null;
|
|
2727
2743
|
return getElementBounds(target);
|
|
2728
2744
|
}
|
|
@@ -3182,8 +3198,10 @@ var ArrowTool = class {
|
|
|
3182
3198
|
if (options.width !== void 0) this.width = options.width;
|
|
3183
3199
|
}
|
|
3184
3200
|
layerFilter(ctx) {
|
|
3185
|
-
|
|
3201
|
+
const activeLayerId = ctx.activeLayerId;
|
|
3202
|
+
if (!activeLayerId && !ctx.isLayerVisible && !ctx.isLayerLocked) return void 0;
|
|
3186
3203
|
return (el) => {
|
|
3204
|
+
if (activeLayerId && el.layerId !== activeLayerId) return false;
|
|
3187
3205
|
if (ctx.isLayerVisible && !ctx.isLayerVisible(el.layerId)) return false;
|
|
3188
3206
|
if (ctx.isLayerLocked && ctx.isLayerLocked(el.layerId)) return false;
|
|
3189
3207
|
return true;
|
|
@@ -3567,7 +3585,7 @@ var UpdateLayerCommand = class {
|
|
|
3567
3585
|
};
|
|
3568
3586
|
|
|
3569
3587
|
// src/index.ts
|
|
3570
|
-
var VERSION = "0.
|
|
3588
|
+
var VERSION = "0.7.0";
|
|
3571
3589
|
export {
|
|
3572
3590
|
AddElementCommand,
|
|
3573
3591
|
ArrowTool,
|