@peter.prib/renderengine 0.12.0 → 0.13.0

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 (31) hide show
  1. package/README.md +10 -4
  2. package/dist/renderengine-workspace.umd.js +1920 -1055
  3. package/dist/renderengine.umd.js +1901 -1052
  4. package/documentation/REFERENCE.md +66 -5
  5. package/package.json +1 -1
  6. package/src/charting/Axis.js +47 -5
  7. package/src/charting/DiagramEditor.js +239 -34
  8. package/src/charting/ModelFileFormat.js +47 -0
  9. package/src/charting/archimate/ArchimateCanvasEditor.js +1108 -1012
  10. package/src/charting/archimate/deleteFromModel.js +57 -0
  11. package/src/charting/archimate/elementMenuItems.js +3 -1
  12. package/src/charting/archimate/heatMaps.js +169 -0
  13. package/src/charting/archimate/index.js +1 -0
  14. package/src/charting/charts/BarChart.js +5 -5
  15. package/src/charting/charts/BarChartBase.js +21 -3
  16. package/src/charting/charts/GroupedBarChart.js +7 -9
  17. package/src/charting/charts/TableChart.js +18 -2
  18. package/src/charting/diagrams/ArchimateModel.js +33 -0
  19. package/src/charting/diagrams/DeleteFromModelCommand.js +81 -0
  20. package/src/charting/diagrams/EdgeGeometry.js +16 -0
  21. package/src/charting/edgeStyle/EdgeStyleSchema.js +6 -2
  22. package/src/charting/pivot/PivotGridChart.js +1 -1
  23. package/src/charting/pivot/PivotView.js +11 -2
  24. package/src/charting/table/TableView.js +10 -1
  25. package/src/charting/table/TableViewChart.js +1 -1
  26. package/src/charting/templates/Template.js +10 -0
  27. package/src/exportImage.js +45 -18
  28. package/src/index.js +17 -4
  29. package/src/workspace/parts/ArchimateCanvasPart.js +3 -0
  30. package/src/workspace/parts/DiagramEditorPart.js +2 -0
  31. package/src/workspace/parts/ModelHosted.js +15 -4
@@ -1,5 +1,6 @@
1
1
  import { pickFile } from './toolbar/pickFile.js';
2
2
  import { downloadBlob } from '../exportImage.js';
3
+ import { FormDialog } from './FormDialog.js';
3
4
 
4
5
  /**
5
6
  * ModelFileFormat — one file format a model is exported to and imported
@@ -100,6 +101,52 @@ export function modelFileMenuItems(formats, {
100
101
  return groups.flatMap((group, i) => (i ? [{ separator: true }, ...group] : group));
101
102
  }
102
103
 
104
+ /**
105
+ * The part of pasted text that is a model in `format`: the text as it is when
106
+ * the format recognizes it; else, as an assistant or a page would wrap it, a
107
+ * fenced block (```json … ```), or the text from its first { (or [) to its
108
+ * last } (or ]). Null when none is.
109
+ * @param {ModelFileFormat} format - one that reads text
110
+ * @param {string} text
111
+ * @returns {string|null}
112
+ */
113
+ export function findPayload(format, text) {
114
+ const candidates = [String(text ?? '').trim()];
115
+ for (const m of candidates[0].matchAll(/```[\w-]*[ \t]*\r?\n([\s\S]*?)```/g)) candidates.push(m[1].trim());
116
+ for (const [open, close] of [['{', '}'], ['[', ']']]) {
117
+ const from = candidates[0].indexOf(open), to = candidates[0].lastIndexOf(close);
118
+ if (from >= 0 && to > from) candidates.push(candidates[0].slice(from, to + 1));
119
+ }
120
+ return candidates.find(c => c && format.recognizes(c)) ?? null;
121
+ }
122
+
123
+ /**
124
+ * Import a model from pasted text rather than a file: a dialog with a text
125
+ * box; what is pasted may be wrapped in other text (findPayload). The new
126
+ * model goes to `onImport`; text with no model in it is refused in the dialog.
127
+ * @param {ModelFileFormat} format - one that reads text
128
+ * @returns {FormDialog}
129
+ */
130
+ export function askPasteImport(format, { onImport, document: doc = globalThis.document } = {}) {
131
+ let model = null;
132
+ const dialog = new FormDialog({
133
+ title: `Paste ${format.label}`,
134
+ description: `Paste the ${format.label} text: a file's contents, or an answer or page that has it in it (in a \`\`\` block, say).`,
135
+ fields: [{ key: 'text', label: 'Text', type: 'textarea', rows: 14, value: '' }],
136
+ submitLabel: 'Import',
137
+ idPrefix: 'paste-import-',
138
+ document: doc,
139
+ validate: ({ text }) => {
140
+ const payload = findPayload(format, text);
141
+ if (!payload) return `No ${format.label} found in what is pasted`;
142
+ try { model = format.import(payload); return null; } catch (err) { return `It could not be read: ${err.message}`; }
143
+ },
144
+ onApply: () => onImport(model),
145
+ });
146
+ dialog.open();
147
+ return dialog;
148
+ }
149
+
103
150
  /**
104
151
  * Ask for a file and import it in `format`; resolves to the new model, or
105
152
  * null when no file was chosen or it could not be read (reported).