@grafloria/element 0.3.23 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/package.json +7 -9
- package/src/index.d.ts +16 -16
- package/src/index.js +58 -339
- package/src/lib/dashboard-kit/dashboard.d.ts +1 -1
- package/src/lib/dashboard-kit/dashboard.js +22 -26
- package/src/lib/dashboard-kit/grid-binder.d.ts +1 -1
- package/src/lib/dashboard-kit/grid-binder.js +62 -65
- package/src/lib/dashboard-kit/grid-mapping.js +14 -26
- package/src/lib/dashboard-kit/index.d.ts +5 -5
- package/src/lib/dashboard-kit/index.js +5 -30
- package/src/lib/dashboard-kit/styles.js +4 -8
- package/src/lib/dashboard-kit/widgets.d.ts +1 -1
- package/src/lib/dashboard-kit/widgets.js +16 -26
- package/src/lib/diagram-kit/card.d.ts +2 -2
- package/src/lib/diagram-kit/card.js +22 -32
- package/src/lib/diagram-kit/editing.js +15 -20
- package/src/lib/diagram-kit/er.d.ts +1 -1
- package/src/lib/diagram-kit/er.js +15 -18
- package/src/lib/diagram-kit/handles.d.ts +4 -4
- package/src/lib/diagram-kit/handles.js +16 -29
- package/src/lib/diagram-kit/index.d.ts +10 -10
- package/src/lib/diagram-kit/index.js +10 -50
- package/src/lib/diagram-kit/join-guidance.js +9 -18
- package/src/lib/diagram-kit/rows.js +1 -4
- package/src/lib/diagram-kit/styles.js +4 -8
- package/src/lib/diagram-kit/uml.js +10 -13
- package/src/lib/diagram-kit/update.d.ts +1 -1
- package/src/lib/diagram-kit/update.js +19 -26
- package/src/lib/grafloria-flow-element.js +19 -24
- package/src/lib/grafloria.d.ts +4 -4
- package/src/lib/grafloria.js +12 -17
- package/src/lib/load.d.ts +3 -3
- package/src/lib/load.js +19 -22
- package/src/lib/node-type-registry.js +6 -14
- package/src/lib/stencil-kit/builders.js +4 -10
- package/src/lib/stencil-kit/card-builders.js +14 -17
- package/src/lib/stencil-kit/index.d.ts +7 -7
- package/src/lib/stencil-kit/index.js +6 -16
- package/src/lib/stencil-kit/palette.js +14 -17
- package/src/lib/stencil-kit/shape-data.js +25 -28
- package/src/lib/stencil-kit/styles.js +1 -4
- package/esm/src/index.js +0 -295
- package/esm/src/lib/dashboard-kit/dashboard.js +0 -590
- package/esm/src/lib/dashboard-kit/grid-binder.js +0 -1633
- package/esm/src/lib/dashboard-kit/grid-mapping.js +0 -164
- package/esm/src/lib/dashboard-kit/index.js +0 -8
- package/esm/src/lib/dashboard-kit/styles.js +0 -205
- package/esm/src/lib/dashboard-kit/widgets.js +0 -379
- package/esm/src/lib/diagram-kit/card.js +0 -199
- package/esm/src/lib/diagram-kit/editing.js +0 -448
- package/esm/src/lib/diagram-kit/er.js +0 -160
- package/esm/src/lib/diagram-kit/handles.js +0 -312
- package/esm/src/lib/diagram-kit/index.js +0 -15
- package/esm/src/lib/diagram-kit/join-guidance.js +0 -322
- package/esm/src/lib/diagram-kit/rows.js +0 -144
- package/esm/src/lib/diagram-kit/styles.js +0 -118
- package/esm/src/lib/diagram-kit/uml.js +0 -135
- package/esm/src/lib/diagram-kit/update.js +0 -244
- package/esm/src/lib/grafloria-flow-element.js +0 -266
- package/esm/src/lib/grafloria.js +0 -69
- package/esm/src/lib/load.js +0 -252
- package/esm/src/lib/node-type-registry.js +0 -42
- package/esm/src/lib/stencil-kit/builders.js +0 -18
- package/esm/src/lib/stencil-kit/card-builders.js +0 -105
- package/esm/src/lib/stencil-kit/index.js +0 -9
- package/esm/src/lib/stencil-kit/palette.js +0 -427
- package/esm/src/lib/stencil-kit/shape-data.js +0 -537
- package/esm/src/lib/stencil-kit/styles.js +0 -126
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Live editing — `updateEntity` / `updateClass` mutate a rendered kit card in
|
|
4
3
|
* place (P3, the foundation the in-canvas editing chrome is built on).
|
|
@@ -28,21 +27,15 @@
|
|
|
28
27
|
* intended extension point — every basic command does it). When no engine is
|
|
29
28
|
* present the edit still applies, just non-undoably.
|
|
30
29
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
exports.addColumnAt = addColumnAt;
|
|
35
|
-
exports.removeColumnAt = removeColumnAt;
|
|
36
|
-
exports.renameColumnAt = renameColumnAt;
|
|
37
|
-
const tslib_1 = require("tslib");
|
|
38
|
-
const engine_1 = require("@grafloria/engine");
|
|
39
|
-
const card_1 = require("./card");
|
|
30
|
+
import { __awaiter } from "tslib";
|
|
31
|
+
import { Command, PortModel, LinkModel } from '@grafloria/engine';
|
|
32
|
+
import { entityCardContent, entityAutoHeight, classCardContent, classAutoHeight, erRowCenterY, rowIndexFromY, matchColumns, } from './card.js';
|
|
40
33
|
/**
|
|
41
34
|
* The single undoable edit. Captures the card's whole before-state on first
|
|
42
35
|
* execute and restores it on undo, so an edit — however many rows and edges it
|
|
43
36
|
* touched — is one Ctrl+Z.
|
|
44
37
|
*/
|
|
45
|
-
class UpdateCardCommand extends
|
|
38
|
+
class UpdateCardCommand extends Command {
|
|
46
39
|
constructor(nodeId, kind, build) {
|
|
47
40
|
super(kind === 'er' ? 'Edit table' : 'Edit class');
|
|
48
41
|
this.nodeId = nodeId;
|
|
@@ -74,12 +67,12 @@ class UpdateCardCommand extends engine_1.Command {
|
|
|
74
67
|
if (this.kind === 'er') {
|
|
75
68
|
const oldCols = ((_c = oldKit['columns']) !== null && _c !== void 0 ? _c : []);
|
|
76
69
|
const newCols = ((_d = result.newKit['columns']) !== null && _d !== void 0 ? _d : []);
|
|
77
|
-
const map =
|
|
70
|
+
const map = matchColumns(oldCols, newCols);
|
|
78
71
|
for (const port of [...node.getPorts()]) {
|
|
79
72
|
const args = (_e = port.layout) === null || _e === void 0 ? void 0 : _e.args;
|
|
80
73
|
if (((_f = port.layout) === null || _f === void 0 ? void 0 : _f.strategy) !== 'absolute' || !args || args.units !== 'px' || args.y == null)
|
|
81
74
|
continue;
|
|
82
|
-
const oldIdx =
|
|
75
|
+
const oldIdx = rowIndexFromY(args.y);
|
|
83
76
|
if (oldIdx < 0 || oldIdx >= oldCols.length)
|
|
84
77
|
continue; // not a row-pinned field port
|
|
85
78
|
const newIdx = map.get(oldIdx);
|
|
@@ -97,7 +90,7 @@ class UpdateCardCommand extends engine_1.Command {
|
|
|
97
90
|
else {
|
|
98
91
|
// Move the port to its column's NEW row; keep the ±dy spread. x tracks
|
|
99
92
|
// the (possibly changed) width by side, so a widened table stays pinned.
|
|
100
|
-
args.y =
|
|
93
|
+
args.y = erRowCenterY(newIdx);
|
|
101
94
|
const side = (_g = port.alignment) === null || _g === void 0 ? void 0 : _g.side;
|
|
102
95
|
args.x = side === 'left' ? 0 : side === 'right' ? newWidth : newWidth / 2;
|
|
103
96
|
// A nested-arg mutation is not tracked — nudge the port so the model
|
|
@@ -132,12 +125,12 @@ class UpdateCardCommand extends engine_1.Command {
|
|
|
132
125
|
live.setOffset(Object.assign({}, ((_a = sp['offset']) !== null && _a !== void 0 ? _a : { x: 0, y: 0 })));
|
|
133
126
|
}
|
|
134
127
|
else {
|
|
135
|
-
node.addPort(
|
|
128
|
+
node.addPort(PortModel.fromJSON(sp));
|
|
136
129
|
}
|
|
137
130
|
}
|
|
138
131
|
for (const sl of this.before.links) {
|
|
139
132
|
if (!model.getLink(sl['id']))
|
|
140
|
-
model.addLink(
|
|
133
|
+
model.addLink(LinkModel.fromJSON(sl));
|
|
141
134
|
}
|
|
142
135
|
}
|
|
143
136
|
canExecute(context) {
|
|
@@ -150,7 +143,7 @@ class UpdateCardCommand extends engine_1.Command {
|
|
|
150
143
|
}
|
|
151
144
|
/** Route a build through the engine's command stack (one undo step) or apply it directly. */
|
|
152
145
|
function runUpdate(api, nodeId, kind, build) {
|
|
153
|
-
return
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
147
|
var _a, _b, _c, _d, _e;
|
|
155
148
|
const model = (_a = api.getModel) === null || _a === void 0 ? void 0 : _a.call(api);
|
|
156
149
|
const node = (_b = model === null || model === void 0 ? void 0 : model.getNode) === null || _b === void 0 ? void 0 : _b.call(model, nodeId);
|
|
@@ -177,7 +170,7 @@ const isEditable = (node) => (node === null || node === void 0 ? void 0 : node.g
|
|
|
177
170
|
*
|
|
178
171
|
* @returns whether the node existed and the edit was applied.
|
|
179
172
|
*/
|
|
180
|
-
function updateEntity(api, entityId, delta) {
|
|
173
|
+
export function updateEntity(api, entityId, delta) {
|
|
181
174
|
var _a, _b, _c;
|
|
182
175
|
const editable = isEditable((_c = (_b = (_a = api.getModel) === null || _a === void 0 ? void 0 : _a.call(api)) === null || _b === void 0 ? void 0 : _b.getNode) === null || _c === void 0 ? void 0 : _c.call(_b, entityId));
|
|
183
176
|
const build = (oldKit) => {
|
|
@@ -192,8 +185,8 @@ function updateEntity(api, entityId, delta) {
|
|
|
192
185
|
newEntity.columns = delta.columns;
|
|
193
186
|
return {
|
|
194
187
|
newKit: newEntity,
|
|
195
|
-
content:
|
|
196
|
-
height:
|
|
188
|
+
content: entityCardContent(newEntity, editable),
|
|
189
|
+
height: entityAutoHeight(newEntity, editable),
|
|
197
190
|
width: newEntity.width,
|
|
198
191
|
};
|
|
199
192
|
};
|
|
@@ -203,7 +196,7 @@ function updateEntity(api, entityId, delta) {
|
|
|
203
196
|
* Edit a rendered UML class in place. `delta` may change the name, stereotype,
|
|
204
197
|
* abstract flag, attributes, methods, and width/height. One undoable step.
|
|
205
198
|
*/
|
|
206
|
-
function updateClass(api, classId, delta) {
|
|
199
|
+
export function updateClass(api, classId, delta) {
|
|
207
200
|
var _a, _b, _c;
|
|
208
201
|
const editable = isEditable((_c = (_b = (_a = api.getModel) === null || _a === void 0 ? void 0 : _a.call(api)) === null || _b === void 0 ? void 0 : _b.getNode) === null || _c === void 0 ? void 0 : _c.call(_b, classId));
|
|
209
202
|
const build = (oldKit) => {
|
|
@@ -224,8 +217,8 @@ function updateClass(api, classId, delta) {
|
|
|
224
217
|
newClass.methods = delta.methods;
|
|
225
218
|
return {
|
|
226
219
|
newKit: newClass,
|
|
227
|
-
content:
|
|
228
|
-
height:
|
|
220
|
+
content: classCardContent(newClass, editable),
|
|
221
|
+
height: classAutoHeight(newClass, editable),
|
|
229
222
|
width: newClass.width,
|
|
230
223
|
};
|
|
231
224
|
};
|
|
@@ -233,19 +226,19 @@ function updateClass(api, classId, delta) {
|
|
|
233
226
|
}
|
|
234
227
|
// -- small column helpers, for the editing chrome and embedders --------------
|
|
235
228
|
/** Append a column (immutably) — returns the new column array. */
|
|
236
|
-
function addColumnAt(columns, column, at = columns.length) {
|
|
229
|
+
export function addColumnAt(columns, column, at = columns.length) {
|
|
237
230
|
const next = columns.slice();
|
|
238
231
|
next.splice(Math.max(0, Math.min(at, next.length)), 0, column);
|
|
239
232
|
return next;
|
|
240
233
|
}
|
|
241
234
|
/** Remove the column at `index` — returns the new column array. */
|
|
242
|
-
function removeColumnAt(columns, index) {
|
|
235
|
+
export function removeColumnAt(columns, index) {
|
|
243
236
|
const next = columns.slice();
|
|
244
237
|
next.splice(index, 1);
|
|
245
238
|
return next;
|
|
246
239
|
}
|
|
247
240
|
/** Rename the column at `index` — returns a new array with a NEW object there. */
|
|
248
|
-
function renameColumnAt(columns, index, name) {
|
|
241
|
+
export function renameColumnAt(columns, index, name) {
|
|
249
242
|
return columns.map((c, i) => (i === index ? Object.assign(Object.assign({}, c), { name }) : c));
|
|
250
243
|
}
|
|
251
244
|
//# sourceMappingURL=update.js.map
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.GrafloriaFlowElement = exports.GRAFLORIA_EVENTS = void 0;
|
|
4
|
-
exports.defineGrafloriaFlow = defineGrafloriaFlow;
|
|
5
|
-
const renderer_1 = require("@grafloria/renderer");
|
|
6
|
-
const node_type_registry_1 = require("./node-type-registry");
|
|
1
|
+
import { createDiagram, DARK_THEME, LIGHT_THEME } from '@grafloria/renderer';
|
|
2
|
+
import { getNodeType, renderFromTemplate } from './node-type-registry.js';
|
|
7
3
|
/**
|
|
8
4
|
* `<grafloria-flow>` — the universal embed.
|
|
9
5
|
*
|
|
@@ -36,11 +32,11 @@ const node_type_registry_1 = require("./node-type-registry");
|
|
|
36
32
|
* Everything it does is delegation. There is no diagram logic in this file.
|
|
37
33
|
*/
|
|
38
34
|
const THEMES = {
|
|
39
|
-
light:
|
|
40
|
-
dark:
|
|
35
|
+
light: LIGHT_THEME,
|
|
36
|
+
dark: DARK_THEME,
|
|
41
37
|
};
|
|
42
38
|
/** Events emitted on the element. All bubble and cross shadow boundaries. */
|
|
43
|
-
|
|
39
|
+
export const GRAFLORIA_EVENTS = {
|
|
44
40
|
ready: 'grafloria-ready',
|
|
45
41
|
nodesChange: 'grafloria-nodes-change',
|
|
46
42
|
edgesChange: 'grafloria-edges-change',
|
|
@@ -66,7 +62,7 @@ const HTMLElementBase = typeof HTMLElement !== 'undefined'
|
|
|
66
62
|
? HTMLElement
|
|
67
63
|
: class {
|
|
68
64
|
};
|
|
69
|
-
class GrafloriaFlowElement extends HTMLElementBase {
|
|
65
|
+
export class GrafloriaFlowElement extends HTMLElementBase {
|
|
70
66
|
constructor() {
|
|
71
67
|
super(...arguments);
|
|
72
68
|
this.instance = null;
|
|
@@ -126,7 +122,7 @@ class GrafloriaFlowElement extends HTMLElementBase {
|
|
|
126
122
|
this.appendChild(this.canvas);
|
|
127
123
|
if (!this.style.display)
|
|
128
124
|
this.style.display = 'block';
|
|
129
|
-
this.instance =
|
|
125
|
+
this.instance = createDiagram(this.canvas, this.buildOptions());
|
|
130
126
|
this.wireEvents(this.instance);
|
|
131
127
|
}
|
|
132
128
|
disconnectedCallback() {
|
|
@@ -199,14 +195,14 @@ class GrafloriaFlowElement extends HTMLElementBase {
|
|
|
199
195
|
* (`Grafloria.registerNodeType`), or a slotted `<template data-node-type="…">`.
|
|
200
196
|
*/
|
|
201
197
|
renderCustomNode(node, element) {
|
|
202
|
-
const renderer =
|
|
198
|
+
const renderer = getNodeType(node.type);
|
|
203
199
|
if (renderer) {
|
|
204
200
|
renderer(node, element);
|
|
205
201
|
return;
|
|
206
202
|
}
|
|
207
203
|
const template = this.querySelector(`template[data-node-type="${cssEscape(node.type)}"]`);
|
|
208
204
|
if (template) {
|
|
209
|
-
|
|
205
|
+
renderFromTemplate(template, node, element);
|
|
210
206
|
return;
|
|
211
207
|
}
|
|
212
208
|
// Nothing registered: leave the host empty rather than throwing inside a
|
|
@@ -214,7 +210,7 @@ class GrafloriaFlowElement extends HTMLElementBase {
|
|
|
214
210
|
}
|
|
215
211
|
resolveTheme() {
|
|
216
212
|
var _a, _b;
|
|
217
|
-
return (_b = THEMES[(_a = this.getAttribute('theme')) !== null && _a !== void 0 ? _a : 'light']) !== null && _b !== void 0 ? _b :
|
|
213
|
+
return (_b = THEMES[(_a = this.getAttribute('theme')) !== null && _a !== void 0 ? _a : 'light']) !== null && _b !== void 0 ? _b : LIGHT_THEME;
|
|
218
214
|
}
|
|
219
215
|
readAttributeModel() {
|
|
220
216
|
if (this._nodes.length === 0 && this.hasAttribute('nodes')) {
|
|
@@ -229,17 +225,16 @@ class GrafloriaFlowElement extends HTMLElementBase {
|
|
|
229
225
|
const forward = (type, detail) => {
|
|
230
226
|
this.dispatchEvent(new CustomEvent(type, { detail, bubbles: true, composed: true }));
|
|
231
227
|
};
|
|
232
|
-
instance.on('ready', () => forward(
|
|
233
|
-
instance.on('nodes:change', (payload) => forward(
|
|
234
|
-
instance.on('edges:change', (payload) => forward(
|
|
235
|
-
instance.on('selection:change', (payload) => forward(
|
|
236
|
-
instance.on('connect', (payload) => forward(
|
|
237
|
-
instance.on('node:click', (payload) => forward(
|
|
238
|
-
instance.on('edge:click', (payload) => forward(
|
|
239
|
-
instance.on('viewport:change', (payload) => forward(
|
|
228
|
+
instance.on('ready', () => forward(GRAFLORIA_EVENTS.ready, { diagram: instance }));
|
|
229
|
+
instance.on('nodes:change', (payload) => forward(GRAFLORIA_EVENTS.nodesChange, payload));
|
|
230
|
+
instance.on('edges:change', (payload) => forward(GRAFLORIA_EVENTS.edgesChange, payload));
|
|
231
|
+
instance.on('selection:change', (payload) => forward(GRAFLORIA_EVENTS.selectionChange, payload));
|
|
232
|
+
instance.on('connect', (payload) => forward(GRAFLORIA_EVENTS.connect, payload));
|
|
233
|
+
instance.on('node:click', (payload) => forward(GRAFLORIA_EVENTS.nodeClick, payload));
|
|
234
|
+
instance.on('edge:click', (payload) => forward(GRAFLORIA_EVENTS.edgeClick, payload));
|
|
235
|
+
instance.on('viewport:change', (payload) => forward(GRAFLORIA_EVENTS.viewportChange, payload));
|
|
240
236
|
}
|
|
241
237
|
}
|
|
242
|
-
exports.GrafloriaFlowElement = GrafloriaFlowElement;
|
|
243
238
|
/** JSON attribute → value. A malformed attribute must not take the page down. */
|
|
244
239
|
function parseJsonAttribute(raw, fallback) {
|
|
245
240
|
if (!raw)
|
|
@@ -261,7 +256,7 @@ function cssEscape(value) {
|
|
|
261
256
|
* `customElements` does not exist) — which is what lets a bundle be imported
|
|
262
257
|
* from an SSR entry point without a `typeof window` dance at every call site.
|
|
263
258
|
*/
|
|
264
|
-
function defineGrafloriaFlow(tagName = 'grafloria-flow') {
|
|
259
|
+
export function defineGrafloriaFlow(tagName = 'grafloria-flow') {
|
|
265
260
|
if (typeof customElements === 'undefined')
|
|
266
261
|
return;
|
|
267
262
|
if (customElements.get(tagName))
|
package/src/lib/grafloria.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CreateDiagramOptions, DiagramInstance, EdgeSpec, NodeSpec, StaticRenderOptions, StaticRenderResult } from '@grafloria/renderer';
|
|
2
|
-
import { defineGrafloriaFlow } from './grafloria-flow-element';
|
|
3
|
-
import type { DashboardSpec } from './dashboard-kit';
|
|
4
|
-
import { registerNodeType, registeredNodeTypes } from './node-type-registry';
|
|
5
|
-
import type { NodeTypeRenderer } from './node-type-registry';
|
|
2
|
+
import { defineGrafloriaFlow } from './grafloria-flow-element.js';
|
|
3
|
+
import type { DashboardSpec } from './dashboard-kit/index.js';
|
|
4
|
+
import { registerNodeType, registeredNodeTypes } from './node-type-registry.js';
|
|
5
|
+
import type { NodeTypeRenderer } from './node-type-registry.js';
|
|
6
6
|
/**
|
|
7
7
|
* `Grafloria` — the Mermaid-shaped top-level API.
|
|
8
8
|
*
|
package/src/lib/grafloria.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.render = render;
|
|
5
|
-
exports.renderStatic = renderStatic;
|
|
6
|
-
const renderer_1 = require("@grafloria/renderer");
|
|
7
|
-
const grafloria_flow_element_1 = require("./grafloria-flow-element");
|
|
8
|
-
const node_type_registry_1 = require("./node-type-registry");
|
|
1
|
+
import { createDiagram, renderToStaticSVG } from '@grafloria/renderer';
|
|
2
|
+
import { defineGrafloriaFlow } from './grafloria-flow-element.js';
|
|
3
|
+
import { registerNodeType, registeredNodeTypes, getNodeType } from './node-type-registry.js';
|
|
9
4
|
/**
|
|
10
5
|
* Mount `spec` into `target` and return the live instance.
|
|
11
6
|
*
|
|
@@ -16,7 +11,7 @@ const node_type_registry_1 = require("./node-type-registry");
|
|
|
16
11
|
* style text DSL. The engine does have a DSL, but wiring it in is a separate
|
|
17
12
|
* card — `render()` is the embedding surface, not a parser.
|
|
18
13
|
*/
|
|
19
|
-
function render(spec, target, options = {}) {
|
|
14
|
+
export function render(spec, target, options = {}) {
|
|
20
15
|
var _a, _b, _c, _d;
|
|
21
16
|
const element = typeof target === 'string'
|
|
22
17
|
? document.querySelector(target)
|
|
@@ -27,14 +22,14 @@ function render(spec, target, options = {}) {
|
|
|
27
22
|
// Kit specs (dashboard()) carry looser node typing than DiagramSpec — both
|
|
28
23
|
// flow into createDiagram's NodeInput[] the same way.
|
|
29
24
|
const parsed = (typeof spec === 'string' ? parseSpec(spec) : spec);
|
|
30
|
-
const instance =
|
|
25
|
+
const instance = createDiagram(element, Object.assign(Object.assign({}, options), { nodes: (_a = parsed.nodes) !== null && _a !== void 0 ? _a : [], edges: (_b = parsed.edges) !== null && _b !== void 0 ? _b : [],
|
|
31
26
|
// Wire the global registry in, so `registerNodeType` works for the tiny API
|
|
32
27
|
// exactly as it does for `<grafloria-flow>` — unless the caller supplies their
|
|
33
28
|
// own. A KIT SPEC may also carry its own painter (dashboard() does: every
|
|
34
29
|
// widget is a custom HTML node), and it must be honoured — otherwise the
|
|
35
30
|
// documented one-liner `render(dashboard({…}), host)` mounts a board whose
|
|
36
31
|
// widgets never paint. Precedence: explicit option > spec > registry.
|
|
37
|
-
renderCustomNode: (_d = (_c = options.renderCustomNode) !== null && _c !== void 0 ? _c : parsed.renderCustomNode) !== null && _d !== void 0 ? _d : ((node, host) => { var _a; return (_a =
|
|
32
|
+
renderCustomNode: (_d = (_c = options.renderCustomNode) !== null && _c !== void 0 ? _c : parsed.renderCustomNode) !== null && _d !== void 0 ? _d : ((node, host) => { var _a; return (_a = getNodeType(node.type)) === null || _a === void 0 ? void 0 : _a(node, host); }) }));
|
|
38
33
|
// Diagram-kit specs (erDiagram/umlDiagram) carry a `finalize(api)` for the
|
|
39
34
|
// post-render wiring that needs the LIVE instance — row interactions,
|
|
40
35
|
// multiplicity chips. Auto-run it so a kit diagram is fully wired from one
|
|
@@ -51,8 +46,8 @@ function render(spec, target, options = {}) {
|
|
|
51
46
|
return instance;
|
|
52
47
|
}
|
|
53
48
|
/** Server-side render (Card 6). Re-exported so the tiny API is self-contained. */
|
|
54
|
-
function renderStatic(options = {}) {
|
|
55
|
-
return
|
|
49
|
+
export function renderStatic(options = {}) {
|
|
50
|
+
return renderToStaticSVG(options);
|
|
56
51
|
}
|
|
57
52
|
function parseSpec(spec) {
|
|
58
53
|
try {
|
|
@@ -63,12 +58,12 @@ function parseSpec(spec) {
|
|
|
63
58
|
}
|
|
64
59
|
}
|
|
65
60
|
/** The namespace object, for `import { Grafloria }` and for `<script>` globals. */
|
|
66
|
-
|
|
61
|
+
export const Grafloria = {
|
|
67
62
|
render,
|
|
68
63
|
renderStatic,
|
|
69
|
-
registerNodeType
|
|
70
|
-
registeredNodeTypes
|
|
64
|
+
registerNodeType,
|
|
65
|
+
registeredNodeTypes,
|
|
71
66
|
/** Register `<grafloria-flow>` (called for you when you import this package). */
|
|
72
|
-
define:
|
|
67
|
+
define: defineGrafloriaFlow,
|
|
73
68
|
};
|
|
74
69
|
//# sourceMappingURL=grafloria.js.map
|
package/src/lib/load.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DiagramDocumentEnvelope, DiagramModel, LinkModel, NodeModel, SerializedDiagramData } from '@grafloria/engine';
|
|
2
|
-
import { type DashboardGridHandle } from './dashboard-kit/grid-binder';
|
|
3
|
-
import { type WidgetRenderer } from './dashboard-kit/widgets';
|
|
4
|
-
import { type DashboardHandle } from './dashboard-kit/dashboard';
|
|
2
|
+
import { type DashboardGridHandle } from './dashboard-kit/grid-binder.js';
|
|
3
|
+
import { type WidgetRenderer } from './dashboard-kit/widgets.js';
|
|
4
|
+
import { type DashboardHandle } from './dashboard-kit/dashboard.js';
|
|
5
5
|
/** Anything `DiagramSerializer.deserialize()` accepts, or the JSON string of it. */
|
|
6
6
|
export type SavedDiagram = SerializedDiagramData | DiagramDocumentEnvelope | Record<string, unknown> | string;
|
|
7
7
|
export interface FromDocumentOptions {
|
package/src/lib/load.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fromDocument = fromDocument;
|
|
4
1
|
/**
|
|
5
2
|
* `fromDocument()` — the LOAD front door.
|
|
6
3
|
*
|
|
@@ -64,15 +61,15 @@ exports.fromDocument = fromDocument;
|
|
|
64
61
|
* "widget" got dashboard chrome painted over it; requiring the stamp the kit
|
|
65
62
|
* itself wrote keeps the registry the general seam it is meant to be.
|
|
66
63
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
import { DiagramSerializer } from '@grafloria/engine';
|
|
65
|
+
import { getNodeType } from './node-type-registry.js';
|
|
66
|
+
import { bindRowInteractions } from './diagram-kit/rows.js';
|
|
67
|
+
import { bindCardEditing } from './diagram-kit/editing.js';
|
|
68
|
+
import { ensureDiagramKitStyles } from './diagram-kit/styles.js';
|
|
69
|
+
import { bindDashboardGrid } from './dashboard-kit/grid-binder.js';
|
|
70
|
+
import { ensureDashboardKitStyles } from './dashboard-kit/styles.js';
|
|
71
|
+
import { defaultWidgetRenderer } from './dashboard-kit/widgets.js';
|
|
72
|
+
import { createDashboardHandle, } from './dashboard-kit/dashboard.js';
|
|
76
73
|
/** True when the node is an ER entity card or a UML class card. */
|
|
77
74
|
function isDiagramKitCard(node) {
|
|
78
75
|
return node.getMetadata('kitEntity') !== undefined || node.getMetadata('kitClass') !== undefined;
|
|
@@ -102,10 +99,10 @@ function widgetSpecOf(node) {
|
|
|
102
99
|
* Accepts the flat serializer form, the portable envelope, or the JSON string
|
|
103
100
|
* of either.
|
|
104
101
|
*/
|
|
105
|
-
function fromDocument(document, options = {}) {
|
|
102
|
+
export function fromDocument(document, options = {}) {
|
|
106
103
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
107
104
|
const parsed = typeof document === 'string' ? parseDocument(document) : document;
|
|
108
|
-
const model = new
|
|
105
|
+
const model = new DiagramSerializer().deserialize(parsed);
|
|
109
106
|
const nodes = model.getNodes();
|
|
110
107
|
const groups = model.getGroups();
|
|
111
108
|
const boards = new Map();
|
|
@@ -113,10 +110,10 @@ function fromDocument(document, options = {}) {
|
|
|
113
110
|
// so an un-styled card would come back as unstyled divs. Only for documents
|
|
114
111
|
// that actually contain that kit's nodes.
|
|
115
112
|
if (nodes.some(isDiagramKitCard))
|
|
116
|
-
|
|
113
|
+
ensureDiagramKitStyles();
|
|
117
114
|
if (nodes.some((n) => widgetSpecOf(n) !== null))
|
|
118
|
-
|
|
119
|
-
const paintWidget = (_a = options.renderWidget) !== null && _a !== void 0 ? _a :
|
|
115
|
+
ensureDashboardKitStyles();
|
|
116
|
+
const paintWidget = (_a = options.renderWidget) !== null && _a !== void 0 ? _a : defaultWidgetRenderer;
|
|
120
117
|
// -- reconstruct the dashboard handle's context from the loaded model -------
|
|
121
118
|
// Every board group carries `dashboardBoard` geometry; its widget members
|
|
122
119
|
// carry `widgetSpec`/title/span/rows — the canonical, lossless source for
|
|
@@ -178,7 +175,7 @@ function fromDocument(document, options = {}) {
|
|
|
178
175
|
active: (_s = activeGroup === null || activeGroup === void 0 ? void 0 : activeGroup.id) !== null && _s !== void 0 ? _s : 'main',
|
|
179
176
|
apiRef: null,
|
|
180
177
|
};
|
|
181
|
-
const handle =
|
|
178
|
+
const handle = createDashboardHandle(ctx);
|
|
182
179
|
const renderCustomNode = (node, host) => {
|
|
183
180
|
var _a, _b;
|
|
184
181
|
if (options.renderCustomNode)
|
|
@@ -191,7 +188,7 @@ function fromDocument(document, options = {}) {
|
|
|
191
188
|
ctx.hosts.set(node.id, host); // captured so update()/repaint() can find the host
|
|
192
189
|
return paintWidget(widget, host);
|
|
193
190
|
}
|
|
194
|
-
(_b =
|
|
191
|
+
(_b = getNodeType(node.type)) === null || _b === void 0 ? void 0 : _b(node, host);
|
|
195
192
|
};
|
|
196
193
|
const finalize = (api) => {
|
|
197
194
|
var _a, _b, _c, _d;
|
|
@@ -223,10 +220,10 @@ function fromDocument(document, options = {}) {
|
|
|
223
220
|
// `rowSelection: false` is recorded only when it is the non-default, so an
|
|
224
221
|
// ordinary document stays byte-identical to what it always was.
|
|
225
222
|
if (!cards.some((n) => n.getMetadata('kitRowSelection') === false)) {
|
|
226
|
-
|
|
223
|
+
bindRowInteractions(a);
|
|
227
224
|
}
|
|
228
225
|
if (cards.some((n) => n.getMetadata('kitEditable') === true)) {
|
|
229
|
-
|
|
226
|
+
bindCardEditing(a);
|
|
230
227
|
}
|
|
231
228
|
}
|
|
232
229
|
// -- dashboard boards -----------------------------------------------------
|
|
@@ -239,7 +236,7 @@ function fromDocument(document, options = {}) {
|
|
|
239
236
|
const board = group.getMetadata('dashboardBoard');
|
|
240
237
|
if (!board)
|
|
241
238
|
continue;
|
|
242
|
-
boards.set(group.id,
|
|
239
|
+
boards.set(group.id, bindDashboardGrid(a, group, Object.assign({}, board)));
|
|
243
240
|
}
|
|
244
241
|
};
|
|
245
242
|
return { nodes, edges: model.getLinks(), renderCustomNode, finalize, model, boards, handle };
|
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerNodeType = registerNodeType;
|
|
4
|
-
exports.getNodeType = getNodeType;
|
|
5
|
-
exports.hasNodeType = hasNodeType;
|
|
6
|
-
exports.unregisterNodeType = unregisterNodeType;
|
|
7
|
-
exports.registeredNodeTypes = registeredNodeTypes;
|
|
8
|
-
exports.renderFromTemplate = renderFromTemplate;
|
|
9
1
|
const registry = new Map();
|
|
10
2
|
/** Register (or replace) a node type globally. */
|
|
11
|
-
function registerNodeType(type, renderer) {
|
|
3
|
+
export function registerNodeType(type, renderer) {
|
|
12
4
|
registry.set(type, renderer);
|
|
13
5
|
}
|
|
14
|
-
function getNodeType(type) {
|
|
6
|
+
export function getNodeType(type) {
|
|
15
7
|
return registry.get(type);
|
|
16
8
|
}
|
|
17
|
-
function hasNodeType(type) {
|
|
9
|
+
export function hasNodeType(type) {
|
|
18
10
|
return registry.has(type);
|
|
19
11
|
}
|
|
20
12
|
/** Drop a registration (mostly for tests). */
|
|
21
|
-
function unregisterNodeType(type) {
|
|
13
|
+
export function unregisterNodeType(type) {
|
|
22
14
|
registry.delete(type);
|
|
23
15
|
}
|
|
24
16
|
/** Every registered type name. */
|
|
25
|
-
function registeredNodeTypes() {
|
|
17
|
+
export function registeredNodeTypes() {
|
|
26
18
|
return [...registry.keys()];
|
|
27
19
|
}
|
|
28
20
|
/**
|
|
@@ -34,7 +26,7 @@ function registeredNodeTypes() {
|
|
|
34
26
|
* user-supplied, and a template engine that injected raw HTML here would be an
|
|
35
27
|
* XSS vector in every host that embeds us.
|
|
36
28
|
*/
|
|
37
|
-
function renderFromTemplate(template, node, element) {
|
|
29
|
+
export function renderFromTemplate(template, node, element) {
|
|
38
30
|
const fragment = template.content.cloneNode(true);
|
|
39
31
|
const fields = fragment.querySelectorAll('[data-field]');
|
|
40
32
|
for (const field of Array.from(fields)) {
|
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerStencilBuilder = registerStencilBuilder;
|
|
4
|
-
exports.getStencilBuilder = getStencilBuilder;
|
|
5
|
-
exports.unregisterStencilBuilder = unregisterStencilBuilder;
|
|
6
|
-
exports.registeredStencilBuilders = registeredStencilBuilders;
|
|
7
1
|
const builders = new Map();
|
|
8
2
|
/** Register the builder for a master id. Last registration wins. */
|
|
9
|
-
function registerStencilBuilder(masterId, builder) {
|
|
3
|
+
export function registerStencilBuilder(masterId, builder) {
|
|
10
4
|
builders.set(masterId, builder);
|
|
11
5
|
}
|
|
12
6
|
/** The builder for a master id, or undefined for the default template path. */
|
|
13
|
-
function getStencilBuilder(masterId) {
|
|
7
|
+
export function getStencilBuilder(masterId) {
|
|
14
8
|
return builders.get(masterId);
|
|
15
9
|
}
|
|
16
10
|
/** Drop a registration (tests, or a host replacing a built-in). */
|
|
17
|
-
function unregisterStencilBuilder(masterId) {
|
|
11
|
+
export function unregisterStencilBuilder(masterId) {
|
|
18
12
|
return builders.delete(masterId);
|
|
19
13
|
}
|
|
20
14
|
/** Every master id that currently resolves to a card builder. */
|
|
21
|
-
function registeredStencilBuilders() {
|
|
15
|
+
export function registeredStencilBuilders() {
|
|
22
16
|
return [...builders.keys()].sort();
|
|
23
17
|
}
|
|
24
18
|
//# sourceMappingURL=builders.js.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerCardBuilders = registerCardBuilders;
|
|
4
1
|
/**
|
|
5
2
|
* Card builders for the stencil palette — the bridge that finally lets a
|
|
6
3
|
* dropped "Entity" or "Class" be a REAL kit card instead of a rectangle.
|
|
@@ -15,9 +12,9 @@ exports.registerCardBuilders = registerCardBuilders;
|
|
|
15
12
|
* after a drop is safe and is what makes the FIRST dropped card interactive on
|
|
16
13
|
* a canvas that was never built by a kit.
|
|
17
14
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
import { NodeModel } from '@grafloria/engine';
|
|
16
|
+
import { entityCardContent, entityAutoHeight, classCardContent, classAutoHeight, bindRowInteractions, bindCardEditing, ensureDiagramKitStyles, } from '../diagram-kit/index.js';
|
|
17
|
+
import { registerStencilBuilder } from './builders.js';
|
|
21
18
|
/** Cards are transparent: the HTML body IS the card, the shape must not paint. */
|
|
22
19
|
const CARD_SHAPE = { type: 'rect', fill: 'none', stroke: 'none' };
|
|
23
20
|
const CARD_STYLE = { fill: 'transparent', stroke: 'transparent', strokeWidth: 0 };
|
|
@@ -26,8 +23,8 @@ const nextId = (prefix) => `${prefix}-${++seq}`;
|
|
|
26
23
|
/** Turn the kit's card spec into a live node, and make the canvas interactive. */
|
|
27
24
|
function mountCard(ctx, opts) {
|
|
28
25
|
var _a, _b, _c, _d;
|
|
29
|
-
|
|
30
|
-
const node = new
|
|
26
|
+
ensureDiagramKitStyles();
|
|
27
|
+
const node = new NodeModel({
|
|
31
28
|
id: opts.id,
|
|
32
29
|
type: 'kit-card',
|
|
33
30
|
position: { x: ctx.at.x, y: ctx.at.y },
|
|
@@ -48,20 +45,20 @@ function mountCard(ctx, opts) {
|
|
|
48
45
|
if (container) {
|
|
49
46
|
const kitApi = Object.assign(Object.assign({}, ctx.api), { container });
|
|
50
47
|
try {
|
|
51
|
-
|
|
48
|
+
bindRowInteractions(kitApi);
|
|
52
49
|
}
|
|
53
50
|
catch ( /* optional */_e) { /* optional */ }
|
|
54
51
|
try {
|
|
55
|
-
|
|
52
|
+
bindCardEditing(kitApi);
|
|
56
53
|
}
|
|
57
54
|
catch ( /* optional */_f) { /* optional */ }
|
|
58
55
|
}
|
|
59
56
|
return node;
|
|
60
57
|
}
|
|
61
58
|
/** Register the built-in card builders (ER entity/table, UML classifiers). */
|
|
62
|
-
function registerCardBuilders() {
|
|
59
|
+
export function registerCardBuilders() {
|
|
63
60
|
for (const masterId of ['erd-entity', 'erd-table', 'erd-associative-entity', 'erd-bridge-entity']) {
|
|
64
|
-
|
|
61
|
+
registerStencilBuilder(masterId, (ctx) => {
|
|
65
62
|
var _a, _b;
|
|
66
63
|
const id = nextId('entity');
|
|
67
64
|
const spec = {
|
|
@@ -75,15 +72,15 @@ function registerCardBuilders() {
|
|
|
75
72
|
return mountCard(ctx, {
|
|
76
73
|
id,
|
|
77
74
|
width: 220,
|
|
78
|
-
height:
|
|
79
|
-
content:
|
|
75
|
+
height: entityAutoHeight(spec, true),
|
|
76
|
+
content: entityCardContent(spec, true),
|
|
80
77
|
metaKey: 'kitEntity',
|
|
81
78
|
spec,
|
|
82
79
|
});
|
|
83
80
|
});
|
|
84
81
|
}
|
|
85
82
|
for (const masterId of ['uml-class', 'uml-abstract-class', 'uml-interface']) {
|
|
86
|
-
|
|
83
|
+
registerStencilBuilder(masterId, (ctx) => {
|
|
87
84
|
var _a, _b;
|
|
88
85
|
const id = nextId('class');
|
|
89
86
|
const spec = {
|
|
@@ -97,8 +94,8 @@ function registerCardBuilders() {
|
|
|
97
94
|
return mountCard(ctx, {
|
|
98
95
|
id,
|
|
99
96
|
width: 220,
|
|
100
|
-
height:
|
|
101
|
-
content:
|
|
97
|
+
height: classAutoHeight(spec, true),
|
|
98
|
+
content: classCardContent(spec, true),
|
|
102
99
|
metaKey: 'kitClass',
|
|
103
100
|
spec,
|
|
104
101
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { bindStencilPalette } from './palette';
|
|
2
|
-
export type { StencilPaletteApi, StencilPaletteOptions, StencilPaletteHandle, } from './palette';
|
|
3
|
-
export { bindShapeDataPanel } from './shape-data';
|
|
4
|
-
export type { ShapeDataPanelApi, ShapeDataPanelOptions, ShapeDataPanelHandle } from './shape-data';
|
|
5
|
-
export { ensureStencilKitStyles } from './styles';
|
|
6
|
-
export { registerStencilBuilder, getStencilBuilder, unregisterStencilBuilder, registeredStencilBuilders, } from './builders';
|
|
7
|
-
export type { StencilBuilder, StencilBuildContext } from './builders';
|
|
1
|
+
export { bindStencilPalette } from './palette.js';
|
|
2
|
+
export type { StencilPaletteApi, StencilPaletteOptions, StencilPaletteHandle, } from './palette.js';
|
|
3
|
+
export { bindShapeDataPanel } from './shape-data.js';
|
|
4
|
+
export type { ShapeDataPanelApi, ShapeDataPanelOptions, ShapeDataPanelHandle } from './shape-data.js';
|
|
5
|
+
export { ensureStencilKitStyles } from './styles.js';
|
|
6
|
+
export { registerStencilBuilder, getStencilBuilder, unregisterStencilBuilder, registeredStencilBuilders, } from './builders.js';
|
|
7
|
+
export type { StencilBuilder, StencilBuildContext } from './builders.js';
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var shape_data_1 = require("./shape-data");
|
|
7
|
-
Object.defineProperty(exports, "bindShapeDataPanel", { enumerable: true, get: function () { return shape_data_1.bindShapeDataPanel; } });
|
|
8
|
-
var styles_1 = require("./styles");
|
|
9
|
-
Object.defineProperty(exports, "ensureStencilKitStyles", { enumerable: true, get: function () { return styles_1.ensureStencilKitStyles; } });
|
|
10
|
-
var builders_1 = require("./builders");
|
|
11
|
-
Object.defineProperty(exports, "registerStencilBuilder", { enumerable: true, get: function () { return builders_1.registerStencilBuilder; } });
|
|
12
|
-
Object.defineProperty(exports, "getStencilBuilder", { enumerable: true, get: function () { return builders_1.getStencilBuilder; } });
|
|
13
|
-
Object.defineProperty(exports, "unregisterStencilBuilder", { enumerable: true, get: function () { return builders_1.unregisterStencilBuilder; } });
|
|
14
|
-
Object.defineProperty(exports, "registeredStencilBuilders", { enumerable: true, get: function () { return builders_1.registeredStencilBuilders; } });
|
|
15
|
-
const card_builders_1 = require("./card-builders");
|
|
1
|
+
export { bindStencilPalette } from './palette.js';
|
|
2
|
+
export { bindShapeDataPanel } from './shape-data.js';
|
|
3
|
+
export { ensureStencilKitStyles } from './styles.js';
|
|
4
|
+
export { registerStencilBuilder, getStencilBuilder, unregisterStencilBuilder, registeredStencilBuilders, } from './builders.js';
|
|
5
|
+
import { registerCardBuilders } from './card-builders.js';
|
|
16
6
|
// The ER/UML card builders ship registered — dropping "Entity" gives a real,
|
|
17
7
|
// editable table out of the box.
|
|
18
|
-
|
|
8
|
+
registerCardBuilders();
|
|
19
9
|
//# sourceMappingURL=index.js.map
|