@aglyn/besigner-ui 1.15.0 → 1.15.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/package.json +17 -17
- package/src/lib/components/connection-records-scope.d.ts +18 -0
- package/src/lib/components/connection-records-scope.js +54 -0
- package/src/lib/components/connection-records-scope.js.map +1 -0
- package/src/lib/components/dnd/draggable-droppable.js +30 -0
- package/src/lib/components/dnd/draggable-droppable.js.map +1 -1
- package/src/lib/components/inline-text-editor.component.js +20 -6
- package/src/lib/components/inline-text-editor.component.js.map +1 -1
- package/src/lib/components/node-leaf.js +115 -106
- package/src/lib/components/node-leaf.js.map +1 -1
- package/src/lib/utils/inline-text-edit.store.d.ts +18 -0
- package/src/lib/utils/inline-text-edit.store.js +10 -0
- package/src/lib/utils/inline-text-edit.store.js.map +1 -1
- package/src/lib/utils/table-cell-edit.d.ts +66 -0
- package/src/lib/utils/table-cell-edit.js +93 -0
- package/src/lib/utils/table-cell-edit.js.map +1 -0
|
@@ -53,6 +53,21 @@ export interface InlinePropEditTarget {
|
|
|
53
53
|
*/
|
|
54
54
|
initialHtml?: string;
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Table-cell edit target: the editor is anchored on one rendered cell of a
|
|
58
|
+
* Table element, and the commit rewrites that cell inside the node's grid
|
|
59
|
+
* attribute instead of its `children` (see `table-cell-edit.ts`). Always the
|
|
60
|
+
* plain surface — a cell stores plain text.
|
|
61
|
+
*/
|
|
62
|
+
export interface InlineCellEditTarget {
|
|
63
|
+
/** The attribute holding the grid string. */
|
|
64
|
+
attribute: string;
|
|
65
|
+
/** Row in the parsed grid, header row included. */
|
|
66
|
+
row: number;
|
|
67
|
+
column: number;
|
|
68
|
+
/** The cell's text when the edit opened. */
|
|
69
|
+
initialText: string;
|
|
70
|
+
}
|
|
56
71
|
/**
|
|
57
72
|
* State for the inline canvas text editor: which node is being edited and
|
|
58
73
|
* where its element sits in viewport coordinates (the editor renders as a
|
|
@@ -73,8 +88,11 @@ declare class InlineTextEditStore {
|
|
|
73
88
|
rect?: InlineTextEditRect;
|
|
74
89
|
anchor?: Element;
|
|
75
90
|
propTarget?: InlinePropEditTarget;
|
|
91
|
+
cellTarget?: InlineCellEditTarget;
|
|
76
92
|
constructor();
|
|
77
93
|
open(node: Aglyn.NodeSchema<any>, rect: InlineTextEditRect, propTarget?: InlinePropEditTarget, anchor?: Element): void;
|
|
94
|
+
/** Opens the editor on one Table cell — see {@link InlineCellEditTarget}. */
|
|
95
|
+
openCell(node: Aglyn.NodeSchema<any>, rect: InlineTextEditRect, cellTarget: InlineCellEditTarget, anchor: Element): void;
|
|
78
96
|
close(): void;
|
|
79
97
|
}
|
|
80
98
|
export declare const inlineTextEdit: InlineTextEditStore;
|
|
@@ -33,6 +33,14 @@
|
|
|
33
33
|
this.node = node;
|
|
34
34
|
this.rect = rect;
|
|
35
35
|
this.propTarget = propTarget;
|
|
36
|
+
this.cellTarget = undefined;
|
|
37
|
+
this.anchor = anchor;
|
|
38
|
+
}
|
|
39
|
+
/** Opens the editor on one Table cell — see {@link InlineCellEditTarget}. */ openCell(node, rect, cellTarget, anchor) {
|
|
40
|
+
this.node = node;
|
|
41
|
+
this.rect = rect;
|
|
42
|
+
this.propTarget = undefined;
|
|
43
|
+
this.cellTarget = cellTarget;
|
|
36
44
|
this.anchor = anchor;
|
|
37
45
|
}
|
|
38
46
|
close() {
|
|
@@ -40,12 +48,14 @@
|
|
|
40
48
|
this.rect = undefined;
|
|
41
49
|
this.anchor = undefined;
|
|
42
50
|
this.propTarget = undefined;
|
|
51
|
+
this.cellTarget = undefined;
|
|
43
52
|
}
|
|
44
53
|
constructor(){
|
|
45
54
|
this.node = undefined;
|
|
46
55
|
this.rect = undefined;
|
|
47
56
|
this.anchor = undefined;
|
|
48
57
|
this.propTarget = undefined;
|
|
58
|
+
this.cellTarget = undefined;
|
|
49
59
|
makeAutoObservable(this, {
|
|
50
60
|
anchor: observableRef
|
|
51
61
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/besigner/feature/designer/src/lib/utils/inline-text-edit.store.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as Aglyn from '@aglyn/aglyn'\nimport { makeAutoObservable, observableRef } from 'mobx'\n\nexport interface InlineTextEditRect {\n left: number\n top: number\n width: number\n height: number\n}\n\n/**\n * Prop-override edit target (AGL-1304): the editor is anchored on a grafted\n * text leaf INSIDE a component instance, and the commit writes the\n * instance's `propValues[propName]` instead of the node's `children`. The\n * `node` held by the store stays the INSTANCE — the grafted leaf is not a\n * canvas node, only the anchor rect came from it.\n */\nexport interface InlinePropEditTarget {\n /** Declared prop name the edit commits to. */\n propName: string\n /**\n * The text the leaf currently renders (override unless unset, else the\n * declared default — `getInstanceEffectivePropText`). Captured at open\n * because the editor cannot re-derive it without the definition.\n */\n initialText: string\n /**\n * The schema of the element the prop fills — what decides which\n * formatting commands are offered, as a node's own schema does for it.\n */\n schema?: Aglyn.ComponentSchema<any>\n /**\n * Whether the edit is formatted text: every element the prop fills draws\n * markup. One that cannot would show the author bold that never renders.\n */\n rich?: boolean\n /**\n * The prop's formatted text as the instance stores it, or `''` — the\n * markup the editor opens with in place of the plain `initialText`.\n */\n initialHtml?: string\n}\n\n/**\n * State for the inline canvas text editor: which node is being edited and\n * where its element sits in viewport coordinates (the editor renders as a\n * fixed overlay OUTSIDE the closed canvas shadow root, so screen coordinates\n * are the only shared frame of reference).\n *\n * `anchor` is the element the rect was measured from, kept so the editor can\n * re-measure rather than drift when the canvas scrolls (AGL-1644). It is the\n * anchor RATHER than the node's `Besigner.refs` entry because a prop-override\n * edit measures a grafted preview leaf, which is not a canvas node and has no\n * ref — the case a ref lookup would have missed silently.\n *\n * An `observableRef`: a DOM node is a foreign object graph, and mobx has no\n * business walking into it.\n */\nclass InlineTextEditStore {\n node?: Aglyn.NodeSchema<any> = undefined\n rect?: InlineTextEditRect = undefined\n anchor?: Element = undefined\n propTarget?: InlinePropEditTarget = undefined\n\n constructor() {\n makeAutoObservable(this, { anchor: observableRef })\n }\n\n open(\n node: Aglyn.NodeSchema<any>,\n rect: InlineTextEditRect,\n propTarget?: InlinePropEditTarget,\n anchor?: Element,\n ) {\n this.node = node\n this.rect = rect\n this.propTarget = propTarget\n this.anchor = anchor\n }\n\n close() {\n this.node = undefined\n this.rect = undefined\n this.anchor = undefined\n this.propTarget = undefined\n }\n}\n\nexport const inlineTextEdit = new InlineTextEditStore()\n\n/**\n * Whether an inline text edit is open ON or INSIDE `element` (AGL-2486).\n *\n * The one place the \"stand down, someone is typing in here\" rule is\n * expressed. Every canvas leaf registers its own pointer handlers, and those\n * handlers begin by preventing the default — which is the default the\n * browser uses to place a caret. Asking only \"is this leaf the node being\n * edited?\" is not enough, and worse than not enough: a nested run stands its\n * own leaf down, the event then BUBBLES to the ancestor leaf, and the\n * ancestor prevents the default instead. The author sees an editor that is\n * open, styled and completely uninteractive — no caret, no drag-select, no\n * double-click-to-select-a-word.\n *\n * Containment, not identity, and by DOM rather than by node tree: the anchor\n * is the element that was measured, which is the one thing that is true for\n * a grafted instance leaf as well as a canvas node, and `contains` answers\n * for any nesting depth including the element itself.\n */\nexport function isInlineEditWithin(\n element: Element | null | undefined,\n): boolean {\n const anchor = inlineTextEdit.anchor\n return Boolean(anchor && element && element.contains(anchor))\n}\n\nexport default inlineTextEdit\n"],"names":["makeAutoObservable","observableRef","InlineTextEditStore","open","node","rect","propTarget","anchor","
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/besigner/feature/designer/src/lib/utils/inline-text-edit.store.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as Aglyn from '@aglyn/aglyn'\nimport { makeAutoObservable, observableRef } from 'mobx'\n\nexport interface InlineTextEditRect {\n left: number\n top: number\n width: number\n height: number\n}\n\n/**\n * Prop-override edit target (AGL-1304): the editor is anchored on a grafted\n * text leaf INSIDE a component instance, and the commit writes the\n * instance's `propValues[propName]` instead of the node's `children`. The\n * `node` held by the store stays the INSTANCE — the grafted leaf is not a\n * canvas node, only the anchor rect came from it.\n */\nexport interface InlinePropEditTarget {\n /** Declared prop name the edit commits to. */\n propName: string\n /**\n * The text the leaf currently renders (override unless unset, else the\n * declared default — `getInstanceEffectivePropText`). Captured at open\n * because the editor cannot re-derive it without the definition.\n */\n initialText: string\n /**\n * The schema of the element the prop fills — what decides which\n * formatting commands are offered, as a node's own schema does for it.\n */\n schema?: Aglyn.ComponentSchema<any>\n /**\n * Whether the edit is formatted text: every element the prop fills draws\n * markup. One that cannot would show the author bold that never renders.\n */\n rich?: boolean\n /**\n * The prop's formatted text as the instance stores it, or `''` — the\n * markup the editor opens with in place of the plain `initialText`.\n */\n initialHtml?: string\n}\n\n/**\n * Table-cell edit target: the editor is anchored on one rendered cell of a\n * Table element, and the commit rewrites that cell inside the node's grid\n * attribute instead of its `children` (see `table-cell-edit.ts`). Always the\n * plain surface — a cell stores plain text.\n */\nexport interface InlineCellEditTarget {\n /** The attribute holding the grid string. */\n attribute: string\n /** Row in the parsed grid, header row included. */\n row: number\n column: number\n /** The cell's text when the edit opened. */\n initialText: string\n}\n\n/**\n * State for the inline canvas text editor: which node is being edited and\n * where its element sits in viewport coordinates (the editor renders as a\n * fixed overlay OUTSIDE the closed canvas shadow root, so screen coordinates\n * are the only shared frame of reference).\n *\n * `anchor` is the element the rect was measured from, kept so the editor can\n * re-measure rather than drift when the canvas scrolls (AGL-1644). It is the\n * anchor RATHER than the node's `Besigner.refs` entry because a prop-override\n * edit measures a grafted preview leaf, which is not a canvas node and has no\n * ref — the case a ref lookup would have missed silently.\n *\n * An `observableRef`: a DOM node is a foreign object graph, and mobx has no\n * business walking into it.\n */\nclass InlineTextEditStore {\n node?: Aglyn.NodeSchema<any> = undefined\n rect?: InlineTextEditRect = undefined\n anchor?: Element = undefined\n propTarget?: InlinePropEditTarget = undefined\n cellTarget?: InlineCellEditTarget = undefined\n\n constructor() {\n makeAutoObservable(this, { anchor: observableRef })\n }\n\n open(\n node: Aglyn.NodeSchema<any>,\n rect: InlineTextEditRect,\n propTarget?: InlinePropEditTarget,\n anchor?: Element,\n ) {\n this.node = node\n this.rect = rect\n this.propTarget = propTarget\n this.cellTarget = undefined\n this.anchor = anchor\n }\n\n /** Opens the editor on one Table cell — see {@link InlineCellEditTarget}. */\n openCell(\n node: Aglyn.NodeSchema<any>,\n rect: InlineTextEditRect,\n cellTarget: InlineCellEditTarget,\n anchor: Element,\n ) {\n this.node = node\n this.rect = rect\n this.propTarget = undefined\n this.cellTarget = cellTarget\n this.anchor = anchor\n }\n\n close() {\n this.node = undefined\n this.rect = undefined\n this.anchor = undefined\n this.propTarget = undefined\n this.cellTarget = undefined\n }\n}\n\nexport const inlineTextEdit = new InlineTextEditStore()\n\n/**\n * Whether an inline text edit is open ON or INSIDE `element` (AGL-2486).\n *\n * The one place the \"stand down, someone is typing in here\" rule is\n * expressed. Every canvas leaf registers its own pointer handlers, and those\n * handlers begin by preventing the default — which is the default the\n * browser uses to place a caret. Asking only \"is this leaf the node being\n * edited?\" is not enough, and worse than not enough: a nested run stands its\n * own leaf down, the event then BUBBLES to the ancestor leaf, and the\n * ancestor prevents the default instead. The author sees an editor that is\n * open, styled and completely uninteractive — no caret, no drag-select, no\n * double-click-to-select-a-word.\n *\n * Containment, not identity, and by DOM rather than by node tree: the anchor\n * is the element that was measured, which is the one thing that is true for\n * a grafted instance leaf as well as a canvas node, and `contains` answers\n * for any nesting depth including the element itself.\n */\nexport function isInlineEditWithin(\n element: Element | null | undefined,\n): boolean {\n const anchor = inlineTextEdit.anchor\n return Boolean(anchor && element && element.contains(anchor))\n}\n\nexport default inlineTextEdit\n"],"names":["makeAutoObservable","observableRef","InlineTextEditStore","open","node","rect","propTarget","anchor","cellTarget","undefined","openCell","close","inlineTextEdit","isInlineEditWithin","element","Boolean","contains"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,kBAAkB,EAAEC,aAAa,QAAQ,OAAM;AA0DxD;;;;;;;;;;;;;;CAcC,GACD,IAAA,AAAMC,sBAAN,MAAMA;IAWJC,KACEC,IAA2B,EAC3BC,IAAwB,EACxBC,UAAiC,EACjCC,MAAgB,EAChB;QACA,IAAI,CAACH,IAAI,GAAGA;QACZ,IAAI,CAACC,IAAI,GAAGA;QACZ,IAAI,CAACC,UAAU,GAAGA;QAClB,IAAI,CAACE,UAAU,GAAGC;QAClB,IAAI,CAACF,MAAM,GAAGA;IAChB;IAEA,2EAA2E,GAC3EG,SACEN,IAA2B,EAC3BC,IAAwB,EACxBG,UAAgC,EAChCD,MAAe,EACf;QACA,IAAI,CAACH,IAAI,GAAGA;QACZ,IAAI,CAACC,IAAI,GAAGA;QACZ,IAAI,CAACC,UAAU,GAAGG;QAClB,IAAI,CAACD,UAAU,GAAGA;QAClB,IAAI,CAACD,MAAM,GAAGA;IAChB;IAEAI,QAAQ;QACN,IAAI,CAACP,IAAI,GAAGK;QACZ,IAAI,CAACJ,IAAI,GAAGI;QACZ,IAAI,CAACF,MAAM,GAAGE;QACd,IAAI,CAACH,UAAU,GAAGG;QAClB,IAAI,CAACD,UAAU,GAAGC;IACpB;IArCA,aAAc;aANdL,OAA+BK;aAC/BJ,OAA4BI;aAC5BF,SAAmBE;aACnBH,aAAoCG;aACpCD,aAAoCC;QAGlCT,mBAAmB,IAAI,EAAE;YAAEO,QAAQN;QAAc;IACnD;AAoCF;AAEA,OAAO,MAAMW,iBAAiB,IAAIV,sBAAqB;AAEvD;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASW,mBACdC,OAAmC;IAEnC,MAAMP,SAASK,eAAeL,MAAM;IACpC,OAAOQ,QAAQR,UAAUO,WAAWA,QAAQE,QAAQ,CAACT;AACvD;AAEA,eAAeK,eAAc"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type * as Aglyn from '@aglyn/aglyn';
|
|
18
|
+
/**
|
|
19
|
+
* In-place editing of one Table cell on the canvas.
|
|
20
|
+
*
|
|
21
|
+
* The Table element stores its whole grid as ONE string attribute (see
|
|
22
|
+
* `@aglyn/shared-data-enums`'s `data-table`), so a cell is not a canvas node
|
|
23
|
+
* and has no `children` of its own to edit. A double-click on a cell opens
|
|
24
|
+
* the same in-place text editor every text element uses, anchored on the
|
|
25
|
+
* cell, and the commit rewrites that one cell inside the stored string —
|
|
26
|
+
* through the same parser and serializer the attributes-panel grid uses, so
|
|
27
|
+
* the two surfaces can never disagree about what a table string means.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* The attribute holding the grid, or `undefined` when the component declares
|
|
31
|
+
* none. Keyed on the schema's own `DATA_TABLE` field declaration — the same
|
|
32
|
+
* declaration that gives the attributes panel its grid — rather than on a
|
|
33
|
+
* component id, so any element that stores a grid this way is editable on
|
|
34
|
+
* the canvas too.
|
|
35
|
+
*/
|
|
36
|
+
export declare function findDataTableAttributeName(node: Aglyn.NodeSchema<any> | undefined): string | undefined;
|
|
37
|
+
/** The cell a point falls in, and where it sits in the stored grid. */
|
|
38
|
+
export interface DataTableCellHit {
|
|
39
|
+
element: HTMLElement;
|
|
40
|
+
/** Row in the parsed grid — the header row, when there is one, is row 0. */
|
|
41
|
+
row: number;
|
|
42
|
+
column: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The rendered cell under a client point inside `root`, if any.
|
|
46
|
+
*
|
|
47
|
+
* Geometric rather than `elementFromPoint`, for the reason instance leaves
|
|
48
|
+
* are hit-tested that way: the canvas is a closed shadow root and the point
|
|
49
|
+
* may come from a touch, so the event target is not something to rely on.
|
|
50
|
+
*
|
|
51
|
+
* The grid row is the cell's `<tr>` index across the whole table. The
|
|
52
|
+
* renderer draws exactly one `<tr>` per parsed row, header included, so the
|
|
53
|
+
* two indexes are the same thing.
|
|
54
|
+
*/
|
|
55
|
+
export declare function findDataTableCellAtPoint(root: Element, clientX: number, clientY: number): DataTableCellHit | undefined;
|
|
56
|
+
/** The text a stored grid holds at one cell, or `''` when it is outside it. */
|
|
57
|
+
export declare function readDataTableCell(value: unknown, row: number, column: number): string;
|
|
58
|
+
/**
|
|
59
|
+
* The stored grid with one cell replaced.
|
|
60
|
+
*
|
|
61
|
+
* A cell is one line — the storage is one row per line — so a line break
|
|
62
|
+
* typed into the cell becomes a space instead of splitting the row. Column
|
|
63
|
+
* alignments survive: they ride the same string as a divider row, and are
|
|
64
|
+
* read back out and written again with the grid.
|
|
65
|
+
*/
|
|
66
|
+
export declare function writeDataTableCell(value: unknown, row: number, column: number, text: string): string;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { FieldComponentType } from "@aglyn/aglyn";
|
|
17
|
+
import { parseDataTableRows, readDataTableAlignments, serializeDataTable, withCellSet } from "@aglyn/shared-data-enums";
|
|
18
|
+
/**
|
|
19
|
+
* In-place editing of one Table cell on the canvas.
|
|
20
|
+
*
|
|
21
|
+
* The Table element stores its whole grid as ONE string attribute (see
|
|
22
|
+
* `@aglyn/shared-data-enums`'s `data-table`), so a cell is not a canvas node
|
|
23
|
+
* and has no `children` of its own to edit. A double-click on a cell opens
|
|
24
|
+
* the same in-place text editor every text element uses, anchored on the
|
|
25
|
+
* cell, and the commit rewrites that one cell inside the stored string —
|
|
26
|
+
* through the same parser and serializer the attributes-panel grid uses, so
|
|
27
|
+
* the two surfaces can never disagree about what a table string means.
|
|
28
|
+
*/ /**
|
|
29
|
+
* The attribute holding the grid, or `undefined` when the component declares
|
|
30
|
+
* none. Keyed on the schema's own `DATA_TABLE` field declaration — the same
|
|
31
|
+
* declaration that gives the attributes panel its grid — rather than on a
|
|
32
|
+
* component id, so any element that stores a grid this way is editable on
|
|
33
|
+
* the canvas too.
|
|
34
|
+
*/ export function findDataTableAttributeName(node) {
|
|
35
|
+
var _ref;
|
|
36
|
+
var _node_componentSchema;
|
|
37
|
+
for (const attribute of (_ref = node == null ? void 0 : (_node_componentSchema = node.componentSchema) == null ? void 0 : _node_componentSchema.attributes) != null ? _ref : []){
|
|
38
|
+
if ((attribute == null ? void 0 : attribute.component) === FieldComponentType.DATA_TABLE) {
|
|
39
|
+
return attribute.name;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The rendered cell under a client point inside `root`, if any.
|
|
46
|
+
*
|
|
47
|
+
* Geometric rather than `elementFromPoint`, for the reason instance leaves
|
|
48
|
+
* are hit-tested that way: the canvas is a closed shadow root and the point
|
|
49
|
+
* may come from a touch, so the event target is not something to rely on.
|
|
50
|
+
*
|
|
51
|
+
* The grid row is the cell's `<tr>` index across the whole table. The
|
|
52
|
+
* renderer draws exactly one `<tr>` per parsed row, header included, so the
|
|
53
|
+
* two indexes are the same thing.
|
|
54
|
+
*/ export function findDataTableCellAtPoint(root, clientX, clientY) {
|
|
55
|
+
const rows = Array.from(root.querySelectorAll('tr'));
|
|
56
|
+
for(let row = 0; row < rows.length; row++){
|
|
57
|
+
const cells = Array.from(rows[row].children).filter((cell)=>cell.tagName === 'TD' || cell.tagName === 'TH');
|
|
58
|
+
for(let column = 0; column < cells.length; column++){
|
|
59
|
+
const rect = cells[column].getBoundingClientRect();
|
|
60
|
+
if (clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom) {
|
|
61
|
+
return {
|
|
62
|
+
element: cells[column],
|
|
63
|
+
row,
|
|
64
|
+
column
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
/** The text a stored grid holds at one cell, or `''` when it is outside it. */ export function readDataTableCell(value, row, column) {
|
|
72
|
+
var _ref;
|
|
73
|
+
var _parseDataTableRows_row;
|
|
74
|
+
return (_ref = (_parseDataTableRows_row = parseDataTableRows(value)[row]) == null ? void 0 : _parseDataTableRows_row[column]) != null ? _ref : '';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The stored grid with one cell replaced.
|
|
78
|
+
*
|
|
79
|
+
* A cell is one line — the storage is one row per line — so a line break
|
|
80
|
+
* typed into the cell becomes a space instead of splitting the row. Column
|
|
81
|
+
* alignments survive: they ride the same string as a divider row, and are
|
|
82
|
+
* read back out and written again with the grid.
|
|
83
|
+
*/ export function writeDataTableCell(value, row, column, text) {
|
|
84
|
+
var _ref;
|
|
85
|
+
var _grid_;
|
|
86
|
+
const grid = parseDataTableRows(value);
|
|
87
|
+
const width = (_ref = (_grid_ = grid[0]) == null ? void 0 : _grid_.length) != null ? _ref : 0;
|
|
88
|
+
const alignments = readDataTableAlignments(value, width);
|
|
89
|
+
const cell = text.replace(/\s*\r?\n\s*/g, ' ').trim();
|
|
90
|
+
return serializeDataTable(withCellSet(grid, row, column, cell), alignments);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=table-cell-edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/besigner/feature/designer/src/lib/utils/table-cell-edit.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as Aglyn from '@aglyn/aglyn'\nimport { FieldComponentType } from '@aglyn/aglyn'\nimport {\n parseDataTableRows,\n readDataTableAlignments,\n serializeDataTable,\n withCellSet,\n} from '@aglyn/shared-data-enums'\n\n/**\n * In-place editing of one Table cell on the canvas.\n *\n * The Table element stores its whole grid as ONE string attribute (see\n * `@aglyn/shared-data-enums`'s `data-table`), so a cell is not a canvas node\n * and has no `children` of its own to edit. A double-click on a cell opens\n * the same in-place text editor every text element uses, anchored on the\n * cell, and the commit rewrites that one cell inside the stored string —\n * through the same parser and serializer the attributes-panel grid uses, so\n * the two surfaces can never disagree about what a table string means.\n */\n\n/**\n * The attribute holding the grid, or `undefined` when the component declares\n * none. Keyed on the schema's own `DATA_TABLE` field declaration — the same\n * declaration that gives the attributes panel its grid — rather than on a\n * component id, so any element that stores a grid this way is editable on\n * the canvas too.\n */\nexport function findDataTableAttributeName(\n node: Aglyn.NodeSchema<any> | undefined,\n): string | undefined {\n for (const attribute of node?.componentSchema?.attributes ?? []) {\n if (attribute?.component === FieldComponentType.DATA_TABLE) {\n return attribute.name\n }\n }\n return undefined\n}\n\n/** The cell a point falls in, and where it sits in the stored grid. */\nexport interface DataTableCellHit {\n element: HTMLElement\n /** Row in the parsed grid — the header row, when there is one, is row 0. */\n row: number\n column: number\n}\n\n/**\n * The rendered cell under a client point inside `root`, if any.\n *\n * Geometric rather than `elementFromPoint`, for the reason instance leaves\n * are hit-tested that way: the canvas is a closed shadow root and the point\n * may come from a touch, so the event target is not something to rely on.\n *\n * The grid row is the cell's `<tr>` index across the whole table. The\n * renderer draws exactly one `<tr>` per parsed row, header included, so the\n * two indexes are the same thing.\n */\nexport function findDataTableCellAtPoint(\n root: Element,\n clientX: number,\n clientY: number,\n): DataTableCellHit | undefined {\n const rows = Array.from(root.querySelectorAll('tr'))\n for (let row = 0; row < rows.length; row++) {\n const cells = Array.from(rows[row].children).filter(\n (cell): cell is HTMLElement =>\n cell.tagName === 'TD' || cell.tagName === 'TH',\n )\n for (let column = 0; column < cells.length; column++) {\n const rect = cells[column].getBoundingClientRect()\n if (\n clientX >= rect.left &&\n clientX <= rect.right &&\n clientY >= rect.top &&\n clientY <= rect.bottom\n ) {\n return { element: cells[column], row, column }\n }\n }\n }\n return undefined\n}\n\n/** The text a stored grid holds at one cell, or `''` when it is outside it. */\nexport function readDataTableCell(\n value: unknown,\n row: number,\n column: number,\n): string {\n return parseDataTableRows(value)[row]?.[column] ?? ''\n}\n\n/**\n * The stored grid with one cell replaced.\n *\n * A cell is one line — the storage is one row per line — so a line break\n * typed into the cell becomes a space instead of splitting the row. Column\n * alignments survive: they ride the same string as a divider row, and are\n * read back out and written again with the grid.\n */\nexport function writeDataTableCell(\n value: unknown,\n row: number,\n column: number,\n text: string,\n): string {\n const grid = parseDataTableRows(value)\n const width = grid[0]?.length ?? 0\n const alignments = readDataTableAlignments(value, width)\n const cell = text.replace(/\\s*\\r?\\n\\s*/g, ' ').trim()\n return serializeDataTable(withCellSet(grid, row, column, cell), alignments)\n}\n"],"names":["FieldComponentType","parseDataTableRows","readDataTableAlignments","serializeDataTable","withCellSet","findDataTableAttributeName","node","attribute","componentSchema","attributes","component","DATA_TABLE","name","undefined","findDataTableCellAtPoint","root","clientX","clientY","rows","Array","from","querySelectorAll","row","length","cells","children","filter","cell","tagName","column","rect","getBoundingClientRect","left","right","top","bottom","element","readDataTableCell","value","writeDataTableCell","text","grid","width","alignments","replace","trim"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,kBAAkB,QAAQ,eAAc;AACjD,SACEC,kBAAkB,EAClBC,uBAAuB,EACvBC,kBAAkB,EAClBC,WAAW,QACN,2BAA0B;AAEjC;;;;;;;;;;CAUC,GAED;;;;;;CAMC,GACD,OAAO,SAASC,2BACdC,IAAuC;;QAEfA;IAAxB,KAAK,MAAMC,qBAAaD,yBAAAA,wBAAAA,KAAME,eAAe,qBAArBF,sBAAuBG,UAAU,mBAAI,EAAE,CAAE;QAC/D,IAAIF,CAAAA,6BAAAA,UAAWG,SAAS,MAAKV,mBAAmBW,UAAU,EAAE;YAC1D,OAAOJ,UAAUK,IAAI;QACvB;IACF;IACA,OAAOC;AACT;AAUA;;;;;;;;;;CAUC,GACD,OAAO,SAASC,yBACdC,IAAa,EACbC,OAAe,EACfC,OAAe;IAEf,MAAMC,OAAOC,MAAMC,IAAI,CAACL,KAAKM,gBAAgB,CAAC;IAC9C,IAAK,IAAIC,MAAM,GAAGA,MAAMJ,KAAKK,MAAM,EAAED,MAAO;QAC1C,MAAME,QAAQL,MAAMC,IAAI,CAACF,IAAI,CAACI,IAAI,CAACG,QAAQ,EAAEC,MAAM,CACjD,CAACC,OACCA,KAAKC,OAAO,KAAK,QAAQD,KAAKC,OAAO,KAAK;QAE9C,IAAK,IAAIC,SAAS,GAAGA,SAASL,MAAMD,MAAM,EAAEM,SAAU;YACpD,MAAMC,OAAON,KAAK,CAACK,OAAO,CAACE,qBAAqB;YAChD,IACEf,WAAWc,KAAKE,IAAI,IACpBhB,WAAWc,KAAKG,KAAK,IACrBhB,WAAWa,KAAKI,GAAG,IACnBjB,WAAWa,KAAKK,MAAM,EACtB;gBACA,OAAO;oBAAEC,SAASZ,KAAK,CAACK,OAAO;oBAAEP;oBAAKO;gBAAO;YAC/C;QACF;IACF;IACA,OAAOhB;AACT;AAEA,6EAA6E,GAC7E,OAAO,SAASwB,kBACdC,KAAc,EACdhB,GAAW,EACXO,MAAc;;QAEP5B;IAAP,gBAAOA,0BAAAA,mBAAmBqC,MAAM,CAAChB,IAAI,qBAA9BrB,uBAAgC,CAAC4B,OAAO,mBAAI;AACrD;AAEA;;;;;;;CAOC,GACD,OAAO,SAASU,mBACdD,KAAc,EACdhB,GAAW,EACXO,MAAc,EACdW,IAAY;;QAGEC;IADd,MAAMA,OAAOxC,mBAAmBqC;IAChC,MAAMI,iBAAQD,SAAAA,IAAI,CAAC,EAAE,qBAAPA,OAASlB,MAAM,mBAAI;IACjC,MAAMoB,aAAazC,wBAAwBoC,OAAOI;IAClD,MAAMf,OAAOa,KAAKI,OAAO,CAAC,gBAAgB,KAAKC,IAAI;IACnD,OAAO1C,mBAAmBC,YAAYqC,MAAMnB,KAAKO,QAAQF,OAAOgB;AAClE"}
|