@motifx-community/ui 0.1.0-beta.16 → 0.1.0-beta.18

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.
Files changed (234) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/components/datagrid/DataGrid.d.ts +2 -1
  3. package/dist/components/datagrid/grid-column.d.ts +6 -0
  4. package/dist/components/datagrid/model/ColumnModel.d.ts +2 -0
  5. package/dist/components/datagrid/model/GridModel.d.ts +4 -0
  6. package/dist/components/datagrid/view/ColumnStyles.d.ts +7 -3
  7. package/dist/components/datagrid/view/GridBody.d.ts +56 -4
  8. package/dist/components/diagram/Diagram.d.ts +92 -0
  9. package/dist/components/diagram/DiagramEdgeView.d.ts +14 -4
  10. package/dist/components/diagram/DiagramLinks.d.ts +2 -0
  11. package/dist/components/diagram/DiagramNodeView.d.ts +19 -1
  12. package/dist/components/diagram/diagram-change.d.ts +3 -2
  13. package/dist/components/diagram/diagram-edge-click-event-args.d.ts +21 -0
  14. package/dist/components/diagram/diagram-edge-pointer-event-args.d.ts +6 -0
  15. package/dist/components/diagram/diagram-edge.d.ts +8 -0
  16. package/dist/components/diagram/diagram-links-host.d.ts +3 -0
  17. package/dist/components/diagram/diagram-node-click-event-args.d.ts +23 -0
  18. package/dist/components/diagram/diagram-node-context.d.ts +5 -0
  19. package/dist/components/diagram/diagram-node-host.d.ts +4 -0
  20. package/dist/components/diagram/diagram-node-pointer-event-args.d.ts +6 -0
  21. package/dist/components/diagram/diagram-props.d.ts +45 -0
  22. package/dist/components/diagram/diagram-text-changed-event-args.d.ts +7 -0
  23. package/dist/components/diagram/diagram-text-changing-event-args.d.ts +14 -0
  24. package/dist/components/diagram/diagram-text-editing-event-args.d.ts +11 -0
  25. package/dist/components/diagram/index.d.ts +7 -0
  26. package/dist/core/ui-strings.d.ts +5 -0
  27. package/dist/excel/index.js +1 -1
  28. package/dist/excel/index.js.map +1 -1
  29. package/dist/index.js +1644 -759
  30. package/dist/index.js.map +1 -1
  31. package/dist/locales/en.json +3 -0
  32. package/dist/locales/tr.json +3 -0
  33. package/dist/parts/table/RowHeights.d.ts +23 -0
  34. package/dist/parts/table/ScrollGeometry.d.ts +6 -1
  35. package/dist/parts/table/table-sheet-column.d.ts +2 -0
  36. package/dist/pdf/index.js +1 -1
  37. package/dist/pdf/index.js.map +1 -1
  38. package/dist/pdf/pdf-export-options.d.ts +4 -1
  39. package/dist/styles.css +58 -0
  40. package/dist/{tr-4GNbFdQh.js → tr-CMuuXBUb.js} +8 -2
  41. package/dist/{tr-4GNbFdQh.js.map → tr-CMuuXBUb.js.map} +1 -1
  42. package/docs/accordion.md +1 -1
  43. package/docs/actionsheet.md +1 -1
  44. package/docs/appbar.md +1 -1
  45. package/docs/appmenu-api.md +1 -1
  46. package/docs/appmenu-programmatic.md +1 -1
  47. package/docs/appmenu-search.md +1 -1
  48. package/docs/appmenu.md +1 -1
  49. package/docs/avatar.md +1 -1
  50. package/docs/badge.md +1 -1
  51. package/docs/bar-gauge-angles.md +1 -1
  52. package/docs/bar-gauge-data.md +1 -1
  53. package/docs/bar-gauge-labels.md +1 -1
  54. package/docs/bar-gauge.md +1 -1
  55. package/docs/barcode.md +1 -1
  56. package/docs/bottomnavigation.md +1 -1
  57. package/docs/bottomsheet.md +1 -1
  58. package/docs/breadcrumb.md +1 -1
  59. package/docs/button.md +1 -1
  60. package/docs/buttongroup.md +1 -1
  61. package/docs/buttons.md +1 -1
  62. package/docs/calendar.md +1 -1
  63. package/docs/card.md +1 -1
  64. package/docs/chart-bars.md +1 -1
  65. package/docs/chart-candles.md +1 -1
  66. package/docs/chart-funnel.md +1 -1
  67. package/docs/chart-heatmap.md +1 -1
  68. package/docs/chart-lines.md +1 -1
  69. package/docs/chart-live.md +1 -1
  70. package/docs/chart-pie.md +1 -1
  71. package/docs/chart-radar.md +1 -1
  72. package/docs/chart-ranges.md +1 -1
  73. package/docs/chart-references.md +1 -1
  74. package/docs/chart-scatter.md +1 -1
  75. package/docs/chart-waterfall.md +1 -1
  76. package/docs/chart-zoom.md +1 -1
  77. package/docs/chart.md +1 -1
  78. package/docs/chat.md +1 -1
  79. package/docs/checkbox.md +1 -1
  80. package/docs/chip.md +1 -1
  81. package/docs/choice.md +1 -1
  82. package/docs/colorbox.md +1 -1
  83. package/docs/combobox.md +1 -1
  84. package/docs/commands.md +1 -1
  85. package/docs/control.md +1 -1
  86. package/docs/data.md +1 -1
  87. package/docs/datagrid-api.md +3 -2
  88. package/docs/datagrid-bands.md +1 -1
  89. package/docs/datagrid-drag-select.md +1 -1
  90. package/docs/datagrid-drag.md +1 -1
  91. package/docs/datagrid-editing.md +1 -1
  92. package/docs/datagrid-filtering.md +1 -1
  93. package/docs/datagrid-forms.md +1 -1
  94. package/docs/datagrid-grouping.md +1 -1
  95. package/docs/datagrid-layout.md +1 -1
  96. package/docs/datagrid-lookups.md +1 -1
  97. package/docs/datagrid-master-detail.md +1 -1
  98. package/docs/datagrid-scrolling.md +77 -1
  99. package/docs/datagrid-selection.md +1 -1
  100. package/docs/datagrid.md +1 -1
  101. package/docs/datebox.md +1 -1
  102. package/docs/daterangebox.md +1 -1
  103. package/docs/diagram-api.md +19 -4
  104. package/docs/diagram-commands.md +2 -1
  105. package/docs/diagram-connections.md +8 -6
  106. package/docs/diagram-custom-nodes.md +1 -1
  107. package/docs/diagram-designer.md +1 -1
  108. package/docs/diagram-editing.md +132 -5
  109. package/docs/diagram-flow.md +21 -4
  110. package/docs/diagram-keyboard.md +5 -1
  111. package/docs/diagram-layout.md +1 -1
  112. package/docs/diagram-nodes.md +1 -1
  113. package/docs/diagram-tables.md +1 -1
  114. package/docs/diagram.md +11 -8
  115. package/docs/display.md +1 -1
  116. package/docs/draggable.md +1 -1
  117. package/docs/drawer.md +1 -1
  118. package/docs/dropdown.md +1 -1
  119. package/docs/editors.md +1 -1
  120. package/docs/expressioneditor.md +1 -1
  121. package/docs/expressions.md +1 -1
  122. package/docs/feedback.md +1 -1
  123. package/docs/fileuploader.md +1 -1
  124. package/docs/filterbuilder.md +1 -1
  125. package/docs/formlayout-schema.md +1 -1
  126. package/docs/formlayout.md +1 -1
  127. package/docs/foundations.md +1 -1
  128. package/docs/gallery.md +1 -1
  129. package/docs/gauge-base.md +1 -1
  130. package/docs/gauge-circular.md +1 -1
  131. package/docs/gauge-dashboards.md +1 -1
  132. package/docs/gauge-linear.md +1 -1
  133. package/docs/gauge-markers.md +1 -1
  134. package/docs/gauge-marks.md +1 -1
  135. package/docs/gauge-ranges.md +1 -1
  136. package/docs/gauge-scales.md +1 -1
  137. package/docs/gauge.md +1 -1
  138. package/docs/home.md +1 -1
  139. package/docs/keyboard.md +1 -1
  140. package/docs/language.md +1 -1
  141. package/docs/layout.md +1 -1
  142. package/docs/listbox.md +1 -1
  143. package/docs/loadpanel.md +1 -1
  144. package/docs/lookup.md +1 -1
  145. package/docs/markdown.md +1 -1
  146. package/docs/menus-api.md +1 -1
  147. package/docs/menus-context.md +1 -1
  148. package/docs/menus-customization.md +1 -1
  149. package/docs/menus-merging.md +1 -1
  150. package/docs/menus-programmatic.md +1 -1
  151. package/docs/menus.md +1 -1
  152. package/docs/multiview.md +1 -1
  153. package/docs/navigation.md +1 -1
  154. package/docs/numberbox.md +1 -1
  155. package/docs/otpinput.md +1 -1
  156. package/docs/pagination.md +1 -1
  157. package/docs/pivotgrid-api.md +1 -1
  158. package/docs/pivotgrid-chart.md +1 -1
  159. package/docs/pivotgrid-drilldown.md +1 -1
  160. package/docs/pivotgrid-export.md +1 -1
  161. package/docs/pivotgrid-fields.md +1 -1
  162. package/docs/pivotgrid-keyboard.md +1 -1
  163. package/docs/pivotgrid-layout.md +1 -1
  164. package/docs/pivotgrid-panel.md +1 -1
  165. package/docs/pivotgrid-remote.md +1 -1
  166. package/docs/pivotgrid-sorting.md +1 -1
  167. package/docs/pivotgrid-state.md +1 -1
  168. package/docs/pivotgrid-summaries.md +1 -1
  169. package/docs/pivotgrid.md +1 -1
  170. package/docs/popover.md +1 -1
  171. package/docs/progress.md +1 -1
  172. package/docs/qrcode.md +1 -1
  173. package/docs/radiogroup.md +1 -1
  174. package/docs/rating.md +1 -1
  175. package/docs/resizable.md +1 -1
  176. package/docs/ribbonmenu-api.md +1 -1
  177. package/docs/ribbonmenu-commands.md +1 -1
  178. package/docs/ribbonmenu-customization.md +1 -1
  179. package/docs/ribbonmenu-display.md +1 -1
  180. package/docs/ribbonmenu-layouts.md +1 -1
  181. package/docs/ribbonmenu-programmatic.md +1 -1
  182. package/docs/ribbonmenu.md +1 -1
  183. package/docs/scheduler-agenda.md +1 -1
  184. package/docs/scheduler-big-data.md +1 -1
  185. package/docs/scheduler-editing.md +1 -1
  186. package/docs/scheduler-form.md +1 -1
  187. package/docs/scheduler-icalendar.md +1 -1
  188. package/docs/scheduler-mobile.md +1 -1
  189. package/docs/scheduler-recurrence.md +1 -1
  190. package/docs/scheduler-resources.md +1 -1
  191. package/docs/scheduler-timeline.md +1 -1
  192. package/docs/scheduler.md +1 -1
  193. package/docs/scrollview.md +1 -1
  194. package/docs/shortcuteditor.md +1 -1
  195. package/docs/showcase-flowstudio.md +1 -1
  196. package/docs/showcase-home.md +1 -1
  197. package/docs/showcase-mail.md +1 -1
  198. package/docs/showcase.md +1 -1
  199. package/docs/signature.md +1 -1
  200. package/docs/skeleton.md +1 -1
  201. package/docs/slider.md +1 -1
  202. package/docs/sortable.md +1 -1
  203. package/docs/sparkline.md +1 -1
  204. package/docs/speeddial.md +1 -1
  205. package/docs/splitter.md +1 -1
  206. package/docs/stepper.md +1 -1
  207. package/docs/switch.md +1 -1
  208. package/docs/tabdocs-dock.md +1 -1
  209. package/docs/tabdocs-drag.md +1 -1
  210. package/docs/tabdocs-menus.md +1 -1
  211. package/docs/tabdocs-mobile.md +1 -1
  212. package/docs/tabdocs-tabs.md +1 -1
  213. package/docs/tabdocs-windows.md +1 -1
  214. package/docs/tabdocs-workspace.md +1 -1
  215. package/docs/tabdocs.md +1 -1
  216. package/docs/tabs.md +1 -1
  217. package/docs/tagbox.md +1 -1
  218. package/docs/textarea.md +1 -1
  219. package/docs/textbox.md +1 -1
  220. package/docs/tileview.md +1 -1
  221. package/docs/timeline.md +1 -1
  222. package/docs/toast.md +1 -1
  223. package/docs/tokens.md +1 -1
  224. package/docs/toolbar-api.md +1 -1
  225. package/docs/toolbar-customization.md +1 -1
  226. package/docs/toolbar.md +1 -1
  227. package/docs/tooltip.md +1 -1
  228. package/docs/treeview.md +1 -1
  229. package/docs/validationsummary.md +1 -1
  230. package/docs/window.md +1 -1
  231. package/docs/wizard.md +1 -1
  232. package/llms-full.txt +460 -214
  233. package/llms.txt +1 -1
  234. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -300,7 +300,7 @@ function pendingScroll(component) {
300
300
  //#endregion
301
301
  //#region src/core/measure/scroll-memory.ts
302
302
  var known$1 = /* @__PURE__ */ new WeakMap();
303
- var heard = /* @__PURE__ */ new WeakSet();
303
+ var heard$1 = /* @__PURE__ */ new WeakSet();
304
304
  /** Elements scrolled and not read yet, and the ones of each window that wait for its next frame. */
305
305
  var unread = /* @__PURE__ */ new WeakSet();
306
306
  var waiting$2 = /* @__PURE__ */ new WeakMap();
@@ -310,8 +310,8 @@ var AT_START = {
310
310
  };
311
311
  /** Notes from now on how far the elements of `view` are scrolled. */
312
312
  function rememberScrolls(view) {
313
- if (heard.has(view)) return;
314
- heard.add(view);
313
+ if (heard$1.has(view)) return;
314
+ heard$1.add(view);
315
315
  onDocument(view.document, "scroll", (e) => {
316
316
  const el = e.target;
317
317
  if (!isElement(el)) return;
@@ -3295,6 +3295,7 @@ var en_exports = /* @__PURE__ */ __exportAll({
3295
3295
  diagramDuplicate: () => diagramDuplicate,
3296
3296
  diagramEdgeIs: () => diagramEdgeIs,
3297
3297
  diagramEdgeLabelIs: () => diagramEdgeLabelIs,
3298
+ diagramEdgeName: () => diagramEdgeName,
3298
3299
  diagramEndsFixed: () => diagramEndsFixed,
3299
3300
  diagramExpand: () => diagramExpand,
3300
3301
  diagramFit: () => diagramFit,
@@ -3318,6 +3319,7 @@ var en_exports = /* @__PURE__ */ __exportAll({
3318
3319
  diagramReconnected: () => diagramReconnected,
3319
3320
  diagramRedo: () => diagramRedo,
3320
3321
  diagramRedone: () => diagramRedone,
3322
+ diagramRename: () => diagramRename,
3321
3323
  diagramReshaped: () => diagramReshaped,
3322
3324
  diagramResized: () => diagramResized,
3323
3325
  diagramRole: () => diagramRole,
@@ -3329,6 +3331,7 @@ var en_exports = /* @__PURE__ */ __exportAll({
3329
3331
  diagramStatusSaid: () => diagramStatusSaid,
3330
3332
  diagramStatusSkipped: () => diagramStatusSkipped,
3331
3333
  diagramStatusWaiting: () => diagramStatusWaiting,
3334
+ diagramTextEditor: () => diagramTextEditor,
3332
3335
  diagramUndo: () => diagramUndo,
3333
3336
  diagramUndone: () => diagramUndone,
3334
3337
  diagramZoomIn: () => diagramZoomIn,
@@ -5219,6 +5222,9 @@ var diagramStatusError = "Failed";
5219
5222
  var diagramStatusWaiting = "Waiting";
5220
5223
  var diagramStatusSkipped = "Skipped";
5221
5224
  var diagramStatusSaid = "{name}: {status}.";
5225
+ var diagramEdgeName = "Connection from {source} to {target}";
5226
+ var diagramRename = "Rename";
5227
+ var diagramTextEditor = "Text of {name}";
5222
5228
  var expressionEditorSuggestions = "Suggestions";
5223
5229
  var expressionProblemUnexpectedEnd = "The expression ends too soon: {expected} is missing.";
5224
5230
  var expressionProblemUnexpectedToken = "{found} was not expected here; {expected} was.";
@@ -6344,6 +6350,9 @@ var en_default = {
6344
6350
  diagramStatusWaiting,
6345
6351
  diagramStatusSkipped,
6346
6352
  diagramStatusSaid,
6353
+ diagramEdgeName,
6354
+ diagramRename,
6355
+ diagramTextEditor,
6347
6356
  expressionEditorSuggestions,
6348
6357
  expressionProblemUnexpectedEnd,
6349
6358
  expressionProblemUnexpectedToken,
@@ -6645,7 +6654,7 @@ function startLocale() {
6645
6654
  */
6646
6655
  var uiLocale = new UiLocale(enStrings, (language) => _rolldown_dynamic_import_helper_default(/* #__PURE__ */ Object.assign({
6647
6656
  "../locales/en.json": () => Promise.resolve().then(() => en_exports),
6648
- "../locales/tr.json": () => import("./tr-4GNbFdQh.js")
6657
+ "../locales/tr.json": () => import("./tr-CMuuXBUb.js")
6649
6658
  }), `../locales/${language}.json`, 3), startLocale());
6650
6659
  //#endregion
6651
6660
  //#region src/core/access-key.ts
@@ -53673,6 +53682,11 @@ var ColumnModel = class {
53673
53682
  const def = this.get(field);
53674
53683
  return def.align ?? (def.type === "number" ? "end" : def.type === "boolean" ? "center" : "start");
53675
53684
  }
53685
+ /** Whether the text of the column's cells wraps onto more lines (`wrap`); the grid's own columns never do. */
53686
+ wraps(field) {
53687
+ this.state.revision;
53688
+ return !this.isInternal(field) && !!readField$1(this.get(field), "wrap");
53689
+ }
53676
53690
  /** Where a band's caption sits: its own, else the `bandAlign` setting. */
53677
53691
  bandAlign(id) {
53678
53692
  return readField$1(this.bands.get(id)?.def, "align") ?? this.settings.get("bandAlign");
@@ -60670,6 +60684,12 @@ var GridModel = class {
60670
60684
  exporting: false,
60671
60685
  acting: false
60672
60686
  }));
60687
+ _defineProperty(
60688
+ this,
60689
+ /** Set when the grid is disposed: a wait for the rows ends with it. */
60690
+ "life",
60691
+ reactive({ over: false })
60692
+ );
60673
60693
  _defineProperty(
60674
60694
  this,
60675
60695
  /** The new-row area, in display order. */
@@ -61153,6 +61173,11 @@ var GridModel = class {
61153
61173
  else if (!this.loadMore()) break;
61154
61174
  return same() && data.total >= Math.min(rows, data.knownCount ?? rows);
61155
61175
  }
61176
+ /** Resolves once the rows the grid waits for have arrived, or failed to: `false` when the grid is disposed first. */
61177
+ async rowsLoaded() {
61178
+ await settled(() => this.life.over || this.state.status !== "loading");
61179
+ return !this.life.over;
61180
+ }
61156
61181
  /** Infinite mode: what the indicator under the rows shows (`loadMoreIndicator`): a part loading, a part that failed, or nothing. Reactive. */
61157
61182
  moreState() {
61158
61183
  if (this.mode !== "infinite" || !this.settings.get("loadMoreIndicator")) return null;
@@ -62355,6 +62380,7 @@ var GridModel = class {
62355
62380
  });
62356
62381
  }
62357
62382
  dispose() {
62383
+ this.life.over = true;
62358
62384
  clearTimeout(this.filterTimer);
62359
62385
  for (const s of this.dataSubscriptions.splice(0)) s.dispose();
62360
62386
  this.events.dispose();
@@ -63982,6 +64008,7 @@ var GridExport = class {
63982
64008
  title: model.columns.title(fields[j]),
63983
64009
  width: options.widthOf(fields[j]),
63984
64010
  align: model.columns.align(fields[j]),
64011
+ wrap: model.columns.wraps(fields[j]) || void 0,
63985
64012
  numberFormat: column.type === "number" && !column.lookup ? formatter.numberOptions(column) : void 0,
63986
64013
  dateFormat: (column.type === "date" || column.type === "datetime") && !column.lookup ? formatter.dateOptions(column) : void 0
63987
64014
  })),
@@ -65208,8 +65235,9 @@ var ColumnMenu = class {
65208
65235
  //#endregion
65209
65236
  //#region src/components/datagrid/view/ColumnStyles.ts
65210
65237
  var escapeAttr = (v) => v.replace(/["\\]/g, "\\$&");
65238
+ var NO_WRAP = /* @__PURE__ */ new Set();
65211
65239
  /**
65212
- * Per-column CSS of one grid: columns not shown, the tracks of the columns pinned to the end, alignment and sticky offsets, written as rules keyed
65240
+ * Per-column CSS of one grid: columns not shown, the tracks of the columns pinned to the end, alignment, wrapping and sticky offsets, written as rules keyed
65213
65241
  * by `data-field` (a pinned band's header by `data-band`, at the offset of its columns). Changing a width or pinning a column rewrites this sheet only; no cell gets a
65214
65242
  * binding of its own and no row is touched. A rule finds the rows through the parts that hold them (the head, the body,
65215
65243
  * the foot, the copy of a dragged row), which carry the grid's id, and goes on by child combinators only: the rows of a
@@ -65235,11 +65263,20 @@ var ColumnStyles = class {
65235
65263
  this.columns = columns;
65236
65264
  this.gridId = gridId;
65237
65265
  }
65238
- /** `placed`: every column's cells get their track by number, so a row may leave out the cells of columns not drawn (virtual columns). */
65239
- update(visible, offsets, align, bands = [], placed = false) {
65266
+ /**
65267
+ * `placed`: every column's cells get their track by number, so a row may leave out the cells of columns not drawn (virtual
65268
+ * columns). `wrap`: the columns whose cells wrap their text; with any, a data row (in the body, and its copy while it is
65269
+ * dragged) is as tall as its tallest cell.
65270
+ */
65271
+ update(visible, offsets, align, bands = [], placed = false, wrap = NO_WRAP) {
65240
65272
  const rows = `[data-grid-id="${this.gridId}"] > .mx-data-grid__row`;
65241
65273
  const rules = [];
65242
65274
  const shown = new Set(visible);
65275
+ if (wrap.size) {
65276
+ const dataRows = `[data-grid-id="${this.gridId}"]:is(.mx-data-grid__body, .mx-data-grid__ghost-rows) > .mx-data-grid__row:not(.mx-data-grid__group-row, .mx-data-grid__group-footer)`;
65277
+ rules.push(`${dataRows}{block-size:auto;min-block-size:var(--_row-height)}`);
65278
+ rules.push(`${dataRows} > .mx-data-grid__cell{contain:size}`);
65279
+ }
65243
65280
  for (const field of this.columns.state.order) {
65244
65281
  const sel = `${rows} > [data-field="${escapeAttr(field)}"]`;
65245
65282
  if (!shown.has(field)) {
@@ -65254,6 +65291,7 @@ var ColumnStyles = class {
65254
65291
  rules.push(`${sel}.mx-data-grid__cell{text-align:${a}}`);
65255
65292
  rules.push(`${sel} > .mx-data-grid__title{text-align:${a}}`);
65256
65293
  }
65294
+ if (wrap.has(field)) rules.push(`${sel}.mx-data-grid__cell:not(.mx-data-grid__summary-cell){contain:inline-size;white-space:pre-line;overflow-wrap:anywhere;text-overflow:clip;line-height:var(--_wrap-line);padding-block:var(--_wrap-space)}`);
65257
65295
  if (sticky) {
65258
65296
  rules.push(`${sel}{position:sticky;inset-inline-${sticky.side}:${sticky.offset}px;z-index:var(--_z-sticky)}`);
65259
65297
  if (sticky.edge) rules.push(`${sel}{box-shadow:var(--_sticky-${sticky.side})}`);
@@ -66019,6 +66057,57 @@ var ExtraHeights = class {
66019
66057
  }
66020
66058
  };
66021
66059
  //#endregion
66060
+ //#region src/parts/table/RowHeights.ts
66061
+ /**
66062
+ * How much taller than the others some rows are (a column that wraps its text), by position among the rows laid out. A
66063
+ * row not measured yet counts as tall as every row. The sums before a position are kept in a Fenwick tree, so a row's
66064
+ * offset is found in a few steps however many rows there are, and a new measurement changes one entry only.
66065
+ */
66066
+ var RowHeights = class {
66067
+ constructor(size) {
66068
+ _defineProperty(this, "size", void 0);
66069
+ _defineProperty(this, "added", void 0);
66070
+ _defineProperty(this, "summed", void 0);
66071
+ _defineProperty(this, "taller", 0);
66072
+ _defineProperty(this, "sum", 0);
66073
+ this.size = size;
66074
+ this.added = new Float64Array(size);
66075
+ this.summed = new Float64Array(size + 1);
66076
+ }
66077
+ /** Whether any row is taller than the others. */
66078
+ get any() {
66079
+ return this.taller > 0;
66080
+ }
66081
+ /** What every row adds, together. */
66082
+ get total() {
66083
+ return this.sum;
66084
+ }
66085
+ /** Gives a position what it adds to the height every row has (0: as tall as the others). Returns whether it changed. */
66086
+ set(position, added) {
66087
+ if (position < 0 || position >= this.size) return false;
66088
+ const value = added > 0 ? added : 0;
66089
+ const before = this.added[position];
66090
+ if (value === before) return false;
66091
+ this.added[position] = value;
66092
+ if (before === 0) this.taller++;
66093
+ else if (value === 0) this.taller--;
66094
+ const diff = value - before;
66095
+ this.sum += diff;
66096
+ for (let i = position + 1; i <= this.size; i += i & -i) this.summed[i] += diff;
66097
+ return true;
66098
+ }
66099
+ /** What a position adds (0 out of range). */
66100
+ addedAt(position) {
66101
+ return position >= 0 && position < this.size ? this.added[position] : 0;
66102
+ }
66103
+ /** What the positions before `position` add. */
66104
+ before(position) {
66105
+ let sum = 0;
66106
+ for (let i = Math.min(Math.max(0, position), this.size); i > 0; i -= i & -i) sum += this.summed[i];
66107
+ return sum;
66108
+ }
66109
+ };
66110
+ //#endregion
66022
66111
  //#region src/parts/table/ScrollGeometry.ts
66023
66112
  var clamp$2 = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
66024
66113
  /**
@@ -66028,7 +66117,7 @@ var clamp$2 = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
66028
66117
  * placed relative to the scroll position, so the wheel and the keyboard still move row by row.
66029
66118
  */
66030
66119
  var ScrollGeometry = class ScrollGeometry {
66031
- constructor(total, rowHeight, viewport, max = ScrollGeometry.MAX_HEIGHT, tall = null, details = null, adaptive = null, tail = 0) {
66120
+ constructor(total, rowHeight, viewport, max = ScrollGeometry.MAX_HEIGHT, tall = null, details = null, adaptive = null, tail = 0, rows = null) {
66032
66121
  _defineProperty(this, "total", void 0);
66033
66122
  _defineProperty(this, "rowHeight", void 0);
66034
66123
  _defineProperty(this, "viewport", void 0);
@@ -66037,6 +66126,7 @@ var ScrollGeometry = class ScrollGeometry {
66037
66126
  _defineProperty(this, "details", void 0);
66038
66127
  _defineProperty(this, "adaptive", void 0);
66039
66128
  _defineProperty(this, "tail", void 0);
66129
+ _defineProperty(this, "rows", void 0);
66040
66130
  this.total = total;
66041
66131
  this.rowHeight = rowHeight;
66042
66132
  this.viewport = viewport;
@@ -66045,19 +66135,20 @@ var ScrollGeometry = class ScrollGeometry {
66045
66135
  this.details = details;
66046
66136
  this.adaptive = adaptive;
66047
66137
  this.tail = tail;
66138
+ this.rows = rows;
66048
66139
  }
66049
66140
  /** Height of all rows, and the room after them. */
66050
66141
  get contentHeight() {
66051
- return this.total * this.rowHeight + this.extraHeight + this.adaptiveBefore(this.total) + (this.details ? this.details.before(this.total) : 0) + this.tail;
66142
+ return this.total * this.rowHeight + this.extraHeight + this.adaptiveBefore(this.total) + (this.details ? this.details.before(this.total) : 0) + (this.rows ? this.rows.before(this.total) : 0) + this.tail;
66052
66143
  }
66053
66144
  /** Top of row `index` in the full content. */
66054
66145
  offsetOf(index) {
66055
66146
  const tall = this.tall;
66056
- return index * this.rowHeight + (tall && index > tall.at ? tall.extra : 0) + this.adaptiveBefore(index) + (this.details ? this.details.before(index) : 0);
66147
+ return index * this.rowHeight + (tall && index > tall.at ? tall.extra : 0) + this.adaptiveBefore(index) + (this.details ? this.details.before(index) : 0) + (this.rows ? this.rows.before(index) : 0);
66057
66148
  }
66058
66149
  /** Height of row `index` itself (the edit form when it stands for the row), without its details. */
66059
66150
  rowHeightOf(index) {
66060
- return this.rowHeight + (this.tall?.at === index ? this.tall.extra : 0);
66151
+ return this.rowHeight + (this.tall?.at === index ? this.tall.extra : 0) + (this.rows ? this.rows.addedAt(index) : 0);
66061
66152
  }
66062
66153
  /** Height of the adaptive detail under row `index` (0 when it has none open). */
66063
66154
  adaptiveAt(index) {
@@ -66070,7 +66161,7 @@ var ScrollGeometry = class ScrollGeometry {
66070
66161
  /** The row at an offset in the full content (a row's details count as the row). */
66071
66162
  indexAt(offset) {
66072
66163
  const tall = this.tall;
66073
- if (this.details?.size || this.adaptive) return this.search(offset);
66164
+ if (this.details?.size || this.adaptive || this.rows?.any) return this.search(offset);
66074
66165
  if (!tall || offset < (tall.at + 1) * this.rowHeight) return Math.floor(offset / this.rowHeight);
66075
66166
  if (offset < (tall.at + 1) * this.rowHeight + tall.extra) return tall.at;
66076
66167
  return Math.floor((offset - tall.extra) / this.rowHeight);
@@ -67677,7 +67768,11 @@ var grids = /* @__PURE__ */ new Set();
67677
67768
  * detail of the one row that has it open (the columns the width hides) is a detail row too, right
67678
67769
  * under its row and before its details. The viewport is read with the measuring layer: a layout asked for
67679
67770
  * runs at once with the viewport as last read (and as the body scrolled it), and again with the next round
67680
- * if the viewport turns out to be elsewhere; the sizes of details and of the edit form are watched.
67771
+ * if the viewport turns out to be elsewhere; the sizes of details and of the edit form are watched. While a
67772
+ * column wraps its text, a data row is as tall as its cells: the rows drawn are measured in the round after
67773
+ * they are laid out, before the screen is drawn, and again when one changes size; what they add over the
67774
+ * rows' height is kept by position (`RowHeights`), and the first row in view stays where it stood when the
67775
+ * rows above it come out taller or shorter.
67681
67776
  */
67682
67777
  var GridBody = class extends Component {
67683
67778
  constructor(grid, viewport, widths, host) {
@@ -67833,6 +67928,74 @@ var GridBody = class extends Component {
67833
67928
  "dropRow",
67834
67929
  null
67835
67930
  );
67931
+ _defineProperty(
67932
+ this,
67933
+ /** Whether a column wraps its text: data rows are as tall as their cells, measured as they are drawn. */
67934
+ "wrapping",
67935
+ false
67936
+ );
67937
+ _defineProperty(
67938
+ this,
67939
+ /** The columns and widths the rows were measured for. */
67940
+ "wrapFor",
67941
+ ""
67942
+ );
67943
+ _defineProperty(
67944
+ this,
67945
+ /** What the rows laid out add over the rows' height, and the rows and height that was found for. */
67946
+ "heights",
67947
+ null
67948
+ );
67949
+ _defineProperty(this, "heightsFor", "");
67950
+ _defineProperty(
67951
+ this,
67952
+ /** The size watches of the pooled rows, while rows are measured. */
67953
+ "rowWatches",
67954
+ /* @__PURE__ */ new Map()
67955
+ );
67956
+ _defineProperty(
67957
+ this,
67958
+ /**
67959
+ * The row kept in place after the last layout, the first in view or the one `reveal` brought in: its position, its id,
67960
+ * how far below the top of the view its top (or its bottom, `edge`) stood, and the scroll then.
67961
+ */
67962
+ "anchor",
67963
+ null
67964
+ );
67965
+ _defineProperty(
67966
+ this,
67967
+ /** The row `reveal` brought into view, at the edge it was brought to: kept there while rows are measured, until the view is scrolled. */
67968
+ "pinned",
67969
+ null
67970
+ );
67971
+ _defineProperty(
67972
+ this,
67973
+ /** The heights of the data rows drawn, read after they were laid out. */
67974
+ "readHeights",
67975
+ () => {
67976
+ const out = [];
67977
+ for (const row of this.byIndex.values()) if (row.row !== void 0) out.push([row, boxOf(row.part).offsetHeight]);
67978
+ return out;
67979
+ }
67980
+ );
67981
+ _defineProperty(
67982
+ this,
67983
+ /** Rows that came out another height: the rows are laid out again, the first row in view where it stood. */
67984
+ "writeHeights",
67985
+ (read) => {
67986
+ const heights = this.wrapping ? this.rowHeights() : null;
67987
+ if (!heights || !this.isBuilt) return;
67988
+ const grid = this.grid;
67989
+ const base = grid.state.rowHeight;
67990
+ let changed = false;
67991
+ for (const [row, height] of read) {
67992
+ if (height <= 0 || row.index < 0 || row.row === void 0) continue;
67993
+ const l = grid.mode !== "paged" ? row.index : grid.localOf(row.index);
67994
+ if (heights.set(l, height - base)) changed = true;
67995
+ }
67996
+ if (changed) this.layoutSoon();
67997
+ }
67998
+ );
67836
67999
  _defineProperty(this, "readView", () => {
67837
68000
  const vp = this.scroller();
67838
68001
  if (!vp) return null;
@@ -67878,8 +68041,10 @@ var GridBody = class extends Component {
67878
68041
  if (scrollTop === null || !wanted || !vp) return;
67879
68042
  const local = this.grid.localOf(wanted.index);
67880
68043
  if (local < 0) return;
67881
- const top = this.geometry().revealRow(scrollTop, local, wanted.align);
68044
+ const g = this.geometry();
68045
+ const top = g.revealRow(scrollTop, local, wanted.align);
67882
68046
  if (top === scrollTop) return;
68047
+ this.pin(g, local, top);
67883
68048
  scrollTo(vp, { top });
67884
68049
  this.lastView = {
67885
68050
  ...this.lastView,
@@ -67924,15 +68089,19 @@ var GridBody = class extends Component {
67924
68089
  });
67925
68090
  this.motif.setDisposable(() => resolved.dispose());
67926
68091
  }
67927
- /** Geometry of the rows the body lays out (all rows, or one page); the edit form's row is as tall as the form, open details and the adaptive detail add their height. */
68092
+ /**
68093
+ * Geometry of the rows the body lays out (all rows, or one page); the edit form's row is as tall as the form, open details
68094
+ * and the adaptive detail add their height, and so do rows taller than the others while a column wraps.
68095
+ */
67928
68096
  geometry() {
67929
68097
  const grid = this.grid;
67930
68098
  const rowHeight = grid.state.rowHeight;
68099
+ const heights = this.rowHeights();
67931
68100
  const at = this.formIndex();
67932
68101
  const local = at < 0 ? -1 : grid.mode !== "paged" ? at : grid.localOf(at);
67933
68102
  const tall = local >= 0 && this.form ? {
67934
68103
  at: local,
67935
- extra: Math.max(0, this.form.height - rowHeight)
68104
+ extra: Math.max(0, this.form.height - rowHeight) - (heights ? heights.addedAt(local) : 0)
67936
68105
  } : null;
67937
68106
  const a = this.adaptiveLocal();
67938
68107
  const adaptive = a >= 0 ? {
@@ -67940,7 +68109,163 @@ var GridBody = class extends Component {
67940
68109
  height: this.adaptive?.id === grid.adaptive.state.rowId ? this.adaptive.height : 0
67941
68110
  } : null;
67942
68111
  const tail = grid.moreState() ? rowHeight : 0;
67943
- return new ScrollGeometry(grid.reachable(), rowHeight, Math.max(rowHeight, grid.state.viewport), ScrollGeometry.MAX_HEIGHT, tall, this.openExtras(), adaptive, tail);
68112
+ return new ScrollGeometry(grid.reachable(), rowHeight, Math.max(rowHeight, grid.state.viewport), ScrollGeometry.MAX_HEIGHT, tall, this.openExtras(), adaptive, tail, heights);
68113
+ }
68114
+ /**
68115
+ * Whether a column wraps its text, and the columns and widths that is for (`key`): with one, rows are measured as they
68116
+ * are drawn and when they change size; another key has the rows drawn measured again.
68117
+ */
68118
+ setWrap(on, key) {
68119
+ if (on === this.wrapping && key === this.wrapFor) return;
68120
+ const was = this.wrapping;
68121
+ this.wrapFor = key;
68122
+ if (!on && !was) return;
68123
+ this.wrapping = on;
68124
+ if (on) for (const row of this.pool) this.watchRow(row);
68125
+ else {
68126
+ for (const stop of this.rowWatches.values()) stop();
68127
+ this.rowWatches.clear();
68128
+ const anchor = this.anchor;
68129
+ this.heights = null;
68130
+ this.heightsFor = "";
68131
+ this.anchor = null;
68132
+ this.pinned = null;
68133
+ if (was && anchor) this.scrollToAnchor(anchor);
68134
+ }
68135
+ this.layoutSoon(true);
68136
+ }
68137
+ /** Scrolls so that a row noted in the view (`anchor`) stands where it stood, in the rows as they are now. */
68138
+ scrollToAnchor(anchor) {
68139
+ const vp = this.scroller();
68140
+ const g = this.geometry();
68141
+ if (!vp || anchor.local >= g.total) return;
68142
+ const edge = anchor.edge === "bottom" ? g.offsetOf(anchor.local) + g.rowHeightOf(anchor.local) : g.offsetOf(anchor.local);
68143
+ const want = Math.max(0, Math.min(g.maxVirtualTop, edge - anchor.screen));
68144
+ this.sizeSpacer(g);
68145
+ if (this.grid.mode !== "paged") {
68146
+ this.setVirtualTop(vp, g, want, true);
68147
+ return;
68148
+ }
68149
+ scrollTo(vp, { top: want });
68150
+ this.lastView = {
68151
+ ...this.lastView,
68152
+ top: want
68153
+ };
68154
+ if (this.seenScroll) this.seenScroll = {
68155
+ ...this.seenScroll,
68156
+ top: want
68157
+ };
68158
+ }
68159
+ /** What the rows laid out add over the rows' height while a column wraps; found again for other rows or another height. */
68160
+ rowHeights() {
68161
+ if (!this.wrapping) return null;
68162
+ return untracked(() => {
68163
+ const grid = this.grid;
68164
+ const st = grid.state;
68165
+ const n = grid.reachable();
68166
+ const same = `${st.version}|${st.connection}|${st.added}|${st.page}|${st.rowHeight}|${grid.mode}`;
68167
+ const key = `${same}|${n}`;
68168
+ if (this.heights && key === this.heightsFor) return this.heights;
68169
+ const was = this.heights;
68170
+ const kept = was !== null && this.heightsFor.startsWith(`${same}|`);
68171
+ this.heightsFor = key;
68172
+ this.heights = new RowHeights(n);
68173
+ if (kept) {
68174
+ for (let l = 0, end = Math.min(n, was.size); l < end; l++) if (was.addedAt(l)) this.heights.set(l, was.addedAt(l));
68175
+ }
68176
+ return this.heights;
68177
+ });
68178
+ }
68179
+ /** Watches a pooled row's size while rows are measured: a row that changes size (its content drawn again) is measured again. */
68180
+ watchRow(row) {
68181
+ if (this.rowWatches.has(row)) return;
68182
+ this.rowWatches.set(row, onLayout(row.part, "size", (size) => this.rowResized(row, size), { owner: this }));
68183
+ }
68184
+ /** A row drawn came out another size than it was measured at: the rows after it move, with the next round. */
68185
+ rowResized(row, size) {
68186
+ const heights = this.wrapping ? this.rowHeights() : null;
68187
+ const height = Math.round(size.height);
68188
+ if (!heights || this.isDisposed || height <= 0 || row.index < 0 || row.row === void 0) return;
68189
+ const l = this.grid.mode !== "paged" ? row.index : this.grid.localOf(row.index);
68190
+ if (heights.set(l, height - this.grid.state.rowHeight)) this.layoutSoon();
68191
+ }
68192
+ /**
68193
+ * While rows are measured, the first row in view stays where it stood when what the rows above it add changed (they were
68194
+ * measured, or found again), unless the view was scrolled since: returns the scroll the rows are laid out for.
68195
+ */
68196
+ keepAnchor(g, scrollTop) {
68197
+ const a = this.anchor;
68198
+ const vp = this.scroller();
68199
+ if (!a || !vp || scrollTop !== a.scrollTop) {
68200
+ if (a) this.pinned = null;
68201
+ return scrollTop;
68202
+ }
68203
+ const grid = this.grid;
68204
+ const paged = grid.mode === "paged";
68205
+ let l = a.local;
68206
+ if (a.rowId !== void 0 && grid.rowIdAt(paged ? grid.viewAt(l) : l) !== a.rowId) {
68207
+ const i = grid.indexOfKey(a.rowId);
68208
+ const found = i < 0 ? -1 : paged ? grid.localOf(i) : i;
68209
+ if (found >= 0) l = found;
68210
+ }
68211
+ if (l < 0 || l >= g.total) return scrollTop;
68212
+ if (this.pinned) this.pinned = {
68213
+ ...this.pinned,
68214
+ local: l
68215
+ };
68216
+ const edge = a.edge === "bottom" ? g.offsetOf(l) + g.rowHeightOf(l) : g.offsetOf(l);
68217
+ const want = Math.max(0, Math.min(g.maxVirtualTop, edge - a.screen));
68218
+ const now = paged ? scrollTop : this.virtualTop;
68219
+ if (Math.abs(want - now) < 1) return scrollTop;
68220
+ let top = want;
68221
+ if (!paged) {
68222
+ this.virtualTop = want;
68223
+ top = g.scrollFromVirtual(want);
68224
+ }
68225
+ scrollTo(vp, { top });
68226
+ this.lastView = {
68227
+ ...this.lastView,
68228
+ top
68229
+ };
68230
+ if (this.seenScroll) this.seenScroll = {
68231
+ ...this.seenScroll,
68232
+ top
68233
+ };
68234
+ return top;
68235
+ }
68236
+ /** Notes the row to keep where it stands (`keepAnchor`): the one `reveal` brought in, else the first that starts in view. */
68237
+ noteAnchor(g, scrollTop) {
68238
+ const grid = this.grid;
68239
+ const paged = grid.mode === "paged";
68240
+ const vt = paged ? scrollTop : this.virtualTop;
68241
+ const p = this.pinned && this.pinned.local < g.total ? this.pinned : null;
68242
+ let l = p ? p.local : g.total > 0 ? g.indexAt(vt) : -1;
68243
+ if (!p && l >= 0 && l < g.total - 1 && g.offsetOf(l) < vt) l++;
68244
+ if (l < 0) {
68245
+ this.anchor = null;
68246
+ return;
68247
+ }
68248
+ const edge = p?.edge ?? "top";
68249
+ const at = edge === "bottom" ? g.offsetOf(l) + g.rowHeightOf(l) : g.offsetOf(l);
68250
+ this.anchor = {
68251
+ local: l,
68252
+ rowId: grid.rowIdAt(paged ? grid.viewAt(l) : l),
68253
+ edge,
68254
+ screen: at - vt,
68255
+ scrollTop
68256
+ };
68257
+ }
68258
+ /** While rows are measured, a row `reveal` scrolled to stays at the edge it came to (`v`: the view's new top). */
68259
+ pin(g, local, v) {
68260
+ if (!this.wrapping) return;
68261
+ this.pinned = Math.abs(v - g.offsetOf(local)) < 1 ? {
68262
+ local,
68263
+ edge: "top"
68264
+ } : {
68265
+ local,
68266
+ edge: "bottom"
68267
+ };
68268
+ this.anchor = null;
67944
68269
  }
67945
68270
  /** The details drawn now, the adaptive detail among them, in grid order (a row's adaptive detail before its details). */
67946
68271
  drawnDetails() {
@@ -68216,7 +68541,9 @@ var GridBody = class extends Component {
68216
68541
  }
68217
68542
  const g = this.geometry();
68218
68543
  this.sizeSpacer(g);
68219
- this.setVirtualTop(vp, g, g.revealRow(this.virtualTop, index, align), true);
68544
+ const v = g.revealRow(this.virtualTop, index, align);
68545
+ if (v !== this.virtualTop) this.pin(g, index, v);
68546
+ this.setVirtualTop(vp, g, v, true);
68220
68547
  }
68221
68548
  /** Back to the first row (after a sort change); the rows follow with the next round. */
68222
68549
  toStart() {
@@ -68236,10 +68563,25 @@ var GridBody = class extends Component {
68236
68563
  };
68237
68564
  this.layoutSoon();
68238
68565
  }
68239
- /** Rows the viewport shows fully, for PageUp/PageDown. */
68240
- pageRows() {
68566
+ /**
68567
+ * Rows the viewport shows fully, for PageUp/PageDown: a screen of rows down (`down`) or up from grid row `from`, counted
68568
+ * by their heights while some are taller than the others.
68569
+ */
68570
+ pageRows(from = -1, down = true) {
68241
68571
  const g = this.geometry();
68242
- return Math.max(1, Math.floor(g.viewport / g.rowHeight) - 1);
68572
+ const even = Math.max(1, Math.floor(g.viewport / g.rowHeight) - 1);
68573
+ const grid = this.grid;
68574
+ const start = !g.rows?.any || from < 0 ? -1 : grid.mode !== "paged" ? from : grid.localOf(from);
68575
+ if (start < 0) return even;
68576
+ const step = down ? 1 : -1;
68577
+ let room = g.viewport - g.heightOf(start);
68578
+ let n = 0;
68579
+ for (let l = start + step; l >= 0 && l < g.total; l += step) {
68580
+ room -= g.heightOf(l);
68581
+ if (room < 0) break;
68582
+ n++;
68583
+ }
68584
+ return Math.max(1, n);
68243
68585
  }
68244
68586
  /** The pooled row that shows grid row `index`, if it is drawn. */
68245
68587
  rowAt(index) {
@@ -68474,7 +68816,7 @@ var GridBody = class extends Component {
68474
68816
  const data = grid.data;
68475
68817
  const g = this.geometry();
68476
68818
  const loading = grid.state.status === "loading";
68477
- const scrollTop = view.top;
68819
+ let scrollTop = view.top;
68478
68820
  let start;
68479
68821
  let end;
68480
68822
  let top;
@@ -68483,6 +68825,7 @@ var GridBody = class extends Component {
68483
68825
  if (this.expectedScrollTop < 0 || Math.abs(scrollTop - this.expectedScrollTop) > 1) this.virtualTop = g.virtualFromScroll(scrollTop);
68484
68826
  this.expectedScrollTop = -1;
68485
68827
  this.virtualTop = Math.max(0, Math.min(g.maxVirtualTop, this.virtualTop));
68828
+ if (this.wrapping) scrollTop = this.keepAnchor(g, scrollTop);
68486
68829
  const vis = g.visibleRange(this.virtualTop);
68487
68830
  const extra = Math.max(0, Math.floor(grid.settings.get("extraRows")));
68488
68831
  start = Math.max(0, vis.first - extra);
@@ -68497,6 +68840,7 @@ var GridBody = class extends Component {
68497
68840
  else if (end > start && dataOf(end) > dataOf(start)) data.ensure(Math.max(0, dataOf(start) - pre), dataOf(end) + pre, immediate);
68498
68841
  if (grid.mode === "infinite" && !loading && data.total - dataOf(vis.end) <= Math.max(0, grid.settings.get("loadMoreDistance")) + pre) grid.loadMore();
68499
68842
  } else {
68843
+ if (this.wrapping) scrollTop = this.keepAnchor(g, scrollTop);
68500
68844
  start = 0;
68501
68845
  end = g.total;
68502
68846
  top = (local) => g.offsetOf(local);
@@ -68587,6 +68931,10 @@ var GridBody = class extends Component {
68587
68931
  const under = i - row === .5 && drawn && adaptiveAt === row ? 2 : 1;
68588
68932
  put(part, "aria-rowindex", String(Number.isInteger(i) ? this.ariaRowIndex(i) : this.ariaRowIndex(row) + under));
68589
68933
  }
68934
+ if (this.wrapping) {
68935
+ this.noteAnchor(g, scrollTop);
68936
+ measure(this, this.readHeights, this.writeHeights);
68937
+ }
68590
68938
  }
68591
68939
  /**
68592
68940
  * Details under the rows that show theirs (made the first time); the others are parked, and those
@@ -68797,6 +69145,7 @@ var GridBody = class extends Component {
68797
69145
  this.controls.add(row.part);
68798
69146
  row.arrange(this.visible);
68799
69147
  this.pool.push(row);
69148
+ if (this.wrapping) this.watchRow(row);
68800
69149
  return row;
68801
69150
  }
68802
69151
  /** Gives a row's element an id of its own. */
@@ -72455,6 +72804,7 @@ var hasKeys = (o) => Object.keys(o).length > 0;
72455
72804
  var COLUMN_LOOK = [
72456
72805
  "title",
72457
72806
  "hidingPriority",
72807
+ "wrap",
72458
72808
  "resizeMode",
72459
72809
  "columnRenderingMode",
72460
72810
  "headerFilterInterval",
@@ -73303,10 +73653,12 @@ var DataGrid = class extends Control {
73303
73653
  * Opens a new row, as the "New row" button does: at the bottom (the grid moves to the end, and a
73304
73654
  * virtual list loads only the last block) or at the top, with the first cell a new row can fill in
73305
73655
  * edit mode. The row being edited is left first, and no row is added if it cannot be left. `values`
73306
- * fill the new row as if typed.
73656
+ * fill the new row as if typed. While the rows load (before the first of them arrive, or after the
73657
+ * sort changes), it waits for them; `false` if the grid is disposed first.
73307
73658
  */
73308
73659
  addRow(values) {
73309
73660
  const { model } = this;
73661
+ if (model.state.status === "loading") return model.rowsLoaded().then((ok) => ok ? this.addRow(values) : false);
73310
73662
  if (model.state.busy) return Promise.resolve(false);
73311
73663
  if (this.formEdit && !this.cancelForm(false)) return Promise.resolve(false);
73312
73664
  const pending = this.pendingInvalid;
@@ -75201,6 +75553,7 @@ var DataGrid = class extends Control {
75201
75553
  cols.template(visible),
75202
75554
  [...cols.stickyOffsets(visible)],
75203
75555
  visible.map((f) => cols.align(f)),
75556
+ visible.map((f) => cols.wraps(f)),
75204
75557
  cols.hasBands ? cols.shownBands(visible) : [],
75205
75558
  cols.anyVirtual(visible)
75206
75559
  ])];
@@ -75209,8 +75562,10 @@ var DataGrid = class extends Control {
75209
75562
  const visible = cols.visible();
75210
75563
  const align = /* @__PURE__ */ new Map();
75211
75564
  for (const f of visible) align.set(f, cols.align(f));
75565
+ const wrap = new Set(visible.filter((f) => cols.wraps(f)));
75212
75566
  if (this.shell) css(this.shell.vp, "--_columns", cols.template(visible));
75213
- this.styles.update(visible, cols.stickyOffsets(visible), align, cols.hasBands ? cols.shownBands(visible) : [], cols.anyVirtual(visible));
75567
+ this.styles.update(visible, cols.stickyOffsets(visible), align, cols.hasBands ? cols.shownBands(visible) : [], cols.anyVirtual(visible), wrap);
75568
+ this.body.setWrap(wrap.size > 0, `${visible.join("\n")}|${cols.template(visible)}|${[...wrap].join("\n")}`);
75214
75569
  });
75215
75570
  this.whenChanged(() => [model.columns.fitWidth(model.state.width).join("\n")], () => {
75216
75571
  const hidden = model.columns.fitWidth(model.state.width);
@@ -77505,7 +77860,7 @@ var DataGrid = class extends Control {
77505
77860
  return;
77506
77861
  }
77507
77862
  if (down ? !hasRows : row < 0) break;
77508
- row = down ? row < 0 ? first : model.stepRow(row, this.body.pageRows()) : model.stepRow(row, -this.body.pageRows());
77863
+ row = down ? row < 0 ? first : model.stepRow(row, this.body.pageRows(row, true)) : model.stepRow(row, -this.body.pageRows(row, false));
77509
77864
  break;
77510
77865
  }
77511
77866
  case "Enter":
@@ -77813,9 +78168,9 @@ var DataGrid = class extends Control {
77813
78168
  model.loadMore();
77814
78169
  break;
77815
78170
  case "pageDown":
77816
- row = model.stepRow(row, this.body.pageRows());
78171
+ row = model.stepRow(row, this.body.pageRows(row, true));
77817
78172
  break;
77818
- case "pageUp": row = model.stepRow(row, -this.body.pageRows());
78173
+ case "pageUp": row = model.stepRow(row, -this.body.pageRows(row, false));
77819
78174
  }
77820
78175
  e.preventDefault();
77821
78176
  if (row < 0) return true;
@@ -77833,7 +78188,7 @@ var DataGrid = class extends Control {
77833
78188
  const move = Object.keys(keys).find((name) => isChord(keys[name] ?? [], e));
77834
78189
  if (!move) return false;
77835
78190
  e.preventDefault();
77836
- const page = this.body.pageRows();
78191
+ const page = move === "pageDown" || move === "pageUp" ? this.body.pageRows(row, move === "pageDown") : 1;
77837
78192
  const to = model.stepRow(row, move === "down" ? 1 : move === "up" ? -1 : move === "pageDown" ? page : -page);
77838
78193
  if (to < 0) return true;
77839
78194
  this.extendSelection(row, to);
@@ -108098,6 +108453,10 @@ function rowSide(port) {
108098
108453
  const sides = typeof port.side === "string" ? [port.side] : port.side;
108099
108454
  return port.label && sides.length === 1 && (sides[0] === "left" || sides[0] === "right") ? sides[0] : null;
108100
108455
  }
108456
+ /** The rows of a side, in the order of their places. */
108457
+ function rowsOf(rows, side) {
108458
+ return [...rows.values()].filter((r) => r.side === side).sort((a, b) => a.at - b.at).map((r) => r.row);
108459
+ }
108101
108460
  /**
108102
108461
  * A kind of node to start one's own from: a header with an icon, the node's text as the title and a line under it, a
108103
108462
  * body of the kind's own, and a row for each port on the left or the right that has a `label`, the port beside its row,
@@ -108129,6 +108488,7 @@ function cardKind(options = {}) {
108129
108488
  const icon = part(header, "span", "mx-diagram__card-icon");
108130
108489
  const titles = part(header, "div", "mx-diagram__card-titles");
108131
108490
  const title = part(titles, "div", "mx-diagram__card-title");
108491
+ context.textPart(title);
108132
108492
  const subtitle = part(titles, "div", "mx-diagram__card-subtitle");
108133
108493
  let inner = null;
108134
108494
  if (options.body) {
@@ -108172,6 +108532,9 @@ function cardKind(options = {}) {
108172
108532
  }
108173
108533
  kept$2(parts.icon, icon !== void 0);
108174
108534
  const seen = /* @__PURE__ */ new Set();
108535
+ let lefts = 0;
108536
+ let rights = 0;
108537
+ let moved = false;
108175
108538
  for (const port of portsOf(node)) {
108176
108539
  const side = rowSide(port);
108177
108540
  if (!side || seen.has(port.id)) continue;
@@ -108186,11 +108549,17 @@ function cardKind(options = {}) {
108186
108549
  put(row, "data-side", side);
108187
108550
  entry = {
108188
108551
  row,
108189
- side
108552
+ side,
108553
+ at: -1
108190
108554
  };
108191
108555
  parts.rows.set(port.id, entry);
108192
108556
  context.anchor(port.id, row);
108193
108557
  }
108558
+ const at = side === "left" ? lefts++ : rights++;
108559
+ if (entry.at !== at) {
108560
+ entry.at = at;
108561
+ moved = true;
108562
+ }
108194
108563
  text$1(entry.row, port.label ?? "");
108195
108564
  }
108196
108565
  for (const [id, entry] of parts.rows) {
@@ -108199,6 +108568,10 @@ function cardKind(options = {}) {
108199
108568
  context.anchor(id, null);
108200
108569
  removePart(entry.row);
108201
108570
  }
108571
+ if (moved) {
108572
+ orderControls(parts.ins, rowsOf(parts.rows, "left"));
108573
+ orderControls(parts.outs, rowsOf(parts.rows, "right"));
108574
+ }
108202
108575
  kept$2(parts.ports, parts.rows.size > 0);
108203
108576
  if (parts.inner) options.update?.(parts.inner);
108204
108577
  }
@@ -108267,6 +108640,7 @@ function builtInKinds(toggle, check) {
108267
108640
  const button = toggleOf(context);
108268
108641
  header.controls.add(button);
108269
108642
  const title = part(header, "div", "mx-diagram__group-title");
108643
+ context.textPart(title);
108270
108644
  part(context.host, "div", "mx-diagram__group-body");
108271
108645
  context.dragHandle(header);
108272
108646
  groups.set(context, {
@@ -108296,6 +108670,7 @@ function builtInKinds(toggle, check) {
108296
108670
  const button = toggleOf(context);
108297
108671
  header.controls.add(button);
108298
108672
  const title = part(header, "div", "mx-diagram__table-title");
108673
+ context.textPart(title);
108299
108674
  const rows = part(context.host, "div", "mx-diagram__table-rows");
108300
108675
  tables.set(context, {
108301
108676
  title,
@@ -108388,6 +108763,7 @@ function builtInKinds(toggle, check) {
108388
108763
  const header = part(context.host, "div", "mx-diagram__class-header");
108389
108764
  const stereotype = part(header, "div", "mx-diagram__class-stereotype");
108390
108765
  const name = part(header, "div", "mx-diagram__class-name");
108766
+ context.textPart(name);
108391
108767
  const button = toggleOf(context);
108392
108768
  header.controls.add(button);
108393
108769
  const attributes = part(context.host, "div", "mx-diagram__class-compartment");
@@ -111276,185 +111652,824 @@ function round$2(value) {
111276
111652
  return Math.round(value * 1e3) / 1e3;
111277
111653
  }
111278
111654
  //#endregion
111279
- //#region src/components/diagram/DiagramEdgeView.ts
111280
- /** How far a line's labels and marks may reach out of the box around its corners, in the diagram's units. */
111281
- var LABEL_ROOM = 80;
111655
+ //#region src/components/diagram/DiagramNodeView.ts
111656
+ /** The ports of a node that names none: the middle of each side; a flow comes in at the top and the left and goes out at the right and the bottom. */
111657
+ var SIDE_PORTS = [
111658
+ {
111659
+ id: "top",
111660
+ side: "top",
111661
+ direction: "target"
111662
+ },
111663
+ {
111664
+ id: "right",
111665
+ side: "right",
111666
+ direction: "source"
111667
+ },
111668
+ {
111669
+ id: "bottom",
111670
+ side: "bottom",
111671
+ direction: "source"
111672
+ },
111673
+ {
111674
+ id: "left",
111675
+ side: "left",
111676
+ direction: "target"
111677
+ }
111678
+ ];
111679
+ var RESIZE_SIDES = [
111680
+ "n",
111681
+ "ne",
111682
+ "e",
111683
+ "se",
111684
+ "s",
111685
+ "sw",
111686
+ "w",
111687
+ "nw"
111688
+ ];
111689
+ var STATUS_WORDS = {
111690
+ running: "diagramStatusRunning",
111691
+ done: "diagramStatusDone",
111692
+ error: "diagramStatusError",
111693
+ waiting: "diagramStatusWaiting",
111694
+ skipped: "diagramStatusSkipped"
111695
+ };
111696
+ /** What a node's status says, in the kit's language: its word, and the node's `statusText` after it. */
111697
+ function statusWords(status, detail) {
111698
+ const word = uiLocale.strings[STATUS_WORDS[status]] ?? status;
111699
+ return detail ? `${word}: ${detail}` : word;
111700
+ }
111282
111701
  /**
111283
- * A connection on the surface: its line, the wider line the pointer finds it by, the marks at its ends and its label.
111284
- * Its way is worked out at every draw; its parts are made the first time it is shown, and leave the page while it is not
111285
- * (a line out of view in a large diagram).
111702
+ * A node on the surface: the app's object drawn at its place with the content of its kind, its ports and, when it may
111703
+ * be resized, its resize handles; its size measured as it is laid out.
111286
111704
  */
111287
- var DiagramEdgeView = class {
111288
- constructor(edges, labels, edge, told) {
111289
- _defineProperty(this, "edges", void 0);
111290
- _defineProperty(this, "labels", void 0);
111291
- _defineProperty(this, "told", void 0);
111292
- _defineProperty(this, "parts", null);
111705
+ var DiagramNodeView = class {
111706
+ constructor(node, host) {
111707
+ _defineProperty(this, "part", void 0);
111293
111708
  _defineProperty(
111294
111709
  this,
111295
- /** The line as last worked out, written to its parts while it is shown. */
111296
- "drawn",
111297
- null
111710
+ /** Where the content of its kind goes: its text, or what the kind made. */
111711
+ "body",
111712
+ void 0
111713
+ );
111714
+ _defineProperty(
111715
+ this,
111716
+ /** The id of its element, which the diagram names as the active node to a screen reader. */
111717
+ "elementId",
111718
+ nextId("diagram-node")
111719
+ );
111720
+ _defineProperty(this, "host", void 0);
111721
+ _defineProperty(
111722
+ this,
111723
+ /** A part for each port on each of its sides, by port and side. */
111724
+ "portParts",
111725
+ /* @__PURE__ */ new Map()
111726
+ );
111727
+ _defineProperty(this, "resizers", /* @__PURE__ */ new Map());
111728
+ _defineProperty(this, "context", void 0);
111729
+ _defineProperty(
111730
+ this,
111731
+ /** The parts of the content ports stand beside, by port, and where those parts are: the share of the way across and down the node to their middles. */
111732
+ "anchors",
111733
+ /* @__PURE__ */ new Map()
111734
+ );
111735
+ _defineProperty(this, "offsets", /* @__PURE__ */ new Map());
111736
+ _defineProperty(
111737
+ this,
111738
+ /** The ports, as read when it was drawn. */
111739
+ "portList",
111740
+ SIDE_PORTS
111298
111741
  );
111299
- _defineProperty(this, "selected", false);
111300
- _defineProperty(this, "moving", false);
111301
111742
  _defineProperty(this, "label", null);
111302
111743
  _defineProperty(
111303
111744
  this,
111304
- /** The texts at its ends. */
111305
- "endLabels",
111306
- {
111307
- source: null,
111308
- target: null
111309
- }
111745
+ /** The mark of its status in its corner, while it has one. */
111746
+ "statusMark",
111747
+ null
111310
111748
  );
111749
+ _defineProperty(this, "kind", null);
111311
111750
  _defineProperty(
111312
111751
  this,
111313
- /** The app's classes and style properties written last, so those it takes away are taken off. */
111752
+ /** The kind whose content it holds now. */
111753
+ "made",
111754
+ null
111755
+ );
111756
+ _defineProperty(
111757
+ this,
111758
+ /** Whether its content is made and laid out: it came into view once, or the diagram shows every node. */
111759
+ "entered",
111760
+ false
111761
+ );
111762
+ _defineProperty(
111763
+ this,
111764
+ /** Whether it is on the page: it lies in view, or the diagram shows every node. */
111765
+ "live",
111766
+ true
111767
+ );
111768
+ _defineProperty(
111769
+ this,
111770
+ /** The part a press drags the node from, when the kind's content named one. */
111771
+ "handle",
111772
+ null
111773
+ );
111774
+ _defineProperty(
111775
+ this,
111776
+ /** The part that shows its text, when the kind's content named one (`context.textPart`). */
111777
+ "textHolder",
111778
+ null
111779
+ );
111780
+ _defineProperty(
111781
+ this,
111782
+ /** The editor of its text, over the part that shows it, while the text is edited. */
111783
+ "editor",
111784
+ null
111785
+ );
111786
+ _defineProperty(
111787
+ this,
111788
+ /** What names it, when the kind's content gave it (`context.label`), and what stops the name following its data. */
111789
+ "naming",
111790
+ null
111791
+ );
111792
+ _defineProperty(this, "stopNaming", null);
111793
+ _defineProperty(
111794
+ this,
111795
+ /** The app's and the kind's classes and the app's style properties written last, so those taken away come off. */
111314
111796
  "drawnClasses",
111315
111797
  []
111316
111798
  );
111317
111799
  _defineProperty(this, "drawnStyle", []);
111318
- _defineProperty(this, "edge", void 0);
111800
+ _defineProperty(this, "node", void 0);
111319
111801
  _defineProperty(
111320
111802
  this,
111321
- /** Where its ends stood when it was last drawn, on the nodes, with the sides they leave by; `null` while it is not drawn. */
111322
- "ends",
111323
- null
111803
+ /** Its border box as laid out, in the diagram's units: the zoom is a transform and does not change it. */
111804
+ "size",
111805
+ {
111806
+ width: 0,
111807
+ height: 0
111808
+ }
111324
111809
  );
111325
111810
  _defineProperty(
111326
111811
  this,
111327
- /** The points the line ran through when it was last drawn: its ends and corners (a curve's own points), and the shape it was drawn with. */
111328
- "corners",
111329
- []
111812
+ /** Hidden in a collapsed group. */
111813
+ "hidden",
111814
+ false
111330
111815
  );
111331
- _defineProperty(this, "shape", "curve");
111332
111816
  _defineProperty(
111333
111817
  this,
111334
- /** Around the line, its marks and its labels as last worked out, in the diagram's units; `null` while it is not drawn. */
111335
- "bounds",
111336
- null
111818
+ /** The share of the way across and down the node to the middle of each part a port stands beside; a part not laid out is left out. */
111819
+ "anchorsRead",
111820
+ () => {
111821
+ const offsets = /* @__PURE__ */ new Map();
111822
+ const box = rectOf(this.part);
111823
+ if (box.width <= 0 || box.height <= 0) return offsets;
111824
+ for (const [id, at] of this.anchors) {
111825
+ const r = rectOf(at);
111826
+ if (r.width <= 0 && r.height <= 0) continue;
111827
+ offsets.set(id, {
111828
+ across: (r.left + r.width / 2 - box.left) / box.width,
111829
+ down: (r.top + r.height / 2 - box.top) / box.height
111830
+ });
111831
+ }
111832
+ return offsets;
111833
+ }
111337
111834
  );
111338
111835
  _defineProperty(
111339
111836
  this,
111340
- /** Whether it is on the page: it lies in view, or the diagram shows every line. */
111341
- "live",
111342
- true
111837
+ /** The ports stand where their parts are now; their connections are drawn again. */
111838
+ "anchorsWritten",
111839
+ (offsets) => {
111840
+ if (offsets.size === this.offsets.size && [...offsets].every(([id, at]) => {
111841
+ const was = this.offsets.get(id);
111842
+ return !!was && Math.abs(was.across - at.across) < 1e-4 && Math.abs(was.down - at.down) < 1e-4;
111843
+ })) return;
111844
+ this.offsets = offsets;
111845
+ this.drawPorts();
111846
+ this.host.sized(this);
111847
+ }
111343
111848
  );
111344
- this.edge = edge;
111345
- this.edges = edges;
111346
- this.labels = labels;
111347
- this.told = told;
111849
+ this.node = node;
111850
+ this.host = host;
111851
+ this.part = loose("div", "mx-diagram__node");
111852
+ this.part.attr.add({
111853
+ id: this.elementId,
111854
+ role: "group"
111855
+ });
111856
+ this.body = part(this.part, "div", "mx-diagram__node-content");
111857
+ const view = this;
111858
+ this.context = {
111859
+ get node() {
111860
+ return view.node;
111861
+ },
111862
+ host: this.body,
111863
+ diagram: host.diagram,
111864
+ get selected() {
111865
+ return host.isSelected(view);
111866
+ },
111867
+ dragHandle(handle) {
111868
+ view.handle = handle;
111869
+ },
111870
+ anchor(id, at) {
111871
+ if (at) view.anchors.set(id, at);
111872
+ else view.anchors.delete(id);
111873
+ view.readAnchors();
111874
+ },
111875
+ label(read) {
111876
+ view.stopNaming?.();
111877
+ view.naming = read;
111878
+ view.stopNaming = effect(() => {
111879
+ const name = read();
111880
+ untracked(() => put(view.part, "aria-label", name || view.node.id));
111881
+ });
111882
+ },
111883
+ textPart(at) {
111884
+ view.textHolder = at;
111885
+ }
111886
+ };
111887
+ this.part.motif.setDisposable(() => this.stopNaming?.());
111888
+ this.part.motif.on("pointerdown", (_, e) => this.pressed(e));
111889
+ this.draw();
111348
111890
  }
111349
- /** The group of its parts; `null` until it is first shown. */
111350
- get group() {
111351
- return this.parts?.group ?? null;
111891
+ /** Makes its content and lays it out: the first time it comes into view, or at once in a diagram that shows every node. */
111892
+ enter() {
111893
+ if (this.entered) return;
111894
+ this.entered = true;
111895
+ const tell = (what) => (_, e) => {
111896
+ if (!this.fromHandle(e)) this.host.told(what, this, e);
111897
+ };
111898
+ this.part.motif.on("click", tell("click"));
111899
+ this.part.motif.on("dblclick", tell("dblclick"));
111900
+ this.part.motif.on("contextmenu", tell("contextmenu"));
111901
+ this.part.motif.on("pointerenter", tell("enter"));
111902
+ this.part.motif.on("pointerleave", tell("leave"));
111903
+ onLayout(this.part, "size", (size) => {
111904
+ if (!size.width && !size.height) return;
111905
+ this.size = size;
111906
+ this.host.sized(this);
111907
+ this.readAnchors();
111908
+ });
111909
+ this.draw();
111352
111910
  }
111353
- /** Puts it on the page or takes it off: its parts are made the first time. Returns whether they were made now. */
111911
+ /** Puts it on the page or takes it off, its content and state kept. */
111354
111912
  setLive(on) {
111355
- if (this.live === on) return false;
111356
111913
  this.live = on;
111357
- if (!on) {
111358
- kept$2(this.parts?.group ?? null, false);
111359
- for (const label of [
111360
- this.label,
111361
- this.endLabels.source,
111362
- this.endLabels.target
111363
- ]) kept$2(label, false);
111364
- return false;
111365
- }
111366
- const made = !this.parts && !!this.drawn;
111367
- this.write();
111368
- return made;
111369
- }
111370
- /**
111371
- * Draws the line between two points on their nodes, each with the side it leaves by, through the connection's own
111372
- * points; an orthogonal line goes around `obstacles`, the nodes.
111373
- */
111374
- draw(source, sourceSide, target, targetSide, shape, look, obstacles) {
111375
- const edge = this.edge;
111376
- const sourceMarker = edge.sourceMarker ?? "none";
111377
- const targetMarker = edge.targetMarker ?? "arrow";
111378
- const route = routeOf(shape, source, sourceSide, target, targetSide, {
111379
- source: markerInset(sourceMarker, look.marker),
111380
- target: markerInset(targetMarker, look.marker)
111381
- }, look, edge.points ?? [], obstacles);
111382
- this.ends = {
111383
- source,
111384
- sourceSide,
111385
- target,
111386
- targetSide
111387
- };
111388
- this.corners = route.corners;
111389
- this.shape = shape;
111390
- this.drawn = {
111391
- route,
111392
- sourceMarker,
111393
- targetMarker,
111394
- look
111395
- };
111396
- const room = look.gap * 2 + look.marker * 2 + (edge.label || edge.sourceLabel || edge.targetLabel ? LABEL_ROOM : 0);
111397
- this.bounds = boundsAround([
111398
- source,
111399
- target,
111400
- ...route.corners
111401
- ], room);
111402
- if (this.live) this.write();
111914
+ kept$2(this.part, on && !this.hidden);
111403
111915
  }
111404
- /** Writes the line as last worked out to its parts, made now if it has none. */
111405
- write() {
111406
- const drawn = this.drawn;
111407
- const ends = this.ends;
111408
- if (!drawn || !ends) return;
111409
- const p = this.parts ??= this.make();
111410
- const { route, sourceMarker, targetMarker, look } = drawn;
111411
- const edge = this.edge;
111412
- put(p.group, "data-id", edge.id);
111413
- mark(p.group, "data-dashed", edge.dashed || edge.animated);
111414
- mark(p.group, "data-animated", edge.animated);
111415
- this.drawLook(p.group);
111416
- kept$2(p.group, true);
111417
- put(p.line, "d", route.d);
111418
- put(p.hit, "d", route.d);
111419
- this.drawMark(p.sourceMark, sourceMarker, ends.source, route.sourceBack, look.marker);
111420
- this.drawMark(p.targetMark, targetMarker, ends.target, route.targetBack, look.marker);
111421
- this.drawLabel(route.label);
111422
- this.drawEndLabel("source", edge.sourceLabel, ends.source, ends.sourceSide, look.marker);
111423
- this.drawEndLabel("target", edge.targetLabel, ends.target, ends.targetSide, look.marker);
111916
+ /** Its ports: the node's own, its kind's, or one in the middle of each side. */
111917
+ get ports() {
111918
+ return this.portList;
111424
111919
  }
111425
- make() {
111426
- const group = svgComponent(this.edges, "g", "mx-diagram__edge");
111427
- const parts = {
111428
- group,
111429
- hit: svgComponent(group, "path", "mx-diagram__edge-hit"),
111430
- line: svgComponent(group, "path", "mx-diagram__edge-line"),
111431
- sourceMark: svgComponent(group, "path", "mx-diagram__edge-marker"),
111432
- targetMark: svgComponent(group, "path", "mx-diagram__edge-marker")
111433
- };
111434
- group.motif.on("pointerdown", (_, e) => this.told.pressed(this, e));
111435
- group.motif.on("click", (_, e) => this.told.clicked(this, e));
111436
- mark(group, "data-selected", this.selected);
111437
- mark(group, "data-moving", this.moving);
111438
- return parts;
111920
+ /** Whether the node or its kind names ports of its own. */
111921
+ get hasOwnPorts() {
111922
+ return !!(this.node.ports ?? this.kind?.ports);
111439
111923
  }
111440
- /** Not drawn: one of its nodes is missing or not laid out yet. */
111441
- hide() {
111442
- this.ends = null;
111443
- this.drawn = null;
111444
- this.bounds = null;
111445
- kept$2(this.parts?.group ?? null, false);
111446
- kept$2(this.label, false);
111447
- kept$2(this.endLabels.source, false);
111448
- kept$2(this.endLabels.target, false);
111924
+ /** Every port on each of its sides, where it stands now. */
111925
+ get places() {
111926
+ const rect = this.rect;
111927
+ const places = [];
111928
+ for (const port of this.portList) for (const side of sidesOf(port)) places.push({
111929
+ port,
111930
+ side,
111931
+ point: portPoint(rect, side, this.offsetOf(port, side))
111932
+ });
111933
+ return places;
111449
111934
  }
111450
- /** What an image of the diagram draws of it: its line and marks, and its labels; `null` while it is not drawn or not on the page. */
111451
- get picture() {
111452
- const p = this.parts;
111453
- if (!this.ends || !p || !this.live) return null;
111454
- const labels = [];
111455
- for (const label of [
111456
- this.label,
111457
- this.endLabels.source,
111935
+ /** Where a port stands: on the one of its sides nearest `toward`; `null` for a port it does not have. */
111936
+ placeOf(id, toward) {
111937
+ const port = this.port(id);
111938
+ if (!port) return null;
111939
+ const rect = this.rect;
111940
+ let best = null;
111941
+ let nearest = Infinity;
111942
+ for (const side of sidesOf(port)) {
111943
+ const point = portPoint(rect, side, this.offsetOf(port, side));
111944
+ const d = Math.hypot(point.x - toward.x, point.y - toward.y);
111945
+ if (d < nearest) {
111946
+ nearest = d;
111947
+ best = {
111948
+ port,
111949
+ side,
111950
+ point
111951
+ };
111952
+ }
111953
+ }
111954
+ return best;
111955
+ }
111956
+ /** How far along a side a port stands: beside the part its content anchors it to, else at its own offset. */
111957
+ offsetOf(port, side) {
111958
+ const at = this.offsets.get(port.id);
111959
+ if (at) return side === "left" || side === "right" ? at.down : at.across;
111960
+ return port.offset ?? .5;
111961
+ }
111962
+ /** Whether it holds other nodes. */
111963
+ get isGroup() {
111964
+ return !!this.kind?.group;
111965
+ }
111966
+ /** Whether it collapses to its header: a group, or a node of a kind that says so. */
111967
+ get isCollapsible() {
111968
+ return !!(this.kind?.group || this.kind?.collapsible);
111969
+ }
111970
+ /** Whether the user may resize it (a collapsed node not, until it opens), and the smallest size a resize leaves. */
111971
+ get isResizable() {
111972
+ if (this.isCollapsible && this.node.collapsed) return false;
111973
+ return this.node.resizable ?? this.kind?.resizable ?? false;
111974
+ }
111975
+ get minSize() {
111976
+ return {
111977
+ width: this.kind?.minWidth ?? 40,
111978
+ height: this.kind?.minHeight ?? 24
111979
+ };
111980
+ }
111981
+ port(id) {
111982
+ return id === void 0 ? null : this.ports.find((p) => p.id === id) ?? null;
111983
+ }
111984
+ /** Marks a port as the end a connection being drawn would take, or would be refused at; none for `null`. */
111985
+ markPort(id, state) {
111986
+ for (const { port, part: p } of this.portParts.values()) {
111987
+ mark(p, "data-target", port === id && state === "target");
111988
+ mark(p, "data-refused", port === id && state === "refused");
111989
+ }
111990
+ }
111991
+ /** Marks the ports a connection being drawn may end at; none for `null`. */
111992
+ markAvailable(ids) {
111993
+ for (const { port, part: p } of this.portParts.values()) mark(p, "data-available", !!ids?.has(port));
111994
+ }
111995
+ markSelected(on) {
111996
+ mark(this.part, "data-selected", on);
111997
+ }
111998
+ markMovable(on) {
111999
+ mark(this.part, "data-movable", on);
112000
+ }
112001
+ markDragging(on) {
112002
+ mark(this.part, "data-dragging", on);
112003
+ }
112004
+ /** The node the keys are on. */
112005
+ markActive(on) {
112006
+ mark(this.part, "data-active", on);
112007
+ }
112008
+ /** A group under it is collapsed: it leaves the surface, in its place. */
112009
+ markHidden(on) {
112010
+ this.hidden = on;
112011
+ if (this.entered) kept$2(this.part, this.live && !on);
112012
+ }
112013
+ /** A group that will take the node if it is dropped now. */
112014
+ markDropTarget(on) {
112015
+ mark(this.part, "data-drop-target", on);
112016
+ }
112017
+ /** What a screen reader calls it: the name its kind's content gives, else its text, else its `id`. */
112018
+ get name() {
112019
+ return (this.naming ? untracked(this.naming) : this.node.text) || this.node.id;
112020
+ }
112021
+ /** Writes what the node says now; what did not change is not written again. */
112022
+ draw() {
112023
+ const node = this.node;
112024
+ const kind = this.host.kindOf(node);
112025
+ this.kind = kind;
112026
+ this.portList = node.ports ?? (typeof kind.ports === "function" ? kind.ports(node) : kind.ports) ?? SIDE_PORTS;
112027
+ if (!this.entered) return;
112028
+ if (kind !== this.made) this.build(kind);
112029
+ put(this.part, "data-id", node.id);
112030
+ put(this.part, "data-kind", node.kind ?? null);
112031
+ this.drawPlace();
112032
+ this.drawSize();
112033
+ if (kind.content) kind.update?.(this.context);
112034
+ else if (this.label) text$1(this.label, node.text ?? "");
112035
+ if (!this.naming) put(this.part, "aria-label", this.name);
112036
+ put(this.part, "aria-roledescription", uiLocale.strings.diagramNode);
112037
+ mark(this.part, "data-no-connect", node.connectable === false);
112038
+ mark(this.part, "data-group", !!kind.group);
112039
+ mark(this.part, "data-collapsed", this.isCollapsible && !!node.collapsed);
112040
+ mark(this.part, "data-resizable", this.isResizable);
112041
+ this.drawLook(kind);
112042
+ this.drawStatus();
112043
+ this.drawPorts();
112044
+ this.drawResizers();
112045
+ this.readAnchors();
112046
+ }
112047
+ /** Moves the node to its place now, while it is dragged: only its place is written. */
112048
+ drawPlace() {
112049
+ css(this.part, "transform", `translate(${this.node.x}px, ${this.node.y}px)`);
112050
+ }
112051
+ /**
112052
+ * Writes the size the node gives, while it is resized too; without one it takes the size of its content, no smaller
112053
+ * than its kind allows. A collapsed group keeps its width and takes the height of its header.
112054
+ */
112055
+ drawSize() {
112056
+ const given = this.given;
112057
+ const kind = this.kind;
112058
+ css(this.part, "width", given.width !== null ? `${given.width}px` : "");
112059
+ css(this.part, "max-width", given.width !== null ? "none" : "");
112060
+ css(this.part, "height", given.height !== null ? `${given.height}px` : "");
112061
+ const min = this.minSize;
112062
+ const minWidth = kind?.minWidth ?? (this.isResizable ? min.width : given.width !== null ? 0 : null);
112063
+ const minHeight = kind?.minHeight ?? (this.isResizable ? min.height : given.height !== null ? 0 : null);
112064
+ css(this.part, "min-width", this.folded("horizontal") ? "0" : minWidth !== null ? `${minWidth}px` : "");
112065
+ css(this.part, "min-height", this.folded("vertical") ? "0" : minHeight !== null ? `${minHeight}px` : "");
112066
+ }
112067
+ /** Whether it has a size to draw with: laid out, given, or likely (a node of a large diagram not seen yet). */
112068
+ get isSized() {
112069
+ return !this.hidden && (this.size.width > 0 || this.given.width !== null || this.host.estimate(this).width > 0);
112070
+ }
112071
+ /** Whether its size is known for sure: laid out, or both sides given. */
112072
+ get isMeasured() {
112073
+ const given = this.given;
112074
+ return !this.hidden && (this.size.width > 0 || given.width !== null && given.height !== null);
112075
+ }
112076
+ /**
112077
+ * Its place and size in the diagram's units: a side it gives as given (no smaller than its kind allows), which holds
112078
+ * at once while it is resized; else as laid out, or, not laid out yet in a large diagram, as it is likely to be.
112079
+ */
112080
+ get rect() {
112081
+ const node = this.node;
112082
+ const given = this.given;
112083
+ const size = this.size.width > 0 ? this.size : this.host.estimate(this);
112084
+ const width = given.width !== null ? Math.max(given.width, this.kind?.minWidth ?? 0) : size.width;
112085
+ const height = given.height !== null ? Math.max(given.height, this.kind?.minHeight ?? 0) : size.height;
112086
+ return {
112087
+ x: node.x,
112088
+ y: node.y,
112089
+ width,
112090
+ height
112091
+ };
112092
+ }
112093
+ /** The sides of its size it gives: a collapsed group takes one from its header. */
112094
+ get given() {
112095
+ const node = this.node;
112096
+ return {
112097
+ width: node.width != null && !this.folded("horizontal") ? node.width : null,
112098
+ height: node.height != null && !this.folded("vertical") ? node.height : null
112099
+ };
112100
+ }
112101
+ /** Whether it is collapsed the way given: `'vertical'` to the height of its header, `'horizontal'` to its width. */
112102
+ folded(way) {
112103
+ return this.isCollapsible && !!this.node.collapsed && (this.kind?.collapse ?? "vertical") === way;
112104
+ }
112105
+ /** Reads where the parts its ports stand beside are, with the window's next run. */
112106
+ readAnchors() {
112107
+ if (this.anchors.size || this.offsets.size) measure(this.part, this.anchorsRead, this.anchorsWritten);
112108
+ }
112109
+ /** Makes the content of a kind, in place of what the last one made. */
112110
+ build(kind) {
112111
+ clearParts(this.body);
112112
+ this.label = null;
112113
+ this.textHolder = null;
112114
+ this.handle = null;
112115
+ this.anchors.clear();
112116
+ this.offsets = /* @__PURE__ */ new Map();
112117
+ this.stopNaming?.();
112118
+ this.stopNaming = null;
112119
+ this.naming = null;
112120
+ this.made = kind;
112121
+ if (!kind.content) {
112122
+ this.label = part(this.body, "div", "mx-diagram__node-text");
112123
+ return;
112124
+ }
112125
+ const made = kind.content(this.context);
112126
+ if (made instanceof ComponentBase) this.body.controls.add(made);
112127
+ else if (made !== void 0 && made !== null && made !== "") text$1(this.body, String(made));
112128
+ }
112129
+ /**
112130
+ * A press on the node: a resize handle resizes, a port draws a connection, a control of the content keeps it, and
112131
+ * the rest drags the node (off a drag handle, it only selects).
112132
+ */
112133
+ pressed(e) {
112134
+ if (this.editor?.motif.isEventFrom(e)) return;
112135
+ for (const [side, p] of this.resizers) {
112136
+ if (!p.motif.isEventFrom(e)) continue;
112137
+ this.host.resizePressed(this, side, e);
112138
+ return;
112139
+ }
112140
+ for (const { port, part: p } of this.portParts.values()) {
112141
+ if (!p.motif.isEventFrom(e)) continue;
112142
+ this.host.pressed(this, this.port(port), e, false);
112143
+ return;
112144
+ }
112145
+ if (this.fromControl(this.body, e)) return;
112146
+ this.host.pressed(this, null, e, !this.handle || this.handle.motif.isEventFrom(e));
112147
+ }
112148
+ /** Whether an event comes from a port, a resize handle or the editor of its text: none of them is the node's own. */
112149
+ fromHandle(e) {
112150
+ if (this.editor?.motif.isEventFrom(e)) return true;
112151
+ for (const p of this.resizers.values()) if (p.motif.isEventFrom(e)) return true;
112152
+ for (const { part: p } of this.portParts.values()) if (p.motif.isEventFrom(e)) return true;
112153
+ return false;
112154
+ }
112155
+ /** Whether an event came from the part that shows its text: anywhere on a node of a text, off its ports and handles. */
112156
+ isTextEvent(e) {
112157
+ if (!this.made?.content) return !this.fromHandle(e);
112158
+ return !!this.textHolder?.motif.isEventFrom(e);
112159
+ }
112160
+ /** The part its text is edited over: the one that shows it, else its content. */
112161
+ get textPlace() {
112162
+ return this.textHolder ?? this.label ?? this.body;
112163
+ }
112164
+ /** Whether its text is being edited in place. */
112165
+ get isEditing() {
112166
+ return !!this.editor;
112167
+ }
112168
+ /**
112169
+ * Puts the editor of its text over the part that shows the text, as wide as it and no narrower than the editor's
112170
+ * own smallest; `null` takes it away. The editor is placed with the window's next measuring round, when the node is
112171
+ * laid out, and moves and zooms with the node.
112172
+ */
112173
+ holdEditor(editor) {
112174
+ if (this.editor === editor) return;
112175
+ removePart(this.editor);
112176
+ this.editor = editor;
112177
+ mark(this.part, "data-editing", !!editor);
112178
+ if (!editor) return;
112179
+ this.part.controls.add(editor);
112180
+ const place = this.textPlace;
112181
+ measure(this.part, () => ({
112182
+ box: rectOf(this.part),
112183
+ at: rectOf(place)
112184
+ }), ({ box, at }) => {
112185
+ if (this.editor !== editor || box.width <= 0 || this.size.width <= 0) return;
112186
+ const zoom = box.width / this.size.width;
112187
+ css(editor, "left", `${(at.left - box.left) / zoom}px`);
112188
+ css(editor, "top", `${(at.top - box.top + at.height / 2) / zoom}px`);
112189
+ css(editor, "width", `${at.width / zoom}px`);
112190
+ });
112191
+ }
112192
+ /**
112193
+ * Whether an event comes from a control inside `from`: a part that takes focus, a control of the kit whose focus is a
112194
+ * part of its own (a field), or one that is off (a button that is off keeps the press too). A layout of the kit, such
112195
+ * as a stack, is looked into.
112196
+ */
112197
+ fromControl(from, e) {
112198
+ for (const child of from.controls.items) {
112199
+ if (!child.motif.isEventFrom(e)) continue;
112200
+ if (canTakeFocus(child)) return true;
112201
+ if (child instanceof Control && (child.focusPart !== null && child.focusPart !== child || !child.isEnabled)) return true;
112202
+ return this.fromControl(child, e);
112203
+ }
112204
+ return false;
112205
+ }
112206
+ /** The app's and the kind's classes, and the app's style properties; those taken away since the last draw come off. */
112207
+ drawLook(kind) {
112208
+ const classes = `${kind.cssClass ?? ""} ${this.node.cssClass ?? ""}`.split(/\s+/).filter(Boolean);
112209
+ for (const name of this.drawnClasses) if (!classes.includes(name)) toggleClass(this.part, name, false);
112210
+ for (const name of classes) toggleClass(this.part, name, true);
112211
+ this.drawnClasses = classes;
112212
+ const style = this.node.style ?? {};
112213
+ for (const name of this.drawnStyle) if (!(name in style)) css(this.part, name, "");
112214
+ for (const [name, value] of Object.entries(style)) css(this.part, name, value);
112215
+ this.drawnStyle = Object.keys(style);
112216
+ }
112217
+ /** Its status: a mark in its corner with the status in its tip, and the same said with its name to a screen reader. */
112218
+ drawStatus() {
112219
+ const status = this.node.status;
112220
+ put(this.part, "data-status", status ?? null);
112221
+ if (!status) {
112222
+ removePart(this.statusMark);
112223
+ this.statusMark = null;
112224
+ put(this.part, "aria-description", null);
112225
+ return;
112226
+ }
112227
+ if (!this.statusMark) {
112228
+ this.statusMark = part(this.part, "span", "mx-glyph mx-diagram__status");
112229
+ put(this.statusMark, "aria-hidden", "true");
112230
+ }
112231
+ const said = statusWords(status, this.node.statusText);
112232
+ put(this.statusMark, "title", said);
112233
+ put(this.part, "aria-description", said);
112234
+ }
112235
+ /** A part for each port on each of its sides, matched by `id` and side, at its place there. */
112236
+ drawPorts() {
112237
+ const seen = /* @__PURE__ */ new Set();
112238
+ for (const port of this.portList) for (const side of sidesOf(port)) {
112239
+ const key = `${port.id}\n${side}`;
112240
+ seen.add(key);
112241
+ let entry = this.portParts.get(key);
112242
+ if (!entry) {
112243
+ const p = part(this.part, "div", "mx-diagram__port");
112244
+ p.attr.add({ "aria-hidden": "true" });
112245
+ entry = {
112246
+ port: port.id,
112247
+ side,
112248
+ part: p
112249
+ };
112250
+ this.portParts.set(key, entry);
112251
+ }
112252
+ put(entry.part, "data-port", port.id);
112253
+ put(entry.part, "data-side", side);
112254
+ put(entry.part, "data-direction", port.direction && port.direction !== "both" ? port.direction : null);
112255
+ put(entry.part, "title", port.label || null);
112256
+ css(entry.part, "--_at", `${this.offsetOf(port, side) * 100}%`);
112257
+ }
112258
+ for (const [key, entry] of this.portParts) {
112259
+ if (seen.has(key)) continue;
112260
+ this.portParts.delete(key);
112261
+ removePart(entry.part);
112262
+ }
112263
+ }
112264
+ /** The resize handles of a node the user may resize, at its sides and corners; shown while it is selected. */
112265
+ drawResizers() {
112266
+ if (!this.isResizable) {
112267
+ for (const p of this.resizers.values()) removePart(p);
112268
+ this.resizers.clear();
112269
+ return;
112270
+ }
112271
+ for (const side of RESIZE_SIDES) {
112272
+ if (this.resizers.has(side)) continue;
112273
+ const p = part(this.part, "div", "mx-diagram__resizer");
112274
+ p.attr.add({
112275
+ "aria-hidden": "true",
112276
+ "data-side": side
112277
+ });
112278
+ this.resizers.set(side, p);
112279
+ }
112280
+ }
112281
+ };
112282
+ //#endregion
112283
+ //#region src/components/diagram/DiagramEdgeView.ts
112284
+ /** How far a line's labels and marks may reach out of the box around its corners, in the diagram's units. */
112285
+ var LABEL_ROOM = 80;
112286
+ /**
112287
+ * A connection on the surface: its line, the wider line the pointer finds it by, the marks at its ends and its label.
112288
+ * Its way is worked out at every draw; its parts are made the first time it is shown, and leave the page while it is not
112289
+ * (a line out of view in a large diagram).
112290
+ */
112291
+ var DiagramEdgeView = class {
112292
+ constructor(edges, labels, edge, told) {
112293
+ _defineProperty(this, "edges", void 0);
112294
+ _defineProperty(this, "labels", void 0);
112295
+ _defineProperty(this, "told", void 0);
112296
+ _defineProperty(this, "parts", null);
112297
+ _defineProperty(
112298
+ this,
112299
+ /** The tip of its status, while it has one. */
112300
+ "tip",
112301
+ null
112302
+ );
112303
+ _defineProperty(
112304
+ this,
112305
+ /** The line as last worked out, written to its parts while it is shown. */
112306
+ "drawn",
112307
+ null
112308
+ );
112309
+ _defineProperty(this, "selected", false);
112310
+ _defineProperty(this, "moving", false);
112311
+ _defineProperty(this, "label", null);
112312
+ _defineProperty(
112313
+ this,
112314
+ /** The texts at its ends. */
112315
+ "endLabels",
112316
+ {
112317
+ source: null,
112318
+ target: null
112319
+ }
112320
+ );
112321
+ _defineProperty(
112322
+ this,
112323
+ /** The app's classes and style properties written last, so those it takes away are taken off. */
112324
+ "drawnClasses",
112325
+ []
112326
+ );
112327
+ _defineProperty(this, "drawnStyle", []);
112328
+ _defineProperty(this, "edge", void 0);
112329
+ _defineProperty(
112330
+ this,
112331
+ /** Where its ends stood when it was last drawn, on the nodes, with the sides they leave by; `null` while it is not drawn. */
112332
+ "ends",
112333
+ null
112334
+ );
112335
+ _defineProperty(
112336
+ this,
112337
+ /** The points the line ran through when it was last drawn: its ends and corners (a curve's own points), and the shape it was drawn with. */
112338
+ "corners",
112339
+ []
112340
+ );
112341
+ _defineProperty(this, "shape", "curve");
112342
+ _defineProperty(
112343
+ this,
112344
+ /** Around the line, its marks and its labels as last worked out, in the diagram's units; `null` while it is not drawn. */
112345
+ "bounds",
112346
+ null
112347
+ );
112348
+ _defineProperty(
112349
+ this,
112350
+ /** Whether it is on the page: it lies in view, or the diagram shows every line. */
112351
+ "live",
112352
+ true
112353
+ );
112354
+ this.edge = edge;
112355
+ this.edges = edges;
112356
+ this.labels = labels;
112357
+ this.told = told;
112358
+ }
112359
+ /** The group of its parts; `null` until it is first shown. */
112360
+ get group() {
112361
+ return this.parts?.group ?? null;
112362
+ }
112363
+ /** Puts it on the page or takes it off: its parts are made the first time. Returns whether they were made now. */
112364
+ setLive(on) {
112365
+ if (this.live === on) return false;
112366
+ this.live = on;
112367
+ if (!on) {
112368
+ kept$2(this.parts?.group ?? null, false);
112369
+ for (const label of [
112370
+ this.label,
112371
+ this.endLabels.source,
112372
+ this.endLabels.target
112373
+ ]) kept$2(label, false);
112374
+ return false;
112375
+ }
112376
+ const made = !this.parts && !!this.drawn;
112377
+ this.write();
112378
+ return made;
112379
+ }
112380
+ /**
112381
+ * Draws the line between two points on their nodes, each with the side it leaves by, through the connection's own
112382
+ * points; an orthogonal line goes around `obstacles`, the nodes.
112383
+ */
112384
+ draw(source, sourceSide, target, targetSide, shape, look, obstacles) {
112385
+ const edge = this.edge;
112386
+ const sourceMarker = edge.sourceMarker ?? "none";
112387
+ const targetMarker = edge.targetMarker ?? "arrow";
112388
+ const route = routeOf(shape, source, sourceSide, target, targetSide, {
112389
+ source: markerInset(sourceMarker, look.marker),
112390
+ target: markerInset(targetMarker, look.marker)
112391
+ }, look, edge.points ?? [], obstacles);
112392
+ this.ends = {
112393
+ source,
112394
+ sourceSide,
112395
+ target,
112396
+ targetSide
112397
+ };
112398
+ this.corners = route.corners;
112399
+ this.shape = shape;
112400
+ this.drawn = {
112401
+ route,
112402
+ sourceMarker,
112403
+ targetMarker,
112404
+ look
112405
+ };
112406
+ const room = look.gap * 2 + look.marker * 2 + (edge.label || edge.sourceLabel || edge.targetLabel ? LABEL_ROOM : 0);
112407
+ this.bounds = boundsAround([
112408
+ source,
112409
+ target,
112410
+ ...route.corners
112411
+ ], room);
112412
+ if (this.live) this.write();
112413
+ }
112414
+ /** Writes the line as last worked out to its parts, made now if it has none. */
112415
+ write() {
112416
+ const drawn = this.drawn;
112417
+ const ends = this.ends;
112418
+ if (!drawn || !ends) return;
112419
+ const p = this.parts ??= this.make();
112420
+ const { route, sourceMarker, targetMarker, look } = drawn;
112421
+ const edge = this.edge;
112422
+ put(p.group, "data-id", edge.id);
112423
+ mark(p.group, "data-dashed", edge.dashed || edge.animated);
112424
+ mark(p.group, "data-animated", edge.animated);
112425
+ this.drawLook(p.group);
112426
+ this.drawStatus(p.group);
112427
+ kept$2(p.group, true);
112428
+ put(p.line, "d", route.d);
112429
+ put(p.hit, "d", route.d);
112430
+ this.drawMark(p.sourceMark, sourceMarker, ends.source, route.sourceBack, look.marker);
112431
+ this.drawMark(p.targetMark, targetMarker, ends.target, route.targetBack, look.marker);
112432
+ this.drawLabel(route.label);
112433
+ this.drawEndLabel("source", edge.sourceLabel, ends.source, ends.sourceSide, look.marker);
112434
+ this.drawEndLabel("target", edge.targetLabel, ends.target, ends.targetSide, look.marker);
112435
+ }
112436
+ make() {
112437
+ const group = svgComponent(this.edges, "g", "mx-diagram__edge");
112438
+ const parts = {
112439
+ group,
112440
+ hit: svgComponent(group, "path", "mx-diagram__edge-hit"),
112441
+ line: svgComponent(group, "path", "mx-diagram__edge-line"),
112442
+ sourceMark: svgComponent(group, "path", "mx-diagram__edge-marker"),
112443
+ targetMark: svgComponent(group, "path", "mx-diagram__edge-marker")
112444
+ };
112445
+ group.motif.on("pointerdown", (_, e) => this.told.pressed(this, e));
112446
+ group.motif.on("click", (_, e) => this.told.clicked(this, e));
112447
+ group.motif.on("dblclick", (_, e) => this.told.pointer("dblclick", this, e));
112448
+ group.motif.on("contextmenu", (_, e) => this.told.pointer("contextmenu", this, e));
112449
+ group.motif.on("pointerenter", (_, e) => this.told.pointer("enter", this, e));
112450
+ group.motif.on("pointerleave", (_, e) => this.told.pointer("leave", this, e));
112451
+ mark(group, "data-selected", this.selected);
112452
+ mark(group, "data-moving", this.moving);
112453
+ return parts;
112454
+ }
112455
+ /** Not drawn: one of its nodes is missing or not laid out yet. */
112456
+ hide() {
112457
+ this.ends = null;
112458
+ this.drawn = null;
112459
+ this.bounds = null;
112460
+ kept$2(this.parts?.group ?? null, false);
112461
+ kept$2(this.label, false);
112462
+ kept$2(this.endLabels.source, false);
112463
+ kept$2(this.endLabels.target, false);
112464
+ }
112465
+ /** What an image of the diagram draws of it: its line and marks, and its labels; `null` while it is not drawn or not on the page. */
112466
+ get picture() {
112467
+ const p = this.parts;
112468
+ if (!this.ends || !p || !this.live) return null;
112469
+ const labels = [];
112470
+ for (const label of [
112471
+ this.label,
112472
+ this.endLabels.source,
111458
112473
  this.endLabels.target
111459
112474
  ]) if (label) labels.push(label);
111460
112475
  return {
@@ -111494,6 +112509,22 @@ var DiagramEdgeView = class {
111494
112509
  for (const [name, value] of Object.entries(style)) css(group, name, value);
111495
112510
  this.drawnStyle = Object.keys(style);
111496
112511
  }
112512
+ /** Writes its status again, as `setEdgeStatus` changed it: nothing else of the line changes. */
112513
+ drawState() {
112514
+ if (this.parts) this.drawStatus(this.parts.group);
112515
+ }
112516
+ /** Its status: the look's color of it on the line and its marks, and the status in the line's tip. */
112517
+ drawStatus(group) {
112518
+ const status = this.edge.status;
112519
+ put(group, "data-status", status ?? null);
112520
+ if (!status) {
112521
+ removePart(this.tip);
112522
+ this.tip = null;
112523
+ return;
112524
+ }
112525
+ this.tip ??= svgComponent(group, "title", "mx-diagram__edge-tip");
112526
+ text$1(this.tip, statusWords(status, this.edge.statusText));
112527
+ }
111497
112528
  remove() {
111498
112529
  removePart(this.label);
111499
112530
  removePart(this.endLabels.source);
@@ -111644,6 +112675,16 @@ var DiagramLinks = class {
111644
112675
  void 0
111645
112676
  );
111646
112677
  _defineProperty(this, "views", /* @__PURE__ */ new Map());
112678
+ _defineProperty(
112679
+ this,
112680
+ /** What every line tells the diagram: one object for all the lines, however many. */
112681
+ "told",
112682
+ {
112683
+ pressed: (v, e) => this.edgePressed(v, e),
112684
+ clicked: (v, e) => this.host.edgeClicked(v.edge, e),
112685
+ pointer: (what, v, e) => this.host.edgeTold(what, v.edge, e)
112686
+ }
112687
+ );
111647
112688
  _defineProperty(
111648
112689
  this,
111649
112690
  /** The selected connections, by `id`, and the handles over their ends, which take an end to move it. */
@@ -111777,10 +112818,7 @@ var DiagramLinks = class {
111777
112818
  seen.add(edge.id);
111778
112819
  let view = this.views.get(edge.id);
111779
112820
  if (!view) {
111780
- view = new DiagramEdgeView(this.edgeLayer, this.labelLayer, edge, {
111781
- pressed: (v, e) => this.edgePressed(v, e),
111782
- clicked: (v, e) => this.host.edgeClicked(v.edge, e)
111783
- });
112821
+ view = new DiagramEdgeView(this.edgeLayer, this.labelLayer, edge, this.told);
111784
112822
  if (this.region) view.setLive(false);
111785
112823
  this.views.set(edge.id, view);
111786
112824
  }
@@ -112828,565 +113866,6 @@ function num$1(value) {
112828
113866
  return String(Math.round(value * 100) / 100);
112829
113867
  }
112830
113868
  //#endregion
112831
- //#region src/components/diagram/DiagramNodeView.ts
112832
- /** The ports of a node that names none: the middle of each side; a flow comes in at the top and the left and goes out at the right and the bottom. */
112833
- var SIDE_PORTS = [
112834
- {
112835
- id: "top",
112836
- side: "top",
112837
- direction: "target"
112838
- },
112839
- {
112840
- id: "right",
112841
- side: "right",
112842
- direction: "source"
112843
- },
112844
- {
112845
- id: "bottom",
112846
- side: "bottom",
112847
- direction: "source"
112848
- },
112849
- {
112850
- id: "left",
112851
- side: "left",
112852
- direction: "target"
112853
- }
112854
- ];
112855
- var RESIZE_SIDES = [
112856
- "n",
112857
- "ne",
112858
- "e",
112859
- "se",
112860
- "s",
112861
- "sw",
112862
- "w",
112863
- "nw"
112864
- ];
112865
- var STATUS_WORDS = {
112866
- running: "diagramStatusRunning",
112867
- done: "diagramStatusDone",
112868
- error: "diagramStatusError",
112869
- waiting: "diagramStatusWaiting",
112870
- skipped: "diagramStatusSkipped"
112871
- };
112872
- /** What a node's status says, in the kit's language: its word, and the node's `statusText` after it. */
112873
- function statusWords(status, detail) {
112874
- const word = uiLocale.strings[STATUS_WORDS[status]] ?? status;
112875
- return detail ? `${word}: ${detail}` : word;
112876
- }
112877
- /**
112878
- * A node on the surface: the app's object drawn at its place with the content of its kind, its ports and, when it may
112879
- * be resized, its resize handles; its size measured as it is laid out.
112880
- */
112881
- var DiagramNodeView = class {
112882
- constructor(node, host) {
112883
- _defineProperty(this, "part", void 0);
112884
- _defineProperty(
112885
- this,
112886
- /** Where the content of its kind goes: its text, or what the kind made. */
112887
- "body",
112888
- void 0
112889
- );
112890
- _defineProperty(
112891
- this,
112892
- /** The id of its element, which the diagram names as the active node to a screen reader. */
112893
- "elementId",
112894
- nextId("diagram-node")
112895
- );
112896
- _defineProperty(this, "host", void 0);
112897
- _defineProperty(
112898
- this,
112899
- /** A part for each port on each of its sides, by port and side. */
112900
- "portParts",
112901
- /* @__PURE__ */ new Map()
112902
- );
112903
- _defineProperty(this, "resizers", /* @__PURE__ */ new Map());
112904
- _defineProperty(this, "context", void 0);
112905
- _defineProperty(
112906
- this,
112907
- /** The parts of the content ports stand beside, by port, and where those parts are: the share of the way across and down the node to their middles. */
112908
- "anchors",
112909
- /* @__PURE__ */ new Map()
112910
- );
112911
- _defineProperty(this, "offsets", /* @__PURE__ */ new Map());
112912
- _defineProperty(
112913
- this,
112914
- /** The ports, as read when it was drawn. */
112915
- "portList",
112916
- SIDE_PORTS
112917
- );
112918
- _defineProperty(this, "label", null);
112919
- _defineProperty(
112920
- this,
112921
- /** The mark of its status in its corner, while it has one. */
112922
- "statusMark",
112923
- null
112924
- );
112925
- _defineProperty(this, "kind", null);
112926
- _defineProperty(
112927
- this,
112928
- /** The kind whose content it holds now. */
112929
- "made",
112930
- null
112931
- );
112932
- _defineProperty(
112933
- this,
112934
- /** Whether its content is made and laid out: it came into view once, or the diagram shows every node. */
112935
- "entered",
112936
- false
112937
- );
112938
- _defineProperty(
112939
- this,
112940
- /** Whether it is on the page: it lies in view, or the diagram shows every node. */
112941
- "live",
112942
- true
112943
- );
112944
- _defineProperty(
112945
- this,
112946
- /** The part a press drags the node from, when the kind's content named one. */
112947
- "handle",
112948
- null
112949
- );
112950
- _defineProperty(
112951
- this,
112952
- /** What names it, when the kind's content gave it (`context.label`), and what stops the name following its data. */
112953
- "naming",
112954
- null
112955
- );
112956
- _defineProperty(this, "stopNaming", null);
112957
- _defineProperty(
112958
- this,
112959
- /** The app's and the kind's classes and the app's style properties written last, so those taken away come off. */
112960
- "drawnClasses",
112961
- []
112962
- );
112963
- _defineProperty(this, "drawnStyle", []);
112964
- _defineProperty(this, "node", void 0);
112965
- _defineProperty(
112966
- this,
112967
- /** Its border box as laid out, in the diagram's units: the zoom is a transform and does not change it. */
112968
- "size",
112969
- {
112970
- width: 0,
112971
- height: 0
112972
- }
112973
- );
112974
- _defineProperty(
112975
- this,
112976
- /** Hidden in a collapsed group. */
112977
- "hidden",
112978
- false
112979
- );
112980
- _defineProperty(
112981
- this,
112982
- /** The share of the way across and down the node to the middle of each part a port stands beside; a part not laid out is left out. */
112983
- "anchorsRead",
112984
- () => {
112985
- const offsets = /* @__PURE__ */ new Map();
112986
- const box = rectOf(this.part);
112987
- if (box.width <= 0 || box.height <= 0) return offsets;
112988
- for (const [id, at] of this.anchors) {
112989
- const r = rectOf(at);
112990
- if (r.width <= 0 && r.height <= 0) continue;
112991
- offsets.set(id, {
112992
- across: (r.left + r.width / 2 - box.left) / box.width,
112993
- down: (r.top + r.height / 2 - box.top) / box.height
112994
- });
112995
- }
112996
- return offsets;
112997
- }
112998
- );
112999
- _defineProperty(
113000
- this,
113001
- /** The ports stand where their parts are now; their connections are drawn again. */
113002
- "anchorsWritten",
113003
- (offsets) => {
113004
- if (offsets.size === this.offsets.size && [...offsets].every(([id, at]) => {
113005
- const was = this.offsets.get(id);
113006
- return !!was && Math.abs(was.across - at.across) < 1e-4 && Math.abs(was.down - at.down) < 1e-4;
113007
- })) return;
113008
- this.offsets = offsets;
113009
- this.drawPorts();
113010
- this.host.sized(this);
113011
- }
113012
- );
113013
- this.node = node;
113014
- this.host = host;
113015
- this.part = loose("div", "mx-diagram__node");
113016
- this.part.attr.add({
113017
- id: this.elementId,
113018
- role: "group"
113019
- });
113020
- this.body = part(this.part, "div", "mx-diagram__node-content");
113021
- const view = this;
113022
- this.context = {
113023
- get node() {
113024
- return view.node;
113025
- },
113026
- host: this.body,
113027
- diagram: host.diagram,
113028
- get selected() {
113029
- return host.isSelected(view);
113030
- },
113031
- dragHandle(handle) {
113032
- view.handle = handle;
113033
- },
113034
- anchor(id, at) {
113035
- if (at) view.anchors.set(id, at);
113036
- else view.anchors.delete(id);
113037
- view.readAnchors();
113038
- },
113039
- label(read) {
113040
- view.stopNaming?.();
113041
- view.naming = read;
113042
- view.stopNaming = effect(() => {
113043
- const name = read();
113044
- untracked(() => put(view.part, "aria-label", name || view.node.id));
113045
- });
113046
- }
113047
- };
113048
- this.part.motif.setDisposable(() => this.stopNaming?.());
113049
- this.part.motif.on("pointerdown", (_, e) => this.pressed(e));
113050
- this.draw();
113051
- }
113052
- /** Makes its content and lays it out: the first time it comes into view, or at once in a diagram that shows every node. */
113053
- enter() {
113054
- if (this.entered) return;
113055
- this.entered = true;
113056
- onLayout(this.part, "size", (size) => {
113057
- if (!size.width && !size.height) return;
113058
- this.size = size;
113059
- this.host.sized(this);
113060
- this.readAnchors();
113061
- });
113062
- this.draw();
113063
- }
113064
- /** Puts it on the page or takes it off, its content and state kept. */
113065
- setLive(on) {
113066
- this.live = on;
113067
- kept$2(this.part, on && !this.hidden);
113068
- }
113069
- /** Its ports: the node's own, its kind's, or one in the middle of each side. */
113070
- get ports() {
113071
- return this.portList;
113072
- }
113073
- /** Whether the node or its kind names ports of its own. */
113074
- get hasOwnPorts() {
113075
- return !!(this.node.ports ?? this.kind?.ports);
113076
- }
113077
- /** Every port on each of its sides, where it stands now. */
113078
- get places() {
113079
- const rect = this.rect;
113080
- const places = [];
113081
- for (const port of this.portList) for (const side of sidesOf(port)) places.push({
113082
- port,
113083
- side,
113084
- point: portPoint(rect, side, this.offsetOf(port, side))
113085
- });
113086
- return places;
113087
- }
113088
- /** Where a port stands: on the one of its sides nearest `toward`; `null` for a port it does not have. */
113089
- placeOf(id, toward) {
113090
- const port = this.port(id);
113091
- if (!port) return null;
113092
- const rect = this.rect;
113093
- let best = null;
113094
- let nearest = Infinity;
113095
- for (const side of sidesOf(port)) {
113096
- const point = portPoint(rect, side, this.offsetOf(port, side));
113097
- const d = Math.hypot(point.x - toward.x, point.y - toward.y);
113098
- if (d < nearest) {
113099
- nearest = d;
113100
- best = {
113101
- port,
113102
- side,
113103
- point
113104
- };
113105
- }
113106
- }
113107
- return best;
113108
- }
113109
- /** How far along a side a port stands: beside the part its content anchors it to, else at its own offset. */
113110
- offsetOf(port, side) {
113111
- const at = this.offsets.get(port.id);
113112
- if (at) return side === "left" || side === "right" ? at.down : at.across;
113113
- return port.offset ?? .5;
113114
- }
113115
- /** Whether it holds other nodes. */
113116
- get isGroup() {
113117
- return !!this.kind?.group;
113118
- }
113119
- /** Whether it collapses to its header: a group, or a node of a kind that says so. */
113120
- get isCollapsible() {
113121
- return !!(this.kind?.group || this.kind?.collapsible);
113122
- }
113123
- /** Whether the user may resize it (a collapsed node not, until it opens), and the smallest size a resize leaves. */
113124
- get isResizable() {
113125
- if (this.isCollapsible && this.node.collapsed) return false;
113126
- return this.node.resizable ?? this.kind?.resizable ?? false;
113127
- }
113128
- get minSize() {
113129
- return {
113130
- width: this.kind?.minWidth ?? 40,
113131
- height: this.kind?.minHeight ?? 24
113132
- };
113133
- }
113134
- port(id) {
113135
- return id === void 0 ? null : this.ports.find((p) => p.id === id) ?? null;
113136
- }
113137
- /** Marks a port as the end a connection being drawn would take, or would be refused at; none for `null`. */
113138
- markPort(id, state) {
113139
- for (const { port, part: p } of this.portParts.values()) {
113140
- mark(p, "data-target", port === id && state === "target");
113141
- mark(p, "data-refused", port === id && state === "refused");
113142
- }
113143
- }
113144
- /** Marks the ports a connection being drawn may end at; none for `null`. */
113145
- markAvailable(ids) {
113146
- for (const { port, part: p } of this.portParts.values()) mark(p, "data-available", !!ids?.has(port));
113147
- }
113148
- markSelected(on) {
113149
- mark(this.part, "data-selected", on);
113150
- }
113151
- markMovable(on) {
113152
- mark(this.part, "data-movable", on);
113153
- }
113154
- markDragging(on) {
113155
- mark(this.part, "data-dragging", on);
113156
- }
113157
- /** The node the keys are on. */
113158
- markActive(on) {
113159
- mark(this.part, "data-active", on);
113160
- }
113161
- /** A group under it is collapsed: it leaves the surface, in its place. */
113162
- markHidden(on) {
113163
- this.hidden = on;
113164
- if (this.entered) kept$2(this.part, this.live && !on);
113165
- }
113166
- /** A group that will take the node if it is dropped now. */
113167
- markDropTarget(on) {
113168
- mark(this.part, "data-drop-target", on);
113169
- }
113170
- /** What a screen reader calls it: the name its kind's content gives, else its text, else its `id`. */
113171
- get name() {
113172
- return (this.naming ? untracked(this.naming) : this.node.text) || this.node.id;
113173
- }
113174
- /** Writes what the node says now; what did not change is not written again. */
113175
- draw() {
113176
- const node = this.node;
113177
- const kind = this.host.kindOf(node);
113178
- this.kind = kind;
113179
- this.portList = node.ports ?? (typeof kind.ports === "function" ? kind.ports(node) : kind.ports) ?? SIDE_PORTS;
113180
- if (!this.entered) return;
113181
- if (kind !== this.made) this.build(kind);
113182
- put(this.part, "data-id", node.id);
113183
- put(this.part, "data-kind", node.kind ?? null);
113184
- this.drawPlace();
113185
- this.drawSize();
113186
- if (kind.content) kind.update?.(this.context);
113187
- else if (this.label) text$1(this.label, node.text ?? "");
113188
- if (!this.naming) put(this.part, "aria-label", this.name);
113189
- put(this.part, "aria-roledescription", uiLocale.strings.diagramNode);
113190
- mark(this.part, "data-no-connect", node.connectable === false);
113191
- mark(this.part, "data-group", !!kind.group);
113192
- mark(this.part, "data-collapsed", this.isCollapsible && !!node.collapsed);
113193
- mark(this.part, "data-resizable", this.isResizable);
113194
- this.drawLook(kind);
113195
- this.drawStatus();
113196
- this.drawPorts();
113197
- this.drawResizers();
113198
- this.readAnchors();
113199
- }
113200
- /** Moves the node to its place now, while it is dragged: only its place is written. */
113201
- drawPlace() {
113202
- css(this.part, "transform", `translate(${this.node.x}px, ${this.node.y}px)`);
113203
- }
113204
- /**
113205
- * Writes the size the node gives, while it is resized too; without one it takes the size of its content, no smaller
113206
- * than its kind allows. A collapsed group keeps its width and takes the height of its header.
113207
- */
113208
- drawSize() {
113209
- const given = this.given;
113210
- const kind = this.kind;
113211
- css(this.part, "width", given.width !== null ? `${given.width}px` : "");
113212
- css(this.part, "max-width", given.width !== null ? "none" : "");
113213
- css(this.part, "height", given.height !== null ? `${given.height}px` : "");
113214
- const min = this.minSize;
113215
- const minWidth = kind?.minWidth ?? (this.isResizable ? min.width : given.width !== null ? 0 : null);
113216
- const minHeight = kind?.minHeight ?? (this.isResizable ? min.height : given.height !== null ? 0 : null);
113217
- css(this.part, "min-width", this.folded("horizontal") ? "0" : minWidth !== null ? `${minWidth}px` : "");
113218
- css(this.part, "min-height", this.folded("vertical") ? "0" : minHeight !== null ? `${minHeight}px` : "");
113219
- }
113220
- /** Whether it has a size to draw with: laid out, given, or likely (a node of a large diagram not seen yet). */
113221
- get isSized() {
113222
- return !this.hidden && (this.size.width > 0 || this.given.width !== null || this.host.estimate(this).width > 0);
113223
- }
113224
- /** Whether its size is known for sure: laid out, or both sides given. */
113225
- get isMeasured() {
113226
- const given = this.given;
113227
- return !this.hidden && (this.size.width > 0 || given.width !== null && given.height !== null);
113228
- }
113229
- /**
113230
- * Its place and size in the diagram's units: a side it gives as given (no smaller than its kind allows), which holds
113231
- * at once while it is resized; else as laid out, or, not laid out yet in a large diagram, as it is likely to be.
113232
- */
113233
- get rect() {
113234
- const node = this.node;
113235
- const given = this.given;
113236
- const size = this.size.width > 0 ? this.size : this.host.estimate(this);
113237
- const width = given.width !== null ? Math.max(given.width, this.kind?.minWidth ?? 0) : size.width;
113238
- const height = given.height !== null ? Math.max(given.height, this.kind?.minHeight ?? 0) : size.height;
113239
- return {
113240
- x: node.x,
113241
- y: node.y,
113242
- width,
113243
- height
113244
- };
113245
- }
113246
- /** The sides of its size it gives: a collapsed group takes one from its header. */
113247
- get given() {
113248
- const node = this.node;
113249
- return {
113250
- width: node.width != null && !this.folded("horizontal") ? node.width : null,
113251
- height: node.height != null && !this.folded("vertical") ? node.height : null
113252
- };
113253
- }
113254
- /** Whether it is collapsed the way given: `'vertical'` to the height of its header, `'horizontal'` to its width. */
113255
- folded(way) {
113256
- return this.isCollapsible && !!this.node.collapsed && (this.kind?.collapse ?? "vertical") === way;
113257
- }
113258
- /** Reads where the parts its ports stand beside are, with the window's next run. */
113259
- readAnchors() {
113260
- if (this.anchors.size || this.offsets.size) measure(this.part, this.anchorsRead, this.anchorsWritten);
113261
- }
113262
- /** Makes the content of a kind, in place of what the last one made. */
113263
- build(kind) {
113264
- clearParts(this.body);
113265
- this.label = null;
113266
- this.handle = null;
113267
- this.anchors.clear();
113268
- this.offsets = /* @__PURE__ */ new Map();
113269
- this.stopNaming?.();
113270
- this.stopNaming = null;
113271
- this.naming = null;
113272
- this.made = kind;
113273
- if (!kind.content) {
113274
- this.label = part(this.body, "div", "mx-diagram__node-text");
113275
- return;
113276
- }
113277
- const made = kind.content(this.context);
113278
- if (made instanceof ComponentBase) this.body.controls.add(made);
113279
- else if (made !== void 0 && made !== null && made !== "") text$1(this.body, String(made));
113280
- }
113281
- /**
113282
- * A press on the node: a resize handle resizes, a port draws a connection, a control of the content keeps it, and
113283
- * the rest drags the node (off a drag handle, it only selects).
113284
- */
113285
- pressed(e) {
113286
- for (const [side, p] of this.resizers) {
113287
- if (!p.motif.isEventFrom(e)) continue;
113288
- this.host.resizePressed(this, side, e);
113289
- return;
113290
- }
113291
- for (const { port, part: p } of this.portParts.values()) {
113292
- if (!p.motif.isEventFrom(e)) continue;
113293
- this.host.pressed(this, this.port(port), e, false);
113294
- return;
113295
- }
113296
- if (this.fromControl(this.body, e)) return;
113297
- this.host.pressed(this, null, e, !this.handle || this.handle.motif.isEventFrom(e));
113298
- }
113299
- /**
113300
- * Whether an event comes from a control inside `from`: a part that takes focus, a control of the kit whose focus is a
113301
- * part of its own (a field), or one that is off (a button that is off keeps the press too). A layout of the kit, such
113302
- * as a stack, is looked into.
113303
- */
113304
- fromControl(from, e) {
113305
- for (const child of from.controls.items) {
113306
- if (!child.motif.isEventFrom(e)) continue;
113307
- if (canTakeFocus(child)) return true;
113308
- if (child instanceof Control && (child.focusPart !== null && child.focusPart !== child || !child.isEnabled)) return true;
113309
- return this.fromControl(child, e);
113310
- }
113311
- return false;
113312
- }
113313
- /** The app's and the kind's classes, and the app's style properties; those taken away since the last draw come off. */
113314
- drawLook(kind) {
113315
- const classes = `${kind.cssClass ?? ""} ${this.node.cssClass ?? ""}`.split(/\s+/).filter(Boolean);
113316
- for (const name of this.drawnClasses) if (!classes.includes(name)) toggleClass(this.part, name, false);
113317
- for (const name of classes) toggleClass(this.part, name, true);
113318
- this.drawnClasses = classes;
113319
- const style = this.node.style ?? {};
113320
- for (const name of this.drawnStyle) if (!(name in style)) css(this.part, name, "");
113321
- for (const [name, value] of Object.entries(style)) css(this.part, name, value);
113322
- this.drawnStyle = Object.keys(style);
113323
- }
113324
- /** Its status: a mark in its corner with the status in its tip, and the same said with its name to a screen reader. */
113325
- drawStatus() {
113326
- const status = this.node.status;
113327
- put(this.part, "data-status", status ?? null);
113328
- if (!status) {
113329
- removePart(this.statusMark);
113330
- this.statusMark = null;
113331
- put(this.part, "aria-description", null);
113332
- return;
113333
- }
113334
- if (!this.statusMark) {
113335
- this.statusMark = part(this.part, "span", "mx-glyph mx-diagram__status");
113336
- put(this.statusMark, "aria-hidden", "true");
113337
- }
113338
- const said = statusWords(status, this.node.statusText);
113339
- put(this.statusMark, "title", said);
113340
- put(this.part, "aria-description", said);
113341
- }
113342
- /** A part for each port on each of its sides, matched by `id` and side, at its place there. */
113343
- drawPorts() {
113344
- const seen = /* @__PURE__ */ new Set();
113345
- for (const port of this.portList) for (const side of sidesOf(port)) {
113346
- const key = `${port.id}\n${side}`;
113347
- seen.add(key);
113348
- let entry = this.portParts.get(key);
113349
- if (!entry) {
113350
- const p = part(this.part, "div", "mx-diagram__port");
113351
- p.attr.add({ "aria-hidden": "true" });
113352
- entry = {
113353
- port: port.id,
113354
- side,
113355
- part: p
113356
- };
113357
- this.portParts.set(key, entry);
113358
- }
113359
- put(entry.part, "data-port", port.id);
113360
- put(entry.part, "data-side", side);
113361
- put(entry.part, "data-direction", port.direction && port.direction !== "both" ? port.direction : null);
113362
- put(entry.part, "title", port.label || null);
113363
- css(entry.part, "--_at", `${this.offsetOf(port, side) * 100}%`);
113364
- }
113365
- for (const [key, entry] of this.portParts) {
113366
- if (seen.has(key)) continue;
113367
- this.portParts.delete(key);
113368
- removePart(entry.part);
113369
- }
113370
- }
113371
- /** The resize handles of a node the user may resize, at its sides and corners; shown while it is selected. */
113372
- drawResizers() {
113373
- if (!this.isResizable) {
113374
- for (const p of this.resizers.values()) removePart(p);
113375
- this.resizers.clear();
113376
- return;
113377
- }
113378
- for (const side of RESIZE_SIDES) {
113379
- if (this.resizers.has(side)) continue;
113380
- const p = part(this.part, "div", "mx-diagram__resizer");
113381
- p.attr.add({
113382
- "aria-hidden": "true",
113383
- "data-side": side
113384
- });
113385
- this.resizers.set(side, p);
113386
- }
113387
- }
113388
- };
113389
- //#endregion
113390
113869
  //#region src/components/diagram/DiagramOverview.ts
113391
113870
  /**
113392
113871
  * The sketch of a diagram with too many nodes in view to draw in full: each node a box, a group an outline, the
@@ -113655,6 +114134,7 @@ var OWN$10 = [
113655
114134
  "snapToGrid",
113656
114135
  "guides",
113657
114136
  "history",
114137
+ "textEditable",
113658
114138
  "commandScope",
113659
114139
  "minZoom",
113660
114140
  "maxZoom",
@@ -113942,6 +114422,60 @@ var Diagram = class extends Control {
113942
114422
  _defineProperty(this, "pastingEmitter", new Emitter());
113943
114423
  _defineProperty(this, "pastedEmitter", new Emitter());
113944
114424
  _defineProperty(this, "historyChangedEmitter", new Emitter());
114425
+ _defineProperty(this, "nodeClickEmitter", new Emitter());
114426
+ _defineProperty(this, "nodeDblClickEmitter", new Emitter());
114427
+ _defineProperty(this, "nodeMenuEmitter", new Emitter());
114428
+ _defineProperty(this, "nodeMenu", heard(this.nodeMenuEmitter));
114429
+ _defineProperty(this, "nodePointerEnterEmitter", new Emitter());
114430
+ _defineProperty(this, "nodePointerLeaveEmitter", new Emitter());
114431
+ _defineProperty(this, "edgeClickEmitter", new Emitter());
114432
+ _defineProperty(this, "edgeDblClickEmitter", new Emitter());
114433
+ _defineProperty(this, "edgeMenuEmitter", new Emitter());
114434
+ _defineProperty(this, "edgeMenu", heard(this.edgeMenuEmitter));
114435
+ _defineProperty(this, "edgePointerEnterEmitter", new Emitter());
114436
+ _defineProperty(this, "edgePointerLeaveEmitter", new Emitter());
114437
+ _defineProperty(this, "textEditingEmitter", new Emitter());
114438
+ _defineProperty(this, "textChangingEmitter", new Emitter());
114439
+ _defineProperty(this, "textChangedEmitter", new Emitter());
114440
+ _defineProperty(
114441
+ this,
114442
+ /** What every node's part asks of the diagram and tells it: one object for all the nodes, however many. */
114443
+ "nodeHost",
114444
+ {
114445
+ diagram: this,
114446
+ kindOf: (n) => this.kindOf(n),
114447
+ isSelected: (v) => this.chosen.nodes.has(v.node.id),
114448
+ estimate: (v) => this.estimate(v),
114449
+ sized: (v) => {
114450
+ this.noteSize(v);
114451
+ this.links.nodeChanged(v.node.id);
114452
+ this.sizedSince = true;
114453
+ this.askDraw();
114454
+ },
114455
+ pressed: (v, port, e, drags) => {
114456
+ if (this.panning.isSpaceHeld) return;
114457
+ if (port) {
114458
+ if (this.connectable && this.changeable && v.node.connectable !== false) this.links.startConnect(v, port, e);
114459
+ } else this.dragging.nodePressed(v, e, drags);
114460
+ },
114461
+ resizePressed: (v, side, e) => {
114462
+ if (!this.panning.isSpaceHeld) this.dragging.resizePressed(v, side, e);
114463
+ },
114464
+ told: (what, v, e) => this.nodeTold(what, v, e)
114465
+ }
114466
+ );
114467
+ _defineProperty(
114468
+ this,
114469
+ /** When the Menu key or Shift+F10 last opened the app's menu: the `contextmenu` event the browser sends after it stays its own. */
114470
+ "menuKeyAt",
114471
+ -Infinity
114472
+ );
114473
+ _defineProperty(
114474
+ this,
114475
+ /** The node whose text is edited in place, and its editor, while it is. */
114476
+ "editing",
114477
+ null
114478
+ );
113945
114479
  _defineProperty(
113946
114480
  this,
113947
114481
  /** The size of the surface, from its size observer; 0 until it is laid out. */
@@ -114079,6 +114613,7 @@ var Diagram = class extends Control {
114079
114613
  this.edgeReshapedEmitter.fire(e);
114080
114614
  },
114081
114615
  edgeClicked: (edge, e) => this.edgeClicked(edge, e),
114616
+ edgeTold: (what, edge, e) => this.edgeTold(what, edge, e),
114082
114617
  askDraw: () => this.askDraw(),
114083
114618
  nodesMoved: () => {
114084
114619
  this.contentMoved = true;
@@ -114143,6 +114678,19 @@ var Diagram = class extends Control {
114143
114678
  if (own.onPasted) this.onPasted(own.onPasted);
114144
114679
  if (own.onHistoryChanged) this.onHistoryChanged(own.onHistoryChanged);
114145
114680
  if (own.onContentChanged) this.onContentChanged(own.onContentChanged);
114681
+ if (own.onNodeClick) this.onNodeClick(own.onNodeClick);
114682
+ if (own.onNodeDblClick) this.onNodeDblClick(own.onNodeDblClick);
114683
+ if (own.onNodeContextMenu) this.onNodeContextMenu(own.onNodeContextMenu);
114684
+ if (own.onNodePointerEnter) this.onNodePointerEnter(own.onNodePointerEnter);
114685
+ if (own.onNodePointerLeave) this.onNodePointerLeave(own.onNodePointerLeave);
114686
+ if (own.onEdgeClick) this.onEdgeClick(own.onEdgeClick);
114687
+ if (own.onEdgeDblClick) this.onEdgeDblClick(own.onEdgeDblClick);
114688
+ if (own.onEdgeContextMenu) this.onEdgeContextMenu(own.onEdgeContextMenu);
114689
+ if (own.onEdgePointerEnter) this.onEdgePointerEnter(own.onEdgePointerEnter);
114690
+ if (own.onEdgePointerLeave) this.onEdgePointerLeave(own.onEdgePointerLeave);
114691
+ if (own.onTextEditing) this.onTextEditing(own.onTextEditing);
114692
+ if (own.onTextChanging) this.onTextChanging(own.onTextChanging);
114693
+ if (own.onTextChanged) this.onTextChanged(own.onTextChanged);
114146
114694
  if (own.edges === void 0) this.changeProperty("edges", []);
114147
114695
  this.toldViewport = this.viewport;
114148
114696
  this.observeProperty("nodes", () => this.nodesChanged());
@@ -114163,6 +114711,7 @@ var Diagram = class extends Control {
114163
114711
  this.stopKeyConnect();
114164
114712
  this.stopKeyMove();
114165
114713
  this.setKeyBend(null);
114714
+ this.stopEditing(false);
114166
114715
  }
114167
114716
  this.askDraw();
114168
114717
  });
@@ -114210,7 +114759,13 @@ var Diagram = class extends Control {
114210
114759
  ]);
114211
114760
  onLayout(this, "size", (size) => this.resized(size));
114212
114761
  onLayout(this, "look", () => this.askDraw());
114762
+ this.motif.on("contextmenu", (_, e) => {
114763
+ if (performance.now() - this.menuKeyAt >= 1e3) return;
114764
+ this.menuKeyAt = -Infinity;
114765
+ e.preventDefault();
114766
+ });
114213
114767
  this.motif.on("pointerdown", (_, e) => {
114768
+ this.menuKeyAt = -Infinity;
114214
114769
  if (this.fromMap(e)) return;
114215
114770
  if (!(this.nodeLayer.motif.isEventFrom(e) || this.handleLayer.motif.isEventFrom(e) || this.links.took(e)) && !this.panning.isSpaceHeld && this.dragging.surfacePressed(e)) return;
114216
114771
  this.panning.pointerDown(e);
@@ -114235,6 +114790,7 @@ var Diagram = class extends Control {
114235
114790
  this.nodeLayer.motif.on("focusout", () => this.commandState.typing = false);
114236
114791
  this.motif.setDisposable(() => {
114237
114792
  for (const stop of this.commandStops.splice(0)) stop();
114793
+ this.stopEditing(false);
114238
114794
  this.finishLayout?.();
114239
114795
  this.stopMotion();
114240
114796
  this.panning.dispose();
@@ -114260,7 +114816,20 @@ var Diagram = class extends Control {
114260
114816
  this.columnCheckedEmitter,
114261
114817
  this.edgeReshapingEmitter,
114262
114818
  this.edgeReshapedEmitter,
114263
- this.contentChangedEmitter
114819
+ this.contentChangedEmitter,
114820
+ this.nodeClickEmitter,
114821
+ this.nodeDblClickEmitter,
114822
+ this.nodeMenuEmitter,
114823
+ this.nodePointerEnterEmitter,
114824
+ this.nodePointerLeaveEmitter,
114825
+ this.edgeClickEmitter,
114826
+ this.edgeDblClickEmitter,
114827
+ this.edgeMenuEmitter,
114828
+ this.edgePointerEnterEmitter,
114829
+ this.edgePointerLeaveEmitter,
114830
+ this.textEditingEmitter,
114831
+ this.textChangingEmitter,
114832
+ this.textChangedEmitter
114264
114833
  ]) emitter.dispose();
114265
114834
  });
114266
114835
  this.askDraw();
@@ -114341,6 +114910,12 @@ var Diagram = class extends Control {
114341
114910
  set history(value) {
114342
114911
  this.assignProperty("history", value);
114343
114912
  }
114913
+ get textEditable() {
114914
+ return this.getProperty("textEditable") ?? false;
114915
+ }
114916
+ set textEditable(value) {
114917
+ this.assignProperty("textEditable", value);
114918
+ }
114344
114919
  get commandScope() {
114345
114920
  return this.getProperty("commandScope") ?? null;
114346
114921
  }
@@ -114849,6 +115424,45 @@ var Diagram = class extends Control {
114849
115424
  get onContentChanged() {
114850
115425
  return this.contentChangedEmitter.event;
114851
115426
  }
115427
+ get onNodeClick() {
115428
+ return this.nodeClickEmitter.event;
115429
+ }
115430
+ get onNodeDblClick() {
115431
+ return this.nodeDblClickEmitter.event;
115432
+ }
115433
+ get onNodeContextMenu() {
115434
+ return this.nodeMenu.event;
115435
+ }
115436
+ get onNodePointerEnter() {
115437
+ return this.nodePointerEnterEmitter.event;
115438
+ }
115439
+ get onNodePointerLeave() {
115440
+ return this.nodePointerLeaveEmitter.event;
115441
+ }
115442
+ get onEdgeClick() {
115443
+ return this.edgeClickEmitter.event;
115444
+ }
115445
+ get onEdgeDblClick() {
115446
+ return this.edgeDblClickEmitter.event;
115447
+ }
115448
+ get onEdgeContextMenu() {
115449
+ return this.edgeMenu.event;
115450
+ }
115451
+ get onEdgePointerEnter() {
115452
+ return this.edgePointerEnterEmitter.event;
115453
+ }
115454
+ get onEdgePointerLeave() {
115455
+ return this.edgePointerLeaveEmitter.event;
115456
+ }
115457
+ get onTextEditing() {
115458
+ return this.textEditingEmitter.event;
115459
+ }
115460
+ get onTextChanging() {
115461
+ return this.textChangingEmitter.event;
115462
+ }
115463
+ get onTextChanged() {
115464
+ return this.textChangedEmitter.event;
115465
+ }
114852
115466
  /** Makes the selection these nodes and connections, the ones that exist and may be selected; tells when it changed. */
114853
115467
  choose(nodes, edges, byUser) {
114854
115468
  const nodeIds = /* @__PURE__ */ new Set();
@@ -114879,11 +115493,231 @@ var Diagram = class extends Control {
114879
115493
  });
114880
115494
  }
114881
115495
  edgeClicked(edge, e) {
114882
- if (!this.selectable || !this.isEnabled || edge.selectable === false) return;
115496
+ if (!this.isEnabled) return;
115497
+ const args = this.edgeArgs(edge, e, false);
115498
+ this.edgeClickEmitter.fire(args);
115499
+ if (args.cancel || !this.selectable || edge.selectable === false) return;
114883
115500
  if (!(e.shiftKey || e.ctrlKey || e.metaKey)) this.choose([], [edge.id], true);
114884
115501
  else if (this.chosen.edges.has(edge.id)) this.choose(this.chosen.nodes, [...this.chosen.edges].filter((id) => id !== edge.id), true);
114885
115502
  else this.choose(this.chosen.nodes, [...this.chosen.edges, edge.id], true);
114886
115503
  }
115504
+ /** What the pointer did on a node: told; a double click on its text edits it, a right click opens the app's menu. */
115505
+ nodeTold(what, view, e) {
115506
+ if (!this.isEnabled) return;
115507
+ if (what === "click") this.nodeClickEmitter.fire(this.nodeArgs(view, e, false));
115508
+ else if (what === "dblclick") this.nodeOpened(view, e, false, view.isTextEvent(e));
115509
+ else if (what === "contextmenu") this.nodeMenuAsked(view, e, false);
115510
+ else (what === "enter" ? this.nodePointerEnterEmitter : this.nodePointerLeaveEmitter).fire({
115511
+ node: view.node,
115512
+ event: e
115513
+ });
115514
+ }
115515
+ /** What the pointer did on a connection, besides a click: told; a right click opens the app's menu. */
115516
+ edgeTold(what, edge, e) {
115517
+ if (!this.isEnabled) return;
115518
+ if (what === "dblclick") this.edgeDblClickEmitter.fire(this.edgeArgs(edge, e, false));
115519
+ else if (what === "contextmenu") this.edgeMenuAsked(edge, e, false);
115520
+ else (what === "enter" ? this.edgePointerEnterEmitter : this.edgePointerLeaveEmitter).fire({
115521
+ edge,
115522
+ event: e
115523
+ });
115524
+ }
115525
+ /** What a click on a node tells: where it was on the page, or for a key the middle of the node. */
115526
+ nodeArgs(view, e, byKeyboard) {
115527
+ const r = view.rect;
115528
+ const at = !byKeyboard && "clientX" in e ? {
115529
+ x: e.clientX,
115530
+ y: e.clientY
115531
+ } : this.toClient({
115532
+ x: r.x + r.width / 2,
115533
+ y: r.y + r.height / 2
115534
+ });
115535
+ return {
115536
+ node: view.node,
115537
+ event: e,
115538
+ byKeyboard,
115539
+ at,
115540
+ cancel: false
115541
+ };
115542
+ }
115543
+ /** What a click on a connection tells: where it was on the page, or for a key the middle between its ends. */
115544
+ edgeArgs(edge, e, byKeyboard) {
115545
+ let at;
115546
+ const ends = this.links.lineOf(edge.id)?.ends;
115547
+ if (!byKeyboard && "clientX" in e) at = {
115548
+ x: e.clientX,
115549
+ y: e.clientY
115550
+ };
115551
+ else if (ends) at = this.toClient({
115552
+ x: (ends.source.x + ends.target.x) / 2,
115553
+ y: (ends.source.y + ends.target.y) / 2
115554
+ });
115555
+ else at = this.toClientOfSurface(this.middle());
115556
+ return {
115557
+ edge,
115558
+ event: e,
115559
+ byKeyboard,
115560
+ at,
115561
+ cancel: false
115562
+ };
115563
+ }
115564
+ /** A double click on a node, or Alt+Enter on it: told, then its text is edited (`textEditable`), unless canceled. */
115565
+ nodeOpened(view, e, byKeyboard, onText) {
115566
+ const args = this.nodeArgs(view, e, byKeyboard);
115567
+ this.nodeDblClickEmitter.fire(args);
115568
+ if (!args.cancel && onText && this.textEditable) this.startEditing(view, byKeyboard);
115569
+ }
115570
+ /**
115571
+ * A right click on a node, or the Menu key on it: told to the app, which opens its menu there; the browser's own
115572
+ * stays closed, unless canceled. Nothing is told while nobody listens. Returns whether the app took it.
115573
+ */
115574
+ nodeMenuAsked(view, e, byKeyboard) {
115575
+ if (!this.nodeMenu.heard()) return false;
115576
+ const args = this.nodeArgs(view, e, byKeyboard);
115577
+ this.nodeMenuEmitter.fire(args);
115578
+ if (args.cancel) return false;
115579
+ e.preventDefault();
115580
+ return true;
115581
+ }
115582
+ /** A right click on a connection, or the Menu key on it, as `nodeMenuAsked`. */
115583
+ edgeMenuAsked(edge, e, byKeyboard) {
115584
+ if (!this.edgeMenu.heard()) return false;
115585
+ const args = this.edgeArgs(edge, e, byKeyboard);
115586
+ this.edgeMenuEmitter.fire(args);
115587
+ if (args.cancel) return false;
115588
+ e.preventDefault();
115589
+ return true;
115590
+ }
115591
+ /** The Menu key or Shift+F10: the context menu of the connection or the node under the keys. Returns whether the app took it. */
115592
+ keyMenu(e) {
115593
+ const line = this.lineUnderKeys();
115594
+ if (line) return this.edgeMenuAsked(line.edge, e, true);
115595
+ const view = this.active ? this.views.get(this.active) : void 0;
115596
+ return !!view && this.nodeMenuAsked(view, e, true);
115597
+ }
115598
+ /** Alt+Enter: a double click on the connection or the node under the keys. Returns whether there was one. */
115599
+ keyOpen(e) {
115600
+ const line = this.lineUnderKeys();
115601
+ if (line) {
115602
+ this.edgeDblClickEmitter.fire(this.edgeArgs(line.edge, e, true));
115603
+ return true;
115604
+ }
115605
+ const view = this.active ? this.views.get(this.active) : void 0;
115606
+ if (!view) return false;
115607
+ this.nodeOpened(view, e, true, true);
115608
+ return true;
115609
+ }
115610
+ /** What a screen reader calls a connection: its label, else its two nodes. */
115611
+ edgeName(edge) {
115612
+ if (edge.label) return edge.label;
115613
+ const name = (id) => this.views.get(id)?.name ?? id;
115614
+ return uiLocale.text("diagramEdgeName", {
115615
+ source: name(edge.source),
115616
+ target: name(edge.target)
115617
+ });
115618
+ }
115619
+ /** The node F2 and the `rename` command edit the text of: the one under the keys, else the only one selected. */
115620
+ renameTarget() {
115621
+ const id = this.active ?? (this.chosen.nodes.size === 1 && !this.chosen.edges.size ? [...this.chosen.nodes][0] : null);
115622
+ return id ? this.views.get(id) : void 0;
115623
+ }
115624
+ /** Opens the editor of a node's text over it, after `onTextEditing`; an edit going on elsewhere is written first. */
115625
+ startEditing(view, byKeyboard) {
115626
+ if (this.readOnly || !this.isEnabled || !view.live || !view.entered || view.hidden) return false;
115627
+ if (this.editing?.view === view) return true;
115628
+ const args = {
115629
+ node: view.node,
115630
+ text: view.node.text ?? "",
115631
+ byKeyboard,
115632
+ cancel: false
115633
+ };
115634
+ this.textEditingEmitter.fire(args);
115635
+ if (args.cancel) return false;
115636
+ this.stopEditing(true);
115637
+ this.choose([view.node.id], [], true);
115638
+ this.setActive(view.node.id, false);
115639
+ this.reveal(view);
115640
+ const editor = new TextBox({
115641
+ value: args.text,
115642
+ label: uiLocale.text("diagramTextEditor", { name: view.name }),
115643
+ labelMode: "hidden",
115644
+ size: "sm",
115645
+ selectOnFocus: true,
115646
+ updateOn: "input"
115647
+ });
115648
+ editor.class.add("mx-diagram__text-editor");
115649
+ editor.onEnter(() => this.stopEditing(true));
115650
+ editor.motif.on("keydown", (_, e) => {
115651
+ if (e.key !== "Escape") return;
115652
+ this.stopEditing(false);
115653
+ return { cancel: true };
115654
+ });
115655
+ editor.motif.on("focusout", () => {
115656
+ queueMicrotask(() => {
115657
+ if (this.editing?.editor === editor && !holdsFocus(editor)) this.stopEditing(true);
115658
+ });
115659
+ });
115660
+ this.editing = {
115661
+ view,
115662
+ editor
115663
+ };
115664
+ view.holdEditor(editor);
115665
+ editor.focus();
115666
+ return true;
115667
+ }
115668
+ /**
115669
+ * Ends the edit of a node's text: `write` writes the editor's text, after `onTextChanging`, as a step of the history.
115670
+ * The editor goes; when it had focus, focus comes back to the diagram, on the node.
115671
+ */
115672
+ stopEditing(write) {
115673
+ const now = this.editing;
115674
+ if (!now) return;
115675
+ this.editing = null;
115676
+ const { view, editor } = now;
115677
+ const typed = editor.value ?? "";
115678
+ const hadFocus = holdsFocus(editor);
115679
+ view.holdEditor(null);
115680
+ if (write) this.writeText(view, typed);
115681
+ if (!hadFocus || this.isDisposed) return;
115682
+ this.focus();
115683
+ this.setActive(view.node.id, true);
115684
+ }
115685
+ /** Writes a node's new text, after `onTextChanging`, as a step of the history, and tells it. */
115686
+ writeText(view, typed) {
115687
+ const node = view.node;
115688
+ const before = node.text;
115689
+ const previous = before ?? "";
115690
+ if (typed === previous) return;
115691
+ const args = {
115692
+ node,
115693
+ text: typed,
115694
+ previous,
115695
+ cancel: false
115696
+ };
115697
+ this.textChangingEmitter.fire(args);
115698
+ if (args.cancel || args.text === previous) return;
115699
+ const after = args.text;
115700
+ const set = (value) => {
115701
+ if (value === void 0) delete node.text;
115702
+ else node.text = value;
115703
+ this.views.get(node.id)?.draw();
115704
+ };
115705
+ set(after);
115706
+ this.addStep({
115707
+ undo: () => set(before),
115708
+ redo: () => set(after),
115709
+ change: {
115710
+ kind: "text",
115711
+ nodes: [node],
115712
+ edges: []
115713
+ }
115714
+ });
115715
+ this.textChangedEmitter.fire({
115716
+ node,
115717
+ text: after,
115718
+ previous
115719
+ });
115720
+ }
114887
115721
  canMove(view) {
114888
115722
  return this.draggable && this.changeable && view.node.draggable !== false;
114889
115723
  }
@@ -115627,6 +116461,10 @@ var Diagram = class extends Control {
115627
116461
  make("duplicate", "diagramDuplicate", () => this.duplicate(), () => s.nodesSelected > 0 && changes(), "Mod+D"),
115628
116462
  make("delete", "diagramDelete", () => this.dropBend() || this.deleteChosen(true), () => changes() && (s.selected && this.deletable || !!this.bendUnderKeys()), ["Delete", "Backspace"]),
115629
116463
  make("selectAll", "diagramSelectAll", () => this.chooseAll(), () => this.selectable, "Mod+A"),
116464
+ make("rename", "diagramRename", () => {
116465
+ const view = this.renameTarget();
116466
+ if (view) this.startEditing(view, true);
116467
+ }, () => this.textEditable && changes() && (s.nodesSelected === 1 || !!this.active), "F2"),
115630
116468
  make("zoomIn", "diagramZoomIn", () => this.zoomIn({ animate: true }), () => this.zoomable),
115631
116469
  make("zoomOut", "diagramZoomOut", () => this.zoomOut({ animate: true }), () => this.zoomable),
115632
116470
  make("zoomToFit", "diagramFit", () => this.fit({ animate: true })),
@@ -115744,27 +116582,7 @@ var Diagram = class extends Control {
115744
116582
  seen.add(node.id);
115745
116583
  let view = this.views.get(node.id);
115746
116584
  if (!view) {
115747
- view = new DiagramNodeView(node, {
115748
- diagram: this,
115749
- kindOf: (n) => this.kindOf(n),
115750
- isSelected: (v) => this.chosen.nodes.has(v.node.id),
115751
- estimate: (v) => this.estimate(v),
115752
- sized: (v) => {
115753
- this.noteSize(v);
115754
- this.links.nodeChanged(v.node.id);
115755
- this.sizedSince = true;
115756
- this.askDraw();
115757
- },
115758
- pressed: (v, port, e, drags) => {
115759
- if (this.panning.isSpaceHeld) return;
115760
- if (port) {
115761
- if (this.connectable && this.changeable && v.node.connectable !== false) this.links.startConnect(v, port, e);
115762
- } else this.dragging.nodePressed(v, e, drags);
115763
- },
115764
- resizePressed: (v, side, e) => {
115765
- if (!this.panning.isSpaceHeld) this.dragging.resizePressed(v, side, e);
115766
- }
115767
- });
116585
+ view = new DiagramNodeView(node, this.nodeHost);
115768
116586
  this.views.set(node.id, view);
115769
116587
  if (this.lazy) view.live = false;
115770
116588
  else view.enter();
@@ -115777,6 +116595,7 @@ var Diagram = class extends Control {
115777
116595
  }
115778
116596
  for (const [id, view] of this.views) {
115779
116597
  if (seen.has(id)) continue;
116598
+ if (this.editing?.view === view) this.stopEditing(false);
115780
116599
  this.views.delete(id);
115781
116600
  removePart(view.part);
115782
116601
  }
@@ -116161,6 +116980,39 @@ var Diagram = class extends Control {
116161
116980
  return true;
116162
116981
  }
116163
116982
  /**
116983
+ * Shows what a connection is doing as a run goes along it (`null` takes the status away): the look's color of the
116984
+ * status on its line and its marks, unless it has a `color` of its own, a line that moves while it runs, and the
116985
+ * status in the line's tip; a screen reader hears it with the connection's two nodes. Not a step of the history: the
116986
+ * connection's `status` and `statusText` are written, and saved with it unless the app leaves them out. Returns
116987
+ * whether it changed.
116988
+ */
116989
+ setEdgeStatus(id, status, text) {
116990
+ const line = this.links.lineOf(id);
116991
+ if (!line) return false;
116992
+ const edge = line.edge;
116993
+ if ((edge.status ?? null) === status && (edge.statusText || void 0) === (status ? text || void 0 : void 0)) return false;
116994
+ if (status) edge.status = status;
116995
+ else delete edge.status;
116996
+ if (status && text) edge.statusText = text;
116997
+ else delete edge.statusText;
116998
+ line.drawState();
116999
+ if (status) this.announce(uiLocale.text("diagramStatusSaid", {
117000
+ name: this.edgeName(edge),
117001
+ status: statusWords(status, edge.statusText)
117002
+ }));
117003
+ return true;
117004
+ }
117005
+ /**
117006
+ * Edits a node's text in place, as a double click on it does with `textEditable`: an editor opens over the text, and
117007
+ * Enter or leaving it writes the new text as a step of the history, Escape keeps the old one. The node is selected
117008
+ * and brought into view. Returns whether the editor opened: not in a read-only diagram, not for a node off the page
117009
+ * (out of view in a large diagram, or in a collapsed group), and not when `onTextEditing` cancels.
117010
+ */
117011
+ editText(id) {
117012
+ const view = this.views.get(id);
117013
+ return !!view && this.startEditing(view, false);
117014
+ }
117015
+ /**
116164
117016
  * The connections of a node: those that end at it (`direction: 'in'`), start at it (`'out'`) or either, at one of its
116165
117017
  * ports or any. Read in a getter, it follows the connections as they are drawn, taken away and moved.
116166
117018
  */
@@ -116610,6 +117462,14 @@ var Diagram = class extends Control {
116610
117462
  }
116611
117463
  keyDown(e) {
116612
117464
  if (!this.isEnabled || this.nodeLayer.motif.isEventFrom(e) || this.fromMap(e)) return;
117465
+ if (e.key === "ContextMenu" || e.key === "F10" && e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
117466
+ if (!this.connectingFrom && !this.keyMove && this.keyMenu(e)) this.menuKeyAt = performance.now();
117467
+ return;
117468
+ }
117469
+ if (e.key === "Enter" && e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
117470
+ if (!this.connectingFrom && !this.keyMove && this.keyOpen(e)) e.preventDefault();
117471
+ return;
117472
+ }
116613
117473
  if ((e.key === "]" || e.key === "[") && !e.metaKey && (e.getModifierState("AltGraph") || !e.ctrlKey && !e.altKey)) {
116614
117474
  if (!this.connectingFrom && !this.keyMove && this.walkLines(e.key === "]" ? 1 : -1)) e.preventDefault();
116615
117475
  return;
@@ -116716,6 +117576,31 @@ var Diagram = class extends Control {
116716
117576
  this.moveView(next, true);
116717
117577
  }
116718
117578
  };
117579
+ /**
117580
+ * The event of an emitter that counts its listeners: the diagram keeps the browser's context menu closed only for an
117581
+ * app that listens to the diagram's own.
117582
+ */
117583
+ function heard(emitter) {
117584
+ let count = 0;
117585
+ const event = (listener, thisArgs, disposables) => {
117586
+ const own = emitter.event(listener, thisArgs);
117587
+ count++;
117588
+ let gone = false;
117589
+ const subscription = { dispose: () => {
117590
+ if (gone) return;
117591
+ gone = true;
117592
+ count--;
117593
+ own.dispose();
117594
+ } };
117595
+ if (Array.isArray(disposables)) disposables.push(subscription);
117596
+ else disposables?.add(subscription);
117597
+ return subscription;
117598
+ };
117599
+ return {
117600
+ event,
117601
+ heard: () => count > 0
117602
+ };
117603
+ }
116719
117604
  function clamp(value, low, high) {
116720
117605
  return Math.min(Math.max(value, low), high);
116721
117606
  }