@platforma-sdk/ui-vue 1.87.0 → 1.88.3
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/.turbo/turbo-build.log +35 -12
- package/.turbo/turbo-formatter$colon$check.log +1 -1
- package/.turbo/turbo-linter$colon$check.log +1 -1
- package/CHANGELOG.md +37 -0
- package/dist/columnLinkViews.d.ts +97 -0
- package/dist/columnLinkViews.d.ts.map +1 -0
- package/dist/columnLinkViews.js +208 -0
- package/dist/columnLinkViews.js.map +1 -0
- package/dist/columnLinkViews.test.d.ts +2 -0
- package/dist/columnLinkViews.test.d.ts.map +1 -0
- package/dist/columnLinks.d.ts +5 -0
- package/dist/columnLinks.d.ts.map +1 -0
- package/dist/columnLinks.js +5 -0
- package/dist/columnLinks.js.map +1 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.js +7 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.js.map +1 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.jsdomtest.d.ts +2 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.jsdomtest.d.ts.map +1 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.style.css +1 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.style.js +13 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.style.js.map +1 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.vue.d.ts +4 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.vue.d.ts.map +1 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.vue2.js +79 -0
- package/dist/components/PlBlockDependencies/PlBlockDependencies.vue2.js.map +1 -0
- package/dist/components/PlBlockDependencies/fold.d.ts +25 -0
- package/dist/components/PlBlockDependencies/fold.d.ts.map +1 -0
- package/dist/components/PlBlockDependencies/fold.js +55 -0
- package/dist/components/PlBlockDependencies/fold.js.map +1 -0
- package/dist/components/PlBlockDependencies/index.d.ts +2 -0
- package/dist/components/PlBlockDependencies/index.d.ts.map +1 -0
- package/dist/components/PlBlockDependencies/index.js +1 -0
- package/dist/components/PlBlockName/PlBlockName.js +7 -0
- package/dist/components/PlBlockName/PlBlockName.js.map +1 -0
- package/dist/components/PlBlockName/PlBlockName.jsdomtest.d.ts +2 -0
- package/dist/components/PlBlockName/PlBlockName.jsdomtest.d.ts.map +1 -0
- package/dist/components/PlBlockName/PlBlockName.style.css +1 -0
- package/dist/components/PlBlockName/PlBlockName.style.js +5 -0
- package/dist/components/PlBlockName/PlBlockName.style.js.map +1 -0
- package/dist/components/PlBlockName/PlBlockName.vue.d.ts +14 -0
- package/dist/components/PlBlockName/PlBlockName.vue.d.ts.map +1 -0
- package/dist/components/PlBlockName/PlBlockName.vue2.js +33 -0
- package/dist/components/PlBlockName/PlBlockName.vue2.js.map +1 -0
- package/dist/components/PlBlockName/index.d.ts +2 -0
- package/dist/components/PlBlockName/index.d.ts.map +1 -0
- package/dist/components/PlBlockName/index.js +1 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.js +6 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.js.map +1 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.jsdomtest.d.ts +2 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.jsdomtest.d.ts.map +1 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.vue.d.ts +26 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.vue.d.ts.map +1 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.vue2.js +37 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdown.vue2.js.map +1 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.js +6 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.js.map +1 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.vue.d.ts +26 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.vue.d.ts.map +1 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.vue2.js +37 -0
- package/dist/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.vue2.js.map +1 -0
- package/dist/components/PlColumnValueDropdown/index.d.ts +5 -0
- package/dist/components/PlColumnValueDropdown/index.d.ts.map +1 -0
- package/dist/components/PlColumnValueDropdown/index.js +4 -0
- package/dist/components/PlColumnValueDropdown/settings.d.ts +34 -0
- package/dist/components/PlColumnValueDropdown/settings.d.ts.map +1 -0
- package/dist/components/PlColumnValueDropdown/settings.js +25 -0
- package/dist/components/PlColumnValueDropdown/settings.js.map +1 -0
- package/dist/components/PlColumnValueDropdown/settings.test.d.ts +2 -0
- package/dist/components/PlColumnValueDropdown/settings.test.d.ts.map +1 -0
- package/dist/components/PlColumnValueDropdown/useColumnValueOptions.d.ts +20 -0
- package/dist/components/PlColumnValueDropdown/useColumnValueOptions.d.ts.map +1 -0
- package/dist/components/PlColumnValueDropdown/useColumnValueOptions.js +45 -0
- package/dist/components/PlColumnValueDropdown/useColumnValueOptions.js.map +1 -0
- package/dist/components/PlColumnValueDropdown/useColumnValueOptions.test.d.ts +2 -0
- package/dist/components/PlColumnValueDropdown/useColumnValueOptions.test.d.ts.map +1 -0
- package/dist/components/PlDatasetSelector/PlDatasetSelector.js.map +1 -1
- package/dist/components/PlDatasetSelector/PlDatasetSelector.vue.d.ts.map +1 -1
- package/dist/components/PlDatasetSelector/PlDatasetSelector.vue2.js +49 -35
- package/dist/components/PlDatasetSelector/PlDatasetSelector.vue2.js.map +1 -1
- package/dist/components/PlDatasetSelector/__tests__/missingValueHint.jsdomtest.d.ts +2 -0
- package/dist/components/PlDatasetSelector/__tests__/missingValueHint.jsdomtest.d.ts.map +1 -0
- package/dist/components/ValuePickers/ValuePickers.jsdomtest.d.ts +2 -0
- package/dist/components/ValuePickers/ValuePickers.jsdomtest.d.ts.map +1 -0
- package/dist/components/ValuePickers/columnLinksMissingValue.d.ts +25 -0
- package/dist/components/ValuePickers/columnLinksMissingValue.d.ts.map +1 -0
- package/dist/components/ValuePickers/columnLinksMissingValue.js +35 -0
- package/dist/components/ValuePickers/columnLinksMissingValue.js.map +1 -0
- package/dist/components/ValuePickers/columnLinksMissingValue.jsdomtest.d.ts +2 -0
- package/dist/components/ValuePickers/columnLinksMissingValue.jsdomtest.d.ts.map +1 -0
- package/dist/components/ValuePickers/index.d.ts +276 -0
- package/dist/components/ValuePickers/index.d.ts.map +1 -0
- package/dist/components/ValuePickers/index.js +22 -0
- package/dist/components/ValuePickers/index.js.map +1 -0
- package/dist/composition/useOpenBlock.d.ts +12 -0
- package/dist/composition/useOpenBlock.d.ts.map +1 -0
- package/dist/composition/useOpenBlock.js +20 -0
- package/dist/composition/useOpenBlock.js.map +1 -0
- package/dist/composition/useOpenBlock.test.d.ts +2 -0
- package/dist/composition/useOpenBlock.test.d.ts.map +1 -0
- package/dist/defineApp.d.ts +2 -0
- package/dist/defineApp.d.ts.map +1 -1
- package/dist/defineApp.js +30 -29
- package/dist/defineApp.js.map +1 -1
- package/dist/index.js +48 -40
- package/dist/index.js.map +1 -1
- package/dist/internal/createAppV3.d.ts +3 -1
- package/dist/internal/createAppV3.d.ts.map +1 -1
- package/dist/internal/createAppV3.js +2 -1
- package/dist/internal/createAppV3.js.map +1 -1
- package/dist/lib.d.ts +5 -0
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +49 -38
- package/package.json +6 -6
- package/src/columnLinkViews.test.ts +540 -0
- package/src/columnLinkViews.ts +368 -0
- package/src/columnLinks.ts +6 -0
- package/src/components/PlBlockDependencies/PlBlockDependencies.jsdomtest.ts +101 -0
- package/src/components/PlBlockDependencies/PlBlockDependencies.vue +132 -0
- package/src/components/PlBlockDependencies/fold.ts +85 -0
- package/src/components/PlBlockDependencies/index.ts +1 -0
- package/src/components/PlBlockName/PlBlockName.jsdomtest.ts +52 -0
- package/src/components/PlBlockName/PlBlockName.vue +56 -0
- package/src/components/PlBlockName/index.ts +1 -0
- package/src/components/PlColumnValueDropdown/PlColumnValueDropdown.jsdomtest.ts +144 -0
- package/src/components/PlColumnValueDropdown/PlColumnValueDropdown.vue +50 -0
- package/src/components/PlColumnValueDropdown/PlColumnValueDropdownMulti.vue +50 -0
- package/src/components/PlColumnValueDropdown/index.ts +4 -0
- package/src/components/PlColumnValueDropdown/settings.test.ts +86 -0
- package/src/components/PlColumnValueDropdown/settings.ts +59 -0
- package/src/components/PlColumnValueDropdown/useColumnValueOptions.test.ts +114 -0
- package/src/components/PlColumnValueDropdown/useColumnValueOptions.ts +77 -0
- package/src/components/PlDatasetSelector/PlDatasetSelector.vue +36 -1
- package/src/components/PlDatasetSelector/__tests__/missingValueHint.jsdomtest.ts +81 -0
- package/src/components/ValuePickers/ValuePickers.jsdomtest.ts +77 -0
- package/src/components/ValuePickers/columnLinksMissingValue.jsdomtest.ts +82 -0
- package/src/components/ValuePickers/columnLinksMissingValue.ts +56 -0
- package/src/components/ValuePickers/index.ts +66 -0
- package/src/composition/useOpenBlock.test.ts +49 -0
- package/src/composition/useOpenBlock.ts +41 -0
- package/src/defineApp.ts +8 -8
- package/src/internal/createAppV3.ts +6 -1
- package/src/lib.ts +14 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { groupBy, uniq } from "es-toolkit";
|
|
2
|
+
import {
|
|
3
|
+
collectColumnReferences,
|
|
4
|
+
isColumnUniversalId,
|
|
5
|
+
isColumnUniversalKey,
|
|
6
|
+
isColumnValueId,
|
|
7
|
+
type BlockColumnLinks,
|
|
8
|
+
type BlockOutput,
|
|
9
|
+
type ColumnLink,
|
|
10
|
+
type ColumnUniversalId,
|
|
11
|
+
type ColumnValue,
|
|
12
|
+
type LinkCheck,
|
|
13
|
+
} from "@platforma-sdk/model";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Which way a link goes: `usedBy` — another block's args reference an output of this block;
|
|
17
|
+
* `uses` — this block's args reference an output of another block.
|
|
18
|
+
*/
|
|
19
|
+
export type LinkSide = "usedBy" | "uses";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* What one other block uses of one output, or what this block uses of one output of another
|
|
23
|
+
* block. All references of that block to the output that pick values are merged into one row,
|
|
24
|
+
* with their distinct picked values and the check that needs attention most; its use of the
|
|
25
|
+
* output as a whole is a row of its own.
|
|
26
|
+
*/
|
|
27
|
+
export type LinkRow = Pick<ColumnLink, "columnLabel" | "values" | "check"> & {
|
|
28
|
+
key: string;
|
|
29
|
+
/** The other block: the one using this block's output, or the one producing the output. */
|
|
30
|
+
blockId: string;
|
|
31
|
+
/** The output. Its name is not meant for reading, so it is shown only as a hint. */
|
|
32
|
+
column: BlockOutput;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** The links of one side. */
|
|
36
|
+
export type LinkSection = { side: LinkSide; rows: LinkRow[] };
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A line about links that need attention: the other block's name, then a space and `text`. The
|
|
40
|
+
* name is kept apart so it can be shown as a way to open that block. A line is about one link,
|
|
41
|
+
* about every link to that block whose output is not exported and has no known label: such
|
|
42
|
+
* outputs have no name a reader can tell apart, or about every link to a block that has not been
|
|
43
|
+
* run yet: they all wait for its run. `outputs` names the outputs the line is about,
|
|
44
|
+
* for a hint.
|
|
45
|
+
*/
|
|
46
|
+
export type LinkIssue = {
|
|
47
|
+
key: string;
|
|
48
|
+
blockId: string;
|
|
49
|
+
text: string;
|
|
50
|
+
outputs: string[];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** The links of one side that need attention, shown as its {@link ALERTS} entry says. */
|
|
54
|
+
export type LinkAlert = { side: LinkSide; issues: LinkIssue[] };
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* How the alert of each side shows. `error` on the `uses` side: this block cannot run against
|
|
58
|
+
* the links. `warn` on the `usedBy` side: the other blocks are the ones to fix, by getting the
|
|
59
|
+
* data back here or by being reconfigured; `hint` says so.
|
|
60
|
+
*/
|
|
61
|
+
export const ALERTS = {
|
|
62
|
+
uses: {
|
|
63
|
+
type: "error",
|
|
64
|
+
label: "Links to blocks this block takes data from are broken",
|
|
65
|
+
hint: null,
|
|
66
|
+
},
|
|
67
|
+
usedBy: {
|
|
68
|
+
type: "warn",
|
|
69
|
+
label: "Some blocks are missing data from this block",
|
|
70
|
+
hint:
|
|
71
|
+
"Checked against the last run of this block. Add the missing data and run it, or " +
|
|
72
|
+
"reconfigure those blocks.",
|
|
73
|
+
},
|
|
74
|
+
} as const satisfies Record<
|
|
75
|
+
LinkSide,
|
|
76
|
+
{ type: "error" | "warn"; label: string; hint: null | string }
|
|
77
|
+
>;
|
|
78
|
+
|
|
79
|
+
/** The links of both sides: `usedBy`, then `uses`. */
|
|
80
|
+
export function linkSections(
|
|
81
|
+
links: Pick<BlockColumnLinks, "dependencies" | "dependents">,
|
|
82
|
+
): LinkSection[] {
|
|
83
|
+
const { dependents, dependencies } = links;
|
|
84
|
+
return [
|
|
85
|
+
{
|
|
86
|
+
side: "usedBy",
|
|
87
|
+
rows: groupRows(dependents.map((link) => toRow(link, link.holderBlockId))),
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
side: "uses",
|
|
91
|
+
rows: groupRows(dependencies.map((link) => toRow(link, link.producer.blockId))),
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* One alert per side whose links need attention, in the order of the sections:
|
|
98
|
+
* - `uses` — an output this block uses is not available or lacks picked values;
|
|
99
|
+
* - `usedBy` — another block uses an output this block does not export, or picked values this
|
|
100
|
+
* block's output lacks. The links are checked against this block's last run, as the hint says.
|
|
101
|
+
*/
|
|
102
|
+
export function linkAlerts(sections: LinkSection[]): LinkAlert[] {
|
|
103
|
+
return sections.flatMap((section): LinkAlert[] => {
|
|
104
|
+
const links = section.rows.flatMap((row) => attentionLink(row) ?? []);
|
|
105
|
+
if (links.length === 0) return [];
|
|
106
|
+
const issues = groupIssues(links).map((group) => toIssue(section.side, group));
|
|
107
|
+
return [{ side: section.side, issues }];
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The label of a block, or a short form of its id when it has no label. */
|
|
112
|
+
export function blockName(labels: Record<string, string>, blockId: string): string {
|
|
113
|
+
return labels[blockId] ?? `Block ${blockId.slice(0, 8)}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Why a selected column or column value is missing. `source`: the block meant to provide it, and
|
|
118
|
+
* what went wrong, as a sentence that follows the block's name. `waiting`: its column is provided,
|
|
119
|
+
* while other inputs of the block are not, and the options of one input may be made from another.
|
|
120
|
+
* `name`: what the selection is called — the picked value, or the label of a column selected as a
|
|
121
|
+
* whole; `null` when the column has no known label.
|
|
122
|
+
*/
|
|
123
|
+
export type MissingValueCause =
|
|
124
|
+
| { type: "source"; name: string | null; blockId: string; text: string }
|
|
125
|
+
| { type: "waiting"; name: string | null; text: string };
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Why `value` is missing from its options, by the dependencies of the block: a column value id,
|
|
129
|
+
* or a column — as an id or a ref. When its column is provided, with the value, while other
|
|
130
|
+
* inputs of the block are not, the block offers it once they are: the options of one input may
|
|
131
|
+
* be made from another. `undefined` for any other value, and for one whose column has nothing
|
|
132
|
+
* wrong with it while every other input is provided too.
|
|
133
|
+
*/
|
|
134
|
+
export function describeMissingValue(
|
|
135
|
+
dependencies: readonly ColumnLink[],
|
|
136
|
+
value: unknown,
|
|
137
|
+
): MissingValueCause | undefined {
|
|
138
|
+
const reference = selectedReference(value);
|
|
139
|
+
if (reference === undefined) return undefined;
|
|
140
|
+
const entry = dependencies.find((link) => link.ref === reference.ref);
|
|
141
|
+
if (entry === undefined) return undefined;
|
|
142
|
+
|
|
143
|
+
const column = entry.columnLabel === null ? "the column" : `“${entry.columnLabel}”`;
|
|
144
|
+
const text = missingValueCauseText(entry.check, column, reference.picked);
|
|
145
|
+
const name = reference.picked ?? entry.columnLabel;
|
|
146
|
+
if (text !== undefined) {
|
|
147
|
+
return { type: "source", name, blockId: entry.producer.blockId, text };
|
|
148
|
+
}
|
|
149
|
+
return waitsForOtherInputs(dependencies, entry, reference.picked)
|
|
150
|
+
? { type: "waiting", name, text: "Waiting for the other inputs of this block." }
|
|
151
|
+
: undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Internals
|
|
155
|
+
|
|
156
|
+
/** The column `value` selects, with the value of it a column value id picks. */
|
|
157
|
+
function selectedReference(
|
|
158
|
+
value: unknown,
|
|
159
|
+
): { ref: ColumnUniversalId; picked: ColumnValue | undefined } | undefined {
|
|
160
|
+
const isColumn = isColumnUniversalId(value) || isColumnUniversalKey(value);
|
|
161
|
+
if (!isColumnValueId(value) && !isColumn) return undefined;
|
|
162
|
+
const [reference] = collectColumnReferences(value);
|
|
163
|
+
if (reference === undefined) return undefined;
|
|
164
|
+
if (reference.values === null)
|
|
165
|
+
return isColumn ? { ref: reference.ref, picked: undefined } : undefined;
|
|
166
|
+
return { ref: reference.ref, picked: reference.values[0] };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function missingValueCauseText(
|
|
170
|
+
check: LinkCheck,
|
|
171
|
+
column: string,
|
|
172
|
+
picked: ColumnValue | undefined,
|
|
173
|
+
): string | undefined {
|
|
174
|
+
switch (check.type) {
|
|
175
|
+
case "ok":
|
|
176
|
+
case "unreadable":
|
|
177
|
+
return undefined;
|
|
178
|
+
case "pending":
|
|
179
|
+
return `is still computing ${column}.`;
|
|
180
|
+
case "notRun":
|
|
181
|
+
case "unavailable":
|
|
182
|
+
return `does not provide ${column}.`;
|
|
183
|
+
case "missingValues":
|
|
184
|
+
return picked !== undefined && check.values.includes(picked)
|
|
185
|
+
? `has no “${picked}” in ${column}.`
|
|
186
|
+
: undefined;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Whether a selected column is provided, with the picked value, while another input is not. */
|
|
191
|
+
function waitsForOtherInputs(
|
|
192
|
+
dependencies: readonly ColumnLink[],
|
|
193
|
+
entry: ColumnLink,
|
|
194
|
+
picked: ColumnValue | undefined,
|
|
195
|
+
): boolean {
|
|
196
|
+
if (!providesPick(entry.check, picked)) return false;
|
|
197
|
+
return dependencies.some(
|
|
198
|
+
(link) =>
|
|
199
|
+
link.ref !== entry.ref && link.check.type !== "ok" && link.check.type !== "unreadable",
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Whether a column is provided with the picked value, as far as it was checked. */
|
|
204
|
+
function providesPick(check: LinkCheck, picked: ColumnValue | undefined): boolean {
|
|
205
|
+
switch (check.type) {
|
|
206
|
+
case "ok":
|
|
207
|
+
return true;
|
|
208
|
+
case "missingValues":
|
|
209
|
+
return picked === undefined || !check.values.includes(picked);
|
|
210
|
+
case "unreadable":
|
|
211
|
+
case "pending":
|
|
212
|
+
case "notRun":
|
|
213
|
+
case "unavailable":
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** A link as a row, seen from the side whose other block is `blockId`. */
|
|
219
|
+
function toRow(link: ColumnLink, blockId: string): LinkRow {
|
|
220
|
+
const { producer: column, columnLabel, values, check } = link;
|
|
221
|
+
return {
|
|
222
|
+
key: JSON.stringify([blockId, column.name, values === null]),
|
|
223
|
+
blockId,
|
|
224
|
+
column,
|
|
225
|
+
columnLabel,
|
|
226
|
+
values: values === null ? null : uniq(values),
|
|
227
|
+
check,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Rows of one key merged into one, in the place of the first. */
|
|
232
|
+
function groupRows(rows: LinkRow[]): LinkRow[] {
|
|
233
|
+
return Object.values(groupBy(rows, (row) => row.key)).map((group) => group.reduce(mergeRows));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Two rows of one key: references to one output of one block, picking values or not. */
|
|
237
|
+
function mergeRows(a: LinkRow, b: LinkRow): LinkRow {
|
|
238
|
+
return {
|
|
239
|
+
...a,
|
|
240
|
+
columnLabel: a.columnLabel ?? b.columnLabel,
|
|
241
|
+
values: a.values !== null && b.values !== null ? uniq([...a.values, ...b.values]) : a.values,
|
|
242
|
+
check: mergeCheck(a.check, b.check),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** The check of merged references: the one that needs attention most. */
|
|
247
|
+
function mergeCheck(a: LinkCheck, b: LinkCheck): LinkCheck {
|
|
248
|
+
if (a.type === "missingValues" && b.type === "missingValues") {
|
|
249
|
+
return { type: "missingValues", values: uniq([...a.values, ...b.values]) };
|
|
250
|
+
}
|
|
251
|
+
return CHECK_RANK[b.type] > CHECK_RANK[a.type] ? b : a;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const CHECK_RANK: Record<LinkCheck["type"], number> = {
|
|
255
|
+
ok: 0,
|
|
256
|
+
unreadable: 1,
|
|
257
|
+
pending: 2,
|
|
258
|
+
missingValues: 3,
|
|
259
|
+
notRun: 4,
|
|
260
|
+
unavailable: 4,
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/** A link whose check needs attention: it breaks a block, or lacks picked values. */
|
|
264
|
+
type AttentionLink = { row: LinkRow; check: AttentionCheck };
|
|
265
|
+
|
|
266
|
+
type AttentionCheck = Extract<LinkCheck, { type: "notRun" | "unavailable" | "missingValues" }>;
|
|
267
|
+
|
|
268
|
+
/** The row as a link needing attention; `undefined` when it does not. */
|
|
269
|
+
function attentionLink(row: LinkRow): undefined | AttentionLink {
|
|
270
|
+
const { check } = row;
|
|
271
|
+
switch (check.type) {
|
|
272
|
+
case "notRun":
|
|
273
|
+
case "unavailable":
|
|
274
|
+
case "missingValues":
|
|
275
|
+
return { row, check };
|
|
276
|
+
case "ok":
|
|
277
|
+
case "pending":
|
|
278
|
+
case "unreadable":
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** One link an alert line is about. */
|
|
284
|
+
type SingleIssue = { type: "single"; link: AttentionLink };
|
|
285
|
+
|
|
286
|
+
/** Every link to one block whose output is not exported and has no known label. */
|
|
287
|
+
type UnlabeledIssue = { type: "unlabeled"; blockId: string; outputs: string[] };
|
|
288
|
+
|
|
289
|
+
type Issue = SingleIssue | UnlabeledIssue;
|
|
290
|
+
|
|
291
|
+
/** Groups links into alert lines, each line in the place of its first link. */
|
|
292
|
+
function groupIssues(links: AttentionLink[]): Issue[] {
|
|
293
|
+
const keyed = links.map((link, index) => ({ link, key: issueKey(link, index) }));
|
|
294
|
+
return Object.values(groupBy(keyed, ({ key }) => key)).map((group): Issue => {
|
|
295
|
+
const [{ link }] = group;
|
|
296
|
+
if (!isUnlabeled(link)) return { type: "single", link };
|
|
297
|
+
const outputs = uniq(group.map((item) => item.link.row.column.name));
|
|
298
|
+
return { type: "unlabeled", blockId: link.row.blockId, outputs };
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function issueKey(link: AttentionLink, index: number): string {
|
|
303
|
+
const blockId = JSON.stringify(link.row.blockId);
|
|
304
|
+
return isUnlabeled(link) ? `unlabeled/${blockId}` : `single/${index}`;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** A link to an output that is not exported and has no known label. */
|
|
308
|
+
function isUnlabeled(link: AttentionLink): boolean {
|
|
309
|
+
const { type } = link.check;
|
|
310
|
+
return link.row.columnLabel === null && (type === "notRun" || type === "unavailable");
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function toIssue(side: LinkSide, group: Issue): LinkIssue {
|
|
314
|
+
if (group.type === "unlabeled") {
|
|
315
|
+
return {
|
|
316
|
+
key: `${side}/${JSON.stringify([group.blockId])}`,
|
|
317
|
+
blockId: group.blockId,
|
|
318
|
+
text: describeUnlabeled(side, group.outputs.length),
|
|
319
|
+
outputs: group.outputs,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
const { row } = group.link;
|
|
323
|
+
return {
|
|
324
|
+
key: `${side}/${row.key}`,
|
|
325
|
+
blockId: row.blockId,
|
|
326
|
+
text: describeIssue(side, group.link),
|
|
327
|
+
outputs: [row.column.name],
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Outputs of one block that are not exported and have no known label, as words that follow the
|
|
333
|
+
* other block's name and a space. One such output is the data in question; several are counted.
|
|
334
|
+
*/
|
|
335
|
+
function describeUnlabeled(side: LinkSide, count: number): string {
|
|
336
|
+
const what = count === 1 ? "data" : `${count} outputs`;
|
|
337
|
+
return side === "uses"
|
|
338
|
+
? `does not provide ${what} this block uses`
|
|
339
|
+
: `uses ${what} this block does not export`;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* What is wrong with one link, as words that follow the other block's name and a space. The
|
|
344
|
+
* column is named by its label, quoted; a column with no known label is named by its role.
|
|
345
|
+
*/
|
|
346
|
+
function describeIssue(side: LinkSide, { row, check }: AttentionLink): string {
|
|
347
|
+
const column = row.columnLabel === null ? null : `"${row.columnLabel}"`;
|
|
348
|
+
switch (check.type) {
|
|
349
|
+
case "notRun":
|
|
350
|
+
case "unavailable":
|
|
351
|
+
if (column === null) return describeUnlabeled(side, 1);
|
|
352
|
+
return side === "uses"
|
|
353
|
+
? `does not provide ${column}`
|
|
354
|
+
: `uses ${column}, which this block does not export`;
|
|
355
|
+
case "missingValues": {
|
|
356
|
+
const values = quoteValues(check.values);
|
|
357
|
+
if (side === "uses") return `has no ${values} in ${column ?? "data this block uses"}`;
|
|
358
|
+
return column === null
|
|
359
|
+
? `uses ${values}, which this block's data no longer has`
|
|
360
|
+
: `uses ${values} of ${column}, which this block no longer has`;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** Picked values for display: quoted, comma-separated. */
|
|
366
|
+
function quoteValues(values: string[]): string {
|
|
367
|
+
return values.map((value) => `"${value}"`).join(", ");
|
|
368
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BlockColumnLinks } from "@platforma-sdk/model";
|
|
2
|
+
import type { ComputedRef, InjectionKey } from "vue";
|
|
3
|
+
|
|
4
|
+
/** Column links of the block, as the app computes them; `undefined` in apps that do not. */
|
|
5
|
+
export const columnLinksKey: InjectionKey<ComputedRef<BlockColumnLinks | undefined>> =
|
|
6
|
+
Symbol("column-links");
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createGlobalPObjectId, type BlockColumnLinks } from "@platforma-sdk/model";
|
|
2
|
+
import { mount } from "@vue/test-utils";
|
|
3
|
+
import { describe, expect, test, vi } from "vitest";
|
|
4
|
+
import { computed, nextTick, shallowRef } from "vue";
|
|
5
|
+
|
|
6
|
+
// uikit reads the theme from localStorage on import, which this jsdom setup lacks.
|
|
7
|
+
vi.hoisted(() => {
|
|
8
|
+
const store = new Map<string, string>();
|
|
9
|
+
vi.stubGlobal("localStorage", {
|
|
10
|
+
getItem: (key: string) => store.get(key) ?? null,
|
|
11
|
+
setItem: (key: string, value: string) => store.set(key, value),
|
|
12
|
+
removeItem: (key: string) => store.delete(key),
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
vi.mock("../../composition/useOpenBlock", () => ({ useOpenBlock: () => undefined }));
|
|
17
|
+
|
|
18
|
+
const { PlBlockDependencies } = await import("./index");
|
|
19
|
+
const { columnLinksKey } = await import("../../columnLinks");
|
|
20
|
+
|
|
21
|
+
const PATH = createGlobalPObjectId("samples", "metadata.path");
|
|
22
|
+
|
|
23
|
+
const links: BlockColumnLinks = {
|
|
24
|
+
blockId: "samples",
|
|
25
|
+
dependencies: [],
|
|
26
|
+
dependents: [
|
|
27
|
+
{
|
|
28
|
+
producer: { blockId: "samples", name: "metadata.path" },
|
|
29
|
+
holderBlockId: "enrichment",
|
|
30
|
+
ref: PATH,
|
|
31
|
+
values: null,
|
|
32
|
+
columnLabel: "Path",
|
|
33
|
+
check: { type: "unavailable" },
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
labels: { enrichment: "Enrichment" },
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe("PlBlockDependencies", () => {
|
|
40
|
+
test("shows nothing outside a block", () => {
|
|
41
|
+
const wrapper = mount(PlBlockDependencies);
|
|
42
|
+
expect(wrapper.find("[data-testid^='pl-block-dependencies-alert']").exists()).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("warns about blocks using an output the block does not export", () => {
|
|
46
|
+
const wrapper = mount(PlBlockDependencies, {
|
|
47
|
+
global: { provide: { [columnLinksKey]: computed(() => links) } },
|
|
48
|
+
});
|
|
49
|
+
const alert = wrapper.find("[data-testid='pl-block-dependencies-alert-usedBy']");
|
|
50
|
+
expect(alert.exists()).toBe(true);
|
|
51
|
+
expect(alert.text()).toContain("Enrichment");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("folds the warning to one line, and keeps it folded when the block opens again", async () => {
|
|
55
|
+
const folded = { ...links, blockId: "folded" };
|
|
56
|
+
const wrapper = mountWith(computed(() => folded));
|
|
57
|
+
await wrapper.find("[data-testid='pl-block-dependencies-toggle']").trigger("click");
|
|
58
|
+
|
|
59
|
+
expect(wrapper.find("[data-testid='pl-block-dependencies-count']").text()).toBe("1 block");
|
|
60
|
+
expect(wrapper.find("[data-testid='pl-alert-message']").exists()).toBe(false);
|
|
61
|
+
expect(wrapper.text()).not.toContain("Enrichment");
|
|
62
|
+
|
|
63
|
+
const reopened = mountWith(computed(() => folded));
|
|
64
|
+
expect(reopened.find("[data-testid='pl-block-dependencies-count']").exists()).toBe(true);
|
|
65
|
+
expect(reopened.find("[data-testid='pl-block-dependencies-updated']").exists()).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("marks a folded warning updated once it says something else, until it is read", async () => {
|
|
69
|
+
const current = shallowRef<BlockColumnLinks>({ ...links, blockId: "updated" });
|
|
70
|
+
const wrapper = mountWith(current);
|
|
71
|
+
await wrapper.find("[data-testid='pl-block-dependencies-toggle']").trigger("click");
|
|
72
|
+
|
|
73
|
+
current.value = withDependent(current.value, "dca", "DCA");
|
|
74
|
+
await nextTick();
|
|
75
|
+
expect(wrapper.find("[data-testid='pl-block-dependencies-updated']").exists()).toBe(true);
|
|
76
|
+
expect(wrapper.find("[data-testid='pl-block-dependencies-count']").text()).toBe("2 blocks");
|
|
77
|
+
|
|
78
|
+
await wrapper.find("[data-testid='pl-block-dependencies-toggle']").trigger("click");
|
|
79
|
+
expect(wrapper.text()).toContain("DCA");
|
|
80
|
+
await wrapper.find("[data-testid='pl-block-dependencies-toggle']").trigger("click");
|
|
81
|
+
expect(wrapper.find("[data-testid='pl-block-dependencies-updated']").exists()).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Internals
|
|
86
|
+
|
|
87
|
+
function mountWith(columnLinks: { readonly value: BlockColumnLinks }) {
|
|
88
|
+
return mount(PlBlockDependencies, {
|
|
89
|
+
global: { provide: { [columnLinksKey]: computed(() => columnLinks.value) } },
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function withDependent(of: BlockColumnLinks, blockId: string, label: string): BlockColumnLinks {
|
|
94
|
+
const [link] = of.dependents;
|
|
95
|
+
if (link === undefined) throw new Error("The links have no dependent to copy");
|
|
96
|
+
return {
|
|
97
|
+
...of,
|
|
98
|
+
dependents: [...of.dependents, { ...link, holderBlockId: blockId }],
|
|
99
|
+
labels: { ...of.labels, [blockId]: label },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { PlAlert, PlMaskIcon16 } from "@milaboratories/uikit";
|
|
3
|
+
import { uniq } from "es-toolkit";
|
|
4
|
+
import { computed, inject } from "vue";
|
|
5
|
+
import { columnLinksKey } from "../../columnLinks";
|
|
6
|
+
import { ALERTS, blockName, linkAlerts, linkSections } from "../../columnLinkViews";
|
|
7
|
+
import { PlBlockName } from "../PlBlockName";
|
|
8
|
+
import { useAlertFold } from "./fold";
|
|
9
|
+
|
|
10
|
+
const links = inject(columnLinksKey, undefined);
|
|
11
|
+
|
|
12
|
+
const alerts = computed(() => {
|
|
13
|
+
const value = links?.value;
|
|
14
|
+
return value === undefined ? [] : linkAlerts(linkSections(value));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Only the warning about other blocks folds: broken inputs of this block stop it from running.
|
|
18
|
+
const usedByIssues = computed(
|
|
19
|
+
() => alerts.value.find((alert) => alert.side === "usedBy")?.issues ?? [],
|
|
20
|
+
);
|
|
21
|
+
const usedByFold = useAlertFold({
|
|
22
|
+
blockId: () => links?.value?.blockId,
|
|
23
|
+
saying: () => JSON.stringify(usedByIssues.value.map((issue) => [issue.key, issue.text])),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const nameOf = (blockId: string) => blockName(links?.value?.labels ?? {}, blockId);
|
|
27
|
+
|
|
28
|
+
const isFolded = computed(() => usedByFold.state.value.type === "folded");
|
|
29
|
+
|
|
30
|
+
const isUpdated = computed(() => {
|
|
31
|
+
const state = usedByFold.state.value;
|
|
32
|
+
return state.type === "folded" && state.updated;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const blockCount = computed(() => {
|
|
36
|
+
const count = uniq(usedByIssues.value.map((issue) => issue.blockId)).length;
|
|
37
|
+
return `${count} ${count === 1 ? "block" : "blocks"}`;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const toggleUsedBy = () => (isFolded.value ? usedByFold.open() : usedByFold.fold());
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<template>
|
|
44
|
+
<PlAlert
|
|
45
|
+
v-for="alert in alerts"
|
|
46
|
+
:key="alert.side"
|
|
47
|
+
:data-testid="`pl-block-dependencies-alert-${alert.side}`"
|
|
48
|
+
:type="ALERTS[alert.side].type"
|
|
49
|
+
:label="ALERTS[alert.side].label"
|
|
50
|
+
>
|
|
51
|
+
<template v-if="alert.side === 'usedBy'" #label>
|
|
52
|
+
<button
|
|
53
|
+
type="button"
|
|
54
|
+
data-testid="pl-block-dependencies-toggle"
|
|
55
|
+
:class="$style.title"
|
|
56
|
+
:aria-expanded="!isFolded"
|
|
57
|
+
@click="toggleUsedBy"
|
|
58
|
+
>
|
|
59
|
+
<PlMaskIcon16
|
|
60
|
+
name="chevron-right"
|
|
61
|
+
:class="[$style.chevron, { [$style.open]: !isFolded }]"
|
|
62
|
+
/>
|
|
63
|
+
{{ ALERTS[alert.side].label }}
|
|
64
|
+
<span v-if="isFolded" data-testid="pl-block-dependencies-count" :class="$style.meta">
|
|
65
|
+
{{ blockCount }}
|
|
66
|
+
</span>
|
|
67
|
+
<span v-if="isUpdated" data-testid="pl-block-dependencies-updated" :class="$style.meta">
|
|
68
|
+
<span :class="$style.dot" />Updated
|
|
69
|
+
</span>
|
|
70
|
+
</button>
|
|
71
|
+
</template>
|
|
72
|
+
<template v-if="alert.side !== 'usedBy' || !isFolded" #default>
|
|
73
|
+
<ul :class="$style.issues">
|
|
74
|
+
<li v-for="issue in alert.issues" :key="issue.key" :title="issue.outputs.join(', ')">
|
|
75
|
+
<PlBlockName :block-id="issue.blockId" :name="nameOf(issue.blockId)" />
|
|
76
|
+
{{ issue.text }}
|
|
77
|
+
</li>
|
|
78
|
+
</ul>
|
|
79
|
+
<div v-if="ALERTS[alert.side].hint !== null" :class="$style.hint">
|
|
80
|
+
{{ ALERTS[alert.side].hint }}
|
|
81
|
+
</div>
|
|
82
|
+
</template>
|
|
83
|
+
</PlAlert>
|
|
84
|
+
</template>
|
|
85
|
+
|
|
86
|
+
<style module>
|
|
87
|
+
.issues {
|
|
88
|
+
margin: 0;
|
|
89
|
+
padding-left: 20px;
|
|
90
|
+
}
|
|
91
|
+
.hint {
|
|
92
|
+
margin-top: 8px;
|
|
93
|
+
}
|
|
94
|
+
.title {
|
|
95
|
+
display: inline-flex;
|
|
96
|
+
flex-wrap: wrap;
|
|
97
|
+
align-items: center;
|
|
98
|
+
gap: 8px;
|
|
99
|
+
padding: 0;
|
|
100
|
+
border: none;
|
|
101
|
+
background: none;
|
|
102
|
+
color: inherit;
|
|
103
|
+
font: inherit;
|
|
104
|
+
letter-spacing: inherit;
|
|
105
|
+
text-align: inherit;
|
|
106
|
+
cursor: pointer;
|
|
107
|
+
}
|
|
108
|
+
.title:focus-visible {
|
|
109
|
+
outline: 2px solid var(--border-color-focus);
|
|
110
|
+
outline-offset: 2px;
|
|
111
|
+
}
|
|
112
|
+
.chevron {
|
|
113
|
+
transition-duration: 50ms;
|
|
114
|
+
}
|
|
115
|
+
.open {
|
|
116
|
+
transform: rotate(90deg);
|
|
117
|
+
}
|
|
118
|
+
.meta {
|
|
119
|
+
display: inline-flex;
|
|
120
|
+
align-items: center;
|
|
121
|
+
gap: 6px;
|
|
122
|
+
font-size: 14px;
|
|
123
|
+
line-height: 20px;
|
|
124
|
+
color: var(--txt-03);
|
|
125
|
+
}
|
|
126
|
+
.dot {
|
|
127
|
+
width: 6px;
|
|
128
|
+
height: 6px;
|
|
129
|
+
border-radius: 50%;
|
|
130
|
+
background: var(--txt-link);
|
|
131
|
+
}
|
|
132
|
+
</style>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isPlainObject } from "es-toolkit";
|
|
2
|
+
import type { ComputedRef, MaybeRefOrGetter } from "vue";
|
|
3
|
+
import { computed, shallowRef, toValue, watch } from "vue";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Whether the alert is shown in full, or folded to one line. A folded alert tells whether it
|
|
7
|
+
* says something else now than when it was folded.
|
|
8
|
+
*/
|
|
9
|
+
export type AlertFoldState = { type: "open" } | { type: "folded"; updated: boolean };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The fold of the alert of block `blockId`, which says `saying` now. The fold is the reader's own:
|
|
13
|
+
* it is kept in the browser storage, not with the block, so it does not change the block. An
|
|
14
|
+
* alert is open until the reader folds it.
|
|
15
|
+
*/
|
|
16
|
+
export function useAlertFold(options: {
|
|
17
|
+
blockId: MaybeRefOrGetter<string | undefined>;
|
|
18
|
+
saying: MaybeRefOrGetter<string>;
|
|
19
|
+
}): { state: ComputedRef<AlertFoldState>; fold: () => void; open: () => void } {
|
|
20
|
+
const stored = shallowRef<StoredFold>(OPEN);
|
|
21
|
+
watch(
|
|
22
|
+
() => toValue(options.blockId),
|
|
23
|
+
(blockId) => {
|
|
24
|
+
stored.value = blockId === undefined ? OPEN : readFold(blockId);
|
|
25
|
+
},
|
|
26
|
+
{ immediate: true },
|
|
27
|
+
);
|
|
28
|
+
const saying = computed(() => toValue(options.saying));
|
|
29
|
+
|
|
30
|
+
const state = computed((): AlertFoldState => {
|
|
31
|
+
const fold = stored.value;
|
|
32
|
+
return fold.type === "open" ? fold : { type: "folded", updated: fold.seen !== saying.value };
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const store = (fold: StoredFold) => {
|
|
36
|
+
stored.value = fold;
|
|
37
|
+
const blockId = toValue(options.blockId);
|
|
38
|
+
if (blockId !== undefined) writeFold(blockId, fold);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
state,
|
|
43
|
+
fold: () => store({ type: "folded", seen: saying.value }),
|
|
44
|
+
open: () => store(OPEN),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Internals
|
|
49
|
+
|
|
50
|
+
/** `seen`: what the alert said when it was folded. */
|
|
51
|
+
type StoredFold = { type: "open" } | { type: "folded"; seen: string };
|
|
52
|
+
|
|
53
|
+
const OPEN: StoredFold = { type: "open" };
|
|
54
|
+
|
|
55
|
+
function storageKey(blockId: string): string {
|
|
56
|
+
return `pl-block-dependencies/${blockId}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Storage may be unavailable, or hold anything: the alert is open then. */
|
|
60
|
+
function readFold(blockId: string): StoredFold {
|
|
61
|
+
try {
|
|
62
|
+
return parseFold(localStorage.getItem(storageKey(blockId)));
|
|
63
|
+
} catch {
|
|
64
|
+
return OPEN;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function parseFold(raw: string | null): StoredFold {
|
|
69
|
+
if (raw === null) return OPEN;
|
|
70
|
+
const value: unknown = JSON.parse(raw);
|
|
71
|
+
if (isPlainObject(value) && value.type === "folded" && typeof value.seen === "string") {
|
|
72
|
+
return { type: "folded", seen: value.seen };
|
|
73
|
+
}
|
|
74
|
+
return OPEN;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A fold that cannot be stored lasts while the block is open. */
|
|
78
|
+
function writeFold(blockId: string, fold: StoredFold): void {
|
|
79
|
+
try {
|
|
80
|
+
if (fold.type === "open") localStorage.removeItem(storageKey(blockId));
|
|
81
|
+
else localStorage.setItem(storageKey(blockId), JSON.stringify(fold));
|
|
82
|
+
} catch {
|
|
83
|
+
// The fold stays in memory.
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as PlBlockDependencies } from "./PlBlockDependencies.vue";
|