@abraca/nuxt 2.33.0 → 2.35.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.
- package/dist/module.json +1 -1
- package/dist/runtime/components/ANodeSettingsPanel.d.vue.ts +11 -4
- package/dist/runtime/components/ANodeSettingsPanel.vue +63 -9
- package/dist/runtime/components/ANodeSettingsPanel.vue.d.ts +11 -4
- package/dist/runtime/components/chat/ANodeChatPanel.vue +4 -0
- package/dist/runtime/components/docs/ADocsSearch.d.vue.ts +1 -1
- package/dist/runtime/components/docs/ADocsSearch.vue.d.ts +1 -1
- package/dist/runtime/components/renderers/ASheetsRenderer.client.vue +160 -1
- package/dist/runtime/components/renderers/sheets/ASheetsCell.d.vue.ts +3 -0
- package/dist/runtime/components/renderers/sheets/ASheetsCell.vue +30 -34
- package/dist/runtime/components/renderers/sheets/ASheetsCell.vue.d.ts +3 -0
- package/dist/runtime/components/renderers/sheets/ASheetsConditionalModal.d.vue.ts +15 -0
- package/dist/runtime/components/renderers/sheets/ASheetsConditionalModal.vue +226 -0
- package/dist/runtime/components/renderers/sheets/ASheetsConditionalModal.vue.d.ts +15 -0
- package/dist/runtime/components/renderers/sheets/ASheetsFindPanel.d.vue.ts +31 -0
- package/dist/runtime/components/renderers/sheets/ASheetsFindPanel.vue +130 -0
- package/dist/runtime/components/renderers/sheets/ASheetsFindPanel.vue.d.ts +31 -0
- package/dist/runtime/components/renderers/sheets/ASheetsGrid.vue +25 -6
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.d.vue.ts +6 -0
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.vue +39 -3
- package/dist/runtime/components/renderers/sheets/ASheetsToolbar.vue.d.ts +6 -0
- package/dist/runtime/components/renderers/sheets/ASheetsValidationModal.d.vue.ts +15 -0
- package/dist/runtime/components/renderers/sheets/ASheetsValidationModal.vue +185 -0
- package/dist/runtime/components/renderers/sheets/ASheetsValidationModal.vue.d.ts +15 -0
- package/dist/runtime/components/settings/ASettingsAdminPanel.vue +168 -1
- package/dist/runtime/components/settings/ASettingsInvitesPanel.vue +73 -11
- package/dist/runtime/components/shell/ADocPanelSettings.d.vue.ts +25 -3
- package/dist/runtime/components/shell/ADocPanelSettings.vue +28 -10
- package/dist/runtime/components/shell/ADocPanelSettings.vue.d.ts +25 -3
- package/dist/runtime/components/shell/AUserMenu.d.vue.ts +2 -2
- package/dist/runtime/components/shell/AUserMenu.vue.d.ts +2 -2
- package/dist/runtime/composables/useChatUsers.d.ts +50 -4
- package/dist/runtime/composables/useChatUsers.js +57 -17
- package/dist/runtime/composables/useDocPermissions.d.ts +137 -0
- package/dist/runtime/composables/useDocPermissions.js +258 -0
- package/dist/runtime/composables/useIdentityDoc.d.ts +1 -1
- package/dist/runtime/composables/useOrphans.d.ts +58 -0
- package/dist/runtime/composables/useOrphans.js +87 -0
- package/dist/runtime/composables/useSheetsFind.d.ts +35 -0
- package/dist/runtime/composables/useSheetsFind.js +44 -0
- package/dist/runtime/composables/useSheetsFormat.d.ts +40 -0
- package/dist/runtime/composables/useSheetsFormat.js +132 -0
- package/dist/runtime/composables/useSheetsValidation.d.ts +22 -0
- package/dist/runtime/composables/useSheetsValidation.js +38 -0
- package/dist/runtime/types.d.ts +52 -10
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useOrphans
|
|
3
|
+
*
|
|
4
|
+
* Orphaned-node recovery over the 'doc-orphans' Y.Map — the sibling of
|
|
5
|
+
* [[useTrash]]. A node becomes an "orphan" when its parent is gone but the node
|
|
6
|
+
* itself was never explicitly trashed (e.g. a partial sync, a reparent race, or
|
|
7
|
+
* a detection sweep). This surfaces them and recovers them back into the tree.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors `useTrash`: same `useSyncedMap` channels, same batch-by-batchId (with
|
|
10
|
+
* a legacy orphanedAt±1s fallback) restore semantics, same IndexedDB cleanup on
|
|
11
|
+
* permanent delete. Document-native — nothing lives outside the doc tree.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* const { orphanedItems, orphanedCount, recoverFromOrphans, recoverAllOrphans } = useOrphans()
|
|
15
|
+
*/
|
|
16
|
+
import type { ShallowRef } from 'vue';
|
|
17
|
+
import type * as Y from 'yjs';
|
|
18
|
+
export interface OrphanEntry {
|
|
19
|
+
label: string;
|
|
20
|
+
parentId: string | null;
|
|
21
|
+
order: number;
|
|
22
|
+
type?: string;
|
|
23
|
+
meta?: Record<string, any>;
|
|
24
|
+
orphanedAt: number;
|
|
25
|
+
/** Parent this node hung off before it was orphaned (recovery target). */
|
|
26
|
+
originalParentId?: string | null;
|
|
27
|
+
/** Batch id shared by every node orphaned in the same detection pass. */
|
|
28
|
+
orphanBatchId?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function useOrphans(rootDoc?: ShallowRef<Y.Doc | null>): {
|
|
31
|
+
orphanMap: {
|
|
32
|
+
data: Record<string, OrphanEntry>;
|
|
33
|
+
lastUpdateLocal: ShallowRef<boolean, boolean>;
|
|
34
|
+
set: (key: string, value: OrphanEntry) => OrphanEntry | undefined;
|
|
35
|
+
remove: (key: string) => void | undefined;
|
|
36
|
+
clear: () => void | undefined;
|
|
37
|
+
get: (key: string) => OrphanEntry | undefined;
|
|
38
|
+
yMap: import("vue").ComputedRef<Y.Map<OrphanEntry> | null>;
|
|
39
|
+
};
|
|
40
|
+
orphanedItems: import("vue").ComputedRef<{
|
|
41
|
+
label: string;
|
|
42
|
+
parentId: string | null;
|
|
43
|
+
order: number;
|
|
44
|
+
type?: string;
|
|
45
|
+
meta?: Record<string, any>;
|
|
46
|
+
orphanedAt: number;
|
|
47
|
+
/** Parent this node hung off before it was orphaned (recovery target). */
|
|
48
|
+
originalParentId?: string | null;
|
|
49
|
+
/** Batch id shared by every node orphaned in the same detection pass. */
|
|
50
|
+
orphanBatchId?: string;
|
|
51
|
+
id: string;
|
|
52
|
+
}[]>;
|
|
53
|
+
orphanedCount: import("vue").ComputedRef<number>;
|
|
54
|
+
recoverFromOrphans: (docId: string) => void;
|
|
55
|
+
recoverAllOrphans: () => void;
|
|
56
|
+
permanentlyDeleteOrphan: (docId: string) => void;
|
|
57
|
+
emptyOrphans: () => void;
|
|
58
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { useSyncedMap } from "./useYDoc.js";
|
|
3
|
+
import { useAbracadabra } from "./useAbracadabra.js";
|
|
4
|
+
export function useOrphans(rootDoc) {
|
|
5
|
+
const { doc: globalDoc } = useAbracadabra();
|
|
6
|
+
const _doc = rootDoc ?? globalDoc;
|
|
7
|
+
const orphanMap = useSyncedMap(_doc, "doc-orphans");
|
|
8
|
+
const treeMap = useSyncedMap(_doc, "doc-tree");
|
|
9
|
+
const orphanedItems = computed(
|
|
10
|
+
() => Object.entries(orphanMap.data).map(([id, entry]) => ({ id, ...entry })).sort((a, b) => b.orphanedAt - a.orphanedAt)
|
|
11
|
+
);
|
|
12
|
+
const orphanedCount = computed(() => Object.keys(orphanMap.data).length);
|
|
13
|
+
function recoverFromOrphans(docId) {
|
|
14
|
+
const doc = _doc.value;
|
|
15
|
+
if (!doc) return;
|
|
16
|
+
const entry = orphanMap.get(docId);
|
|
17
|
+
if (!entry) return;
|
|
18
|
+
const { orphanedAt, orphanBatchId } = entry;
|
|
19
|
+
doc.transact(() => {
|
|
20
|
+
const toRestore = Object.entries(orphanMap.data).filter(([, e]) => orphanBatchId ? e.orphanBatchId === orphanBatchId : Math.abs(e.orphanedAt - orphanedAt) < 1e3);
|
|
21
|
+
for (const [id, orphanEntry] of toRestore) {
|
|
22
|
+
const target = orphanEntry.originalParentId ?? null;
|
|
23
|
+
const parentExists = target === null || treeMap.get(target) !== void 0 || toRestore.some(([rid]) => rid === target);
|
|
24
|
+
treeMap.set(id, {
|
|
25
|
+
label: orphanEntry.label,
|
|
26
|
+
parentId: parentExists ? target : null,
|
|
27
|
+
order: orphanEntry.order,
|
|
28
|
+
type: orphanEntry.type,
|
|
29
|
+
meta: orphanEntry.meta
|
|
30
|
+
});
|
|
31
|
+
orphanMap.remove(id);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function recoverAllOrphans() {
|
|
36
|
+
const doc = _doc.value;
|
|
37
|
+
if (!doc) return;
|
|
38
|
+
const ids = Object.keys(orphanMap.data);
|
|
39
|
+
if (!ids.length) return;
|
|
40
|
+
doc.transact(() => {
|
|
41
|
+
for (const id of ids) {
|
|
42
|
+
const entry = orphanMap.get(id);
|
|
43
|
+
if (!entry) continue;
|
|
44
|
+
treeMap.set(id, {
|
|
45
|
+
label: entry.label,
|
|
46
|
+
parentId: null,
|
|
47
|
+
order: entry.order,
|
|
48
|
+
type: entry.type,
|
|
49
|
+
meta: entry.meta
|
|
50
|
+
});
|
|
51
|
+
orphanMap.remove(id);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function permanentlyDeleteOrphan(docId) {
|
|
56
|
+
orphanMap.remove(docId);
|
|
57
|
+
cleanupIDB(docId);
|
|
58
|
+
}
|
|
59
|
+
function emptyOrphans() {
|
|
60
|
+
const doc = _doc.value;
|
|
61
|
+
if (!doc) return;
|
|
62
|
+
const ids = Object.keys(orphanMap.data);
|
|
63
|
+
doc.transact(() => {
|
|
64
|
+
for (const id of ids) orphanMap.remove(id);
|
|
65
|
+
});
|
|
66
|
+
for (const id of ids) cleanupIDB(id);
|
|
67
|
+
}
|
|
68
|
+
async function cleanupIDB(docId) {
|
|
69
|
+
try {
|
|
70
|
+
const dbs = await indexedDB.databases();
|
|
71
|
+
for (const db of dbs) {
|
|
72
|
+
if (db.name?.includes(docId)) indexedDB.deleteDatabase(db.name);
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (import.meta.dev) console.debug("[abracadabra] orphans: failed to cleanup IDB for doc:", e);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
orphanMap,
|
|
80
|
+
orphanedItems,
|
|
81
|
+
orphanedCount,
|
|
82
|
+
recoverFromOrphans,
|
|
83
|
+
recoverAllOrphans,
|
|
84
|
+
permanentlyDeleteOrphan,
|
|
85
|
+
emptyOrphans
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find & replace logic for the Sheets renderer — pure functions over a cell
|
|
3
|
+
* accessor so they can be unit-tested without a grid. The renderer owns the
|
|
4
|
+
* actual tree writes; this module only locates matches and computes replacement
|
|
5
|
+
* strings. Nothing here persists or touches the CRDT directly.
|
|
6
|
+
*
|
|
7
|
+
* All exports auto-import by name (`findMatches`, `replaceInCell`, …).
|
|
8
|
+
*/
|
|
9
|
+
export interface FindMatch {
|
|
10
|
+
colIdx: number;
|
|
11
|
+
rowIdx: number;
|
|
12
|
+
}
|
|
13
|
+
export interface FindOptions {
|
|
14
|
+
matchCase?: boolean;
|
|
15
|
+
wholeCell?: boolean;
|
|
16
|
+
includeFormulas?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** The searchable text of a cell: its formula source when asked, else its label. */
|
|
19
|
+
export interface CellText {
|
|
20
|
+
label: string;
|
|
21
|
+
formula?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Does a single cell's text match the query under the given options? */
|
|
24
|
+
export declare function cellMatches(cell: CellText, query: string, opts?: FindOptions): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Find every matching cell, scanned row-major (stable, predictable Next/Prev
|
|
27
|
+
* order). `getCell` returns the cell text for a coordinate.
|
|
28
|
+
*/
|
|
29
|
+
export declare function findMatches(query: string, getCell: (colIdx: number, rowIdx: number) => CellText, colCount: number, rowCount: number, opts?: FindOptions): FindMatch[];
|
|
30
|
+
/**
|
|
31
|
+
* Compute the replacement text for one cell, or null when nothing changes.
|
|
32
|
+
* Operates on the cell's searchable text (label, or formula source when
|
|
33
|
+
* includeFormulas is set — caller decides how to write the result back).
|
|
34
|
+
*/
|
|
35
|
+
export declare function replaceInCell(cell: CellText, query: string, replacement: string, opts?: FindOptions): string | null;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
function searchable(cell, opts) {
|
|
2
|
+
if (opts.includeFormulas && cell.formula) return `=${cell.formula}`;
|
|
3
|
+
return cell.label;
|
|
4
|
+
}
|
|
5
|
+
export function cellMatches(cell, query, opts = {}) {
|
|
6
|
+
if (query === "") return false;
|
|
7
|
+
let text = searchable(cell, opts);
|
|
8
|
+
let q = query;
|
|
9
|
+
if (!opts.matchCase) {
|
|
10
|
+
text = text.toLowerCase();
|
|
11
|
+
q = q.toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
return opts.wholeCell ? text === q : text.includes(q);
|
|
14
|
+
}
|
|
15
|
+
export function findMatches(query, getCell, colCount, rowCount, opts = {}) {
|
|
16
|
+
const matches = [];
|
|
17
|
+
if (query === "") return matches;
|
|
18
|
+
for (let r = 0; r < rowCount; r++) {
|
|
19
|
+
for (let c = 0; c < colCount; c++) {
|
|
20
|
+
if (cellMatches(getCell(c, r), query, opts)) matches.push({ colIdx: c, rowIdx: r });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return matches;
|
|
24
|
+
}
|
|
25
|
+
export function replaceInCell(cell, query, replacement, opts = {}) {
|
|
26
|
+
if (!cellMatches(cell, query, opts)) return null;
|
|
27
|
+
const text = searchable(cell, opts);
|
|
28
|
+
if (opts.wholeCell) return replacement;
|
|
29
|
+
if (opts.matchCase) return text.split(query).join(replacement);
|
|
30
|
+
const lowerText = text.toLowerCase();
|
|
31
|
+
const lowerQ = query.toLowerCase();
|
|
32
|
+
let out = "";
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < text.length) {
|
|
35
|
+
if (lowerText.startsWith(lowerQ, i)) {
|
|
36
|
+
out += replacement;
|
|
37
|
+
i += query.length;
|
|
38
|
+
} else {
|
|
39
|
+
out += text[i];
|
|
40
|
+
i++;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Number/value display formatting + conditional formatting for the Sheets
|
|
3
|
+
* renderer.
|
|
4
|
+
*
|
|
5
|
+
* Single source of truth: cells render through `formatCellDisplay`, and any
|
|
6
|
+
* other surface that needs a *displayed* value (status bar, copy-as-shown) uses
|
|
7
|
+
* the same helper so they never drift.
|
|
8
|
+
*
|
|
9
|
+
* Everything stays document-native: format options are plain keys on a cell's
|
|
10
|
+
* `meta` (a cell is a document). A COLUMN document's meta supplies the column
|
|
11
|
+
* default — helpers take an optional `columnMeta` and resolve each key as
|
|
12
|
+
* `cellMeta[key] ?? columnMeta[key]`. No format state lives outside the tree.
|
|
13
|
+
*
|
|
14
|
+
* All exports auto-import by name (`formatCellDisplay`, `conditionalStyle`, …).
|
|
15
|
+
*/
|
|
16
|
+
import type { DocPageMeta, SheetsConditionalRule } from '../types.js';
|
|
17
|
+
export type SheetsNumberFormat = NonNullable<DocPageMeta['numberFormat']>;
|
|
18
|
+
/**
|
|
19
|
+
* Format a raw cell value for display given the cell's meta and (optionally) its
|
|
20
|
+
* column's meta as a default source. Non-numeric values for numeric formats fall
|
|
21
|
+
* through to the raw string (matches Sheets/Excel behaviour).
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatCellDisplay(value: string, cellMeta?: DocPageMeta, columnMeta?: DocPageMeta): string;
|
|
24
|
+
/** Whether a negative value in this cell should render red (per resolved meta). */
|
|
25
|
+
export declare function isNegativeRed(value: string, cellMeta?: DocPageMeta, columnMeta?: DocPageMeta): boolean;
|
|
26
|
+
/** Resolve the effective number format for a cell (cell meta, then column). */
|
|
27
|
+
export declare function effectiveNumberFormat(cellMeta?: DocPageMeta, columnMeta?: DocPageMeta): SheetsNumberFormat | undefined;
|
|
28
|
+
export interface ConditionalStyle {
|
|
29
|
+
bg?: string;
|
|
30
|
+
fg?: string;
|
|
31
|
+
bold?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Does a single rule match the raw cell value? */
|
|
34
|
+
export declare function matchConditionalRule(raw: string, rule: SheetsConditionalRule): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve the conditional-formatting style for a cell. Cell rules take priority
|
|
37
|
+
* over column rules. First matching rule wins. Returns undefined when nothing
|
|
38
|
+
* matches (so the caller leaves the cell's own styling untouched).
|
|
39
|
+
*/
|
|
40
|
+
export declare function conditionalStyle(raw: string, cellMeta?: DocPageMeta, columnMeta?: DocPageMeta): ConditionalStyle | undefined;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const _numberFmtCache = /* @__PURE__ */ new Map();
|
|
2
|
+
function getNumberFmt(opts) {
|
|
3
|
+
const key = JSON.stringify(opts);
|
|
4
|
+
let fmt = _numberFmtCache.get(key);
|
|
5
|
+
if (!fmt) {
|
|
6
|
+
fmt = new Intl.NumberFormat(void 0, opts);
|
|
7
|
+
_numberFmtCache.set(key, fmt);
|
|
8
|
+
}
|
|
9
|
+
return fmt;
|
|
10
|
+
}
|
|
11
|
+
function resolve(key, cellMeta, columnMeta) {
|
|
12
|
+
const cv = cellMeta?.[key];
|
|
13
|
+
if (cv !== void 0 && cv !== null) return cv;
|
|
14
|
+
return columnMeta?.[key];
|
|
15
|
+
}
|
|
16
|
+
function formatDatePreset(num, preset) {
|
|
17
|
+
const d = new Date(num);
|
|
18
|
+
if (Number.isNaN(d.getTime())) return String(num);
|
|
19
|
+
switch (preset) {
|
|
20
|
+
case "iso":
|
|
21
|
+
return d.toISOString().slice(0, 10);
|
|
22
|
+
case "long":
|
|
23
|
+
return d.toLocaleDateString(void 0, { year: "numeric", month: "long", day: "numeric" });
|
|
24
|
+
case "short":
|
|
25
|
+
default:
|
|
26
|
+
return d.toLocaleDateString();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function formatCellDisplay(value, cellMeta, columnMeta) {
|
|
30
|
+
const format = resolve("numberFormat", cellMeta, columnMeta);
|
|
31
|
+
if (!format || format === "general") return value;
|
|
32
|
+
const num = Number(value);
|
|
33
|
+
if (value === "" || Number.isNaN(num)) return value;
|
|
34
|
+
const decimals = resolve("numberDecimals", cellMeta, columnMeta);
|
|
35
|
+
const thousands = resolve("numberThousands", cellMeta, columnMeta) ?? false;
|
|
36
|
+
switch (format) {
|
|
37
|
+
case "number":
|
|
38
|
+
return getNumberFmt({
|
|
39
|
+
minimumFractionDigits: decimals ?? 2,
|
|
40
|
+
maximumFractionDigits: decimals ?? 2,
|
|
41
|
+
useGrouping: thousands
|
|
42
|
+
}).format(num);
|
|
43
|
+
case "currency":
|
|
44
|
+
return getNumberFmt({
|
|
45
|
+
style: "currency",
|
|
46
|
+
currency: resolve("numberCurrency", cellMeta, columnMeta) ?? "USD",
|
|
47
|
+
minimumFractionDigits: decimals,
|
|
48
|
+
maximumFractionDigits: decimals,
|
|
49
|
+
useGrouping: true
|
|
50
|
+
}).format(num);
|
|
51
|
+
case "accounting":
|
|
52
|
+
return getNumberFmt({
|
|
53
|
+
style: "currency",
|
|
54
|
+
currency: resolve("numberCurrency", cellMeta, columnMeta) ?? "USD",
|
|
55
|
+
currencySign: "accounting",
|
|
56
|
+
minimumFractionDigits: decimals ?? 2,
|
|
57
|
+
maximumFractionDigits: decimals ?? 2,
|
|
58
|
+
useGrouping: true
|
|
59
|
+
}).format(num);
|
|
60
|
+
case "percent":
|
|
61
|
+
return getNumberFmt({
|
|
62
|
+
style: "percent",
|
|
63
|
+
minimumFractionDigits: decimals ?? 0,
|
|
64
|
+
maximumFractionDigits: decimals ?? 0,
|
|
65
|
+
useGrouping: thousands
|
|
66
|
+
}).format(num);
|
|
67
|
+
case "scientific":
|
|
68
|
+
return num.toExponential(decimals ?? 2);
|
|
69
|
+
case "date":
|
|
70
|
+
return formatDatePreset(num, resolve("dateFormat", cellMeta, columnMeta));
|
|
71
|
+
case "time":
|
|
72
|
+
return new Date(num).toLocaleTimeString();
|
|
73
|
+
case "datetime":
|
|
74
|
+
return new Date(num).toLocaleString();
|
|
75
|
+
default:
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function isNegativeRed(value, cellMeta, columnMeta) {
|
|
80
|
+
const negRed = resolve("numberNegativeRed", cellMeta, columnMeta) ?? false;
|
|
81
|
+
if (!negRed) return false;
|
|
82
|
+
const num = Number(value);
|
|
83
|
+
return value !== "" && !Number.isNaN(num) && num < 0;
|
|
84
|
+
}
|
|
85
|
+
export function effectiveNumberFormat(cellMeta, columnMeta) {
|
|
86
|
+
return resolve("numberFormat", cellMeta, columnMeta);
|
|
87
|
+
}
|
|
88
|
+
export function matchConditionalRule(raw, rule) {
|
|
89
|
+
const num = Number(raw);
|
|
90
|
+
const rv = Number(rule.value);
|
|
91
|
+
const numeric = raw !== "" && !Number.isNaN(num);
|
|
92
|
+
switch (rule.op) {
|
|
93
|
+
case "isEmpty":
|
|
94
|
+
return raw === "";
|
|
95
|
+
case "notEmpty":
|
|
96
|
+
return raw !== "";
|
|
97
|
+
case "contains":
|
|
98
|
+
return raw.toLowerCase().includes(String(rule.value ?? "").toLowerCase());
|
|
99
|
+
case "notContains":
|
|
100
|
+
return !raw.toLowerCase().includes(String(rule.value ?? "").toLowerCase());
|
|
101
|
+
case "eq":
|
|
102
|
+
return numeric && !Number.isNaN(rv) ? num === rv : raw === String(rule.value ?? "");
|
|
103
|
+
case "ne":
|
|
104
|
+
return numeric && !Number.isNaN(rv) ? num !== rv : raw !== String(rule.value ?? "");
|
|
105
|
+
case "gt":
|
|
106
|
+
return numeric && num > rv;
|
|
107
|
+
case "lt":
|
|
108
|
+
return numeric && num < rv;
|
|
109
|
+
case "ge":
|
|
110
|
+
return numeric && num >= rv;
|
|
111
|
+
case "le":
|
|
112
|
+
return numeric && num <= rv;
|
|
113
|
+
case "between":
|
|
114
|
+
return numeric && num >= rv && num <= Number(rule.value2);
|
|
115
|
+
default:
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function conditionalStyle(raw, cellMeta, columnMeta) {
|
|
120
|
+
const rules = cellMeta?.cfRules ?? columnMeta?.cfRules;
|
|
121
|
+
if (!rules || !rules.length) return void 0;
|
|
122
|
+
for (const rule of rules) {
|
|
123
|
+
if (matchConditionalRule(raw, rule)) {
|
|
124
|
+
const s = {};
|
|
125
|
+
if (rule.bg) s.bg = rule.bg;
|
|
126
|
+
if (rule.fg) s.fg = rule.fg;
|
|
127
|
+
if (rule.bold) s.bold = true;
|
|
128
|
+
return s;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return void 0;
|
|
132
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data-validation logic for the Sheets renderer — pure functions over a
|
|
3
|
+
* validation spec stored on a column (or cell) document's meta. The renderer
|
|
4
|
+
* decides what to do with the verdict (flag vs reject) and how to render the
|
|
5
|
+
* dropdown; this module only answers "is this value valid?" and "what are the
|
|
6
|
+
* allowed options?". Document-native: the spec lives on the entry's meta.
|
|
7
|
+
*
|
|
8
|
+
* All exports auto-import by name (`validateValue`, `isCellValid`, …).
|
|
9
|
+
*/
|
|
10
|
+
import type { DocPageMeta, SheetsValidation } from '../types.js';
|
|
11
|
+
/** Resolve the effective validation for a cell: cell meta first, then column. */
|
|
12
|
+
export declare function resolveValidation(cellMeta?: DocPageMeta, columnMeta?: DocPageMeta): SheetsValidation | undefined;
|
|
13
|
+
/** Allowed dropdown options for a list-validated cell (empty otherwise). */
|
|
14
|
+
export declare function validationListValues(v: SheetsValidation | undefined): string[];
|
|
15
|
+
/**
|
|
16
|
+
* Is `raw` valid against the spec? Empty values are always valid (a blank cell
|
|
17
|
+
* is never an error — matches spreadsheet behaviour). Returns true when there is
|
|
18
|
+
* no spec.
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateValue(raw: string, v: SheetsValidation | undefined): boolean;
|
|
21
|
+
/** Convenience: validate a cell value given cell + column meta. */
|
|
22
|
+
export declare function isCellValid(raw: string, cellMeta?: DocPageMeta, columnMeta?: DocPageMeta): boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export function resolveValidation(cellMeta, columnMeta) {
|
|
2
|
+
return cellMeta?.validation ?? columnMeta?.validation;
|
|
3
|
+
}
|
|
4
|
+
export function validationListValues(v) {
|
|
5
|
+
return v?.type === "list" ? v.values ?? [] : [];
|
|
6
|
+
}
|
|
7
|
+
export function validateValue(raw, v) {
|
|
8
|
+
if (!v) return true;
|
|
9
|
+
if (raw === "") return true;
|
|
10
|
+
switch (v.type) {
|
|
11
|
+
case "list":
|
|
12
|
+
return !v.values || v.values.length === 0 || v.values.includes(raw);
|
|
13
|
+
case "number": {
|
|
14
|
+
const n = Number(raw);
|
|
15
|
+
if (Number.isNaN(n)) return false;
|
|
16
|
+
if (v.min !== void 0 && n < v.min) return false;
|
|
17
|
+
if (v.max !== void 0 && n > v.max) return false;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
case "date": {
|
|
21
|
+
const t = Date.parse(raw);
|
|
22
|
+
if (Number.isNaN(t)) return false;
|
|
23
|
+
if (v.dateMin && t < Date.parse(v.dateMin)) return false;
|
|
24
|
+
if (v.dateMax && t > Date.parse(v.dateMax)) return false;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
case "text": {
|
|
28
|
+
if (v.min !== void 0 && raw.length < v.min) return false;
|
|
29
|
+
if (v.max !== void 0 && raw.length > v.max) return false;
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
default:
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function isCellValid(raw, cellMeta, columnMeta) {
|
|
37
|
+
return validateValue(raw, resolveValidation(cellMeta, columnMeta));
|
|
38
|
+
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -270,6 +270,38 @@ export interface DocPageMeta extends Record<string, unknown> {
|
|
|
270
270
|
timelinePixelsPerDay?: number;
|
|
271
271
|
timelineCenterDate?: string;
|
|
272
272
|
timelineZoom?: string;
|
|
273
|
+
bold?: boolean;
|
|
274
|
+
italic?: boolean;
|
|
275
|
+
textColor?: string;
|
|
276
|
+
bgColor?: string;
|
|
277
|
+
align?: 'left' | 'center' | 'right';
|
|
278
|
+
numberFormat?: 'general' | 'number' | 'currency' | 'percent' | 'date' | 'time' | 'datetime' | 'scientific' | 'accounting';
|
|
279
|
+
numberDecimals?: number;
|
|
280
|
+
numberCurrency?: string;
|
|
281
|
+
numberThousands?: boolean;
|
|
282
|
+
numberNegativeRed?: boolean;
|
|
283
|
+
dateFormat?: string;
|
|
284
|
+
cfRules?: SheetsConditionalRule[];
|
|
285
|
+
validation?: SheetsValidation;
|
|
286
|
+
}
|
|
287
|
+
export type SheetsConditionalOp = 'gt' | 'lt' | 'ge' | 'le' | 'eq' | 'ne' | 'between' | 'contains' | 'notContains' | 'isEmpty' | 'notEmpty';
|
|
288
|
+
export interface SheetsConditionalRule {
|
|
289
|
+
op: SheetsConditionalOp;
|
|
290
|
+
value?: string | number;
|
|
291
|
+
value2?: string | number;
|
|
292
|
+
bg?: string;
|
|
293
|
+
fg?: string;
|
|
294
|
+
bold?: boolean;
|
|
295
|
+
}
|
|
296
|
+
export type SheetsValidationType = 'list' | 'number' | 'date' | 'text';
|
|
297
|
+
export interface SheetsValidation {
|
|
298
|
+
type: SheetsValidationType;
|
|
299
|
+
values?: string[];
|
|
300
|
+
min?: number;
|
|
301
|
+
max?: number;
|
|
302
|
+
dateMin?: string;
|
|
303
|
+
dateMax?: string;
|
|
304
|
+
reject?: boolean;
|
|
273
305
|
}
|
|
274
306
|
export interface TableColumnDef {
|
|
275
307
|
id: string;
|
|
@@ -305,9 +337,11 @@ export interface AwarenessUser {
|
|
|
305
337
|
name?: string;
|
|
306
338
|
color?: string;
|
|
307
339
|
avatar?: string;
|
|
308
|
-
/**
|
|
340
|
+
/**
|
|
341
|
+
* Lucide icon name without the `i-lucide-` prefix (e.g. `coffee`).
|
|
309
342
|
* Drives <AAvatar>'s status overlay and optional status-as-avatar
|
|
310
|
-
* rendering. Empty / undefined = no status icon.
|
|
343
|
+
* rendering. Empty / undefined = no status icon.
|
|
344
|
+
*/
|
|
311
345
|
statusIcon?: string;
|
|
312
346
|
/** Free-form short status text (≤ 80 chars). */
|
|
313
347
|
statusText?: string;
|
|
@@ -411,13 +445,17 @@ export interface AbracadabraState {
|
|
|
411
445
|
userColorName: Ref<string>;
|
|
412
446
|
userNeutralColorName: Ref<string>;
|
|
413
447
|
userCount: Ref<number>;
|
|
414
|
-
/**
|
|
415
|
-
*
|
|
448
|
+
/**
|
|
449
|
+
* Lucide icon name (no `i-lucide-` prefix) for the user's status, or
|
|
450
|
+
* empty string when no status is set. Broadcast via awareness.
|
|
451
|
+
*/
|
|
416
452
|
userStatusIcon: Ref<string>;
|
|
417
453
|
/** Free-form short status text (≤ 80 chars). Broadcast via awareness. */
|
|
418
454
|
userStatusText: Ref<string>;
|
|
419
|
-
/**
|
|
420
|
-
*
|
|
455
|
+
/**
|
|
456
|
+
* Local-only preference: when true, <AAvatar> renders the status icon
|
|
457
|
+
* in place of the avatar initials for the current user.
|
|
458
|
+
*/
|
|
421
459
|
userStatusAsAvatar: Ref<boolean>;
|
|
422
460
|
publicKeyB64: Ref<string>;
|
|
423
461
|
connectionError: Ref<string | null>;
|
|
@@ -443,8 +481,10 @@ export interface AbracadabraState {
|
|
|
443
481
|
setUserName: (name: string) => void;
|
|
444
482
|
setUserColor: (colorName: string) => void;
|
|
445
483
|
setNeutralColor: (colorName: string) => void;
|
|
446
|
-
/**
|
|
447
|
-
*
|
|
484
|
+
/**
|
|
485
|
+
* Set the Lucide icon used as the user's status (without the
|
|
486
|
+
* `i-lucide-` prefix). Pass an empty string to clear.
|
|
487
|
+
*/
|
|
448
488
|
setUserStatusIcon: (icon: string) => void;
|
|
449
489
|
/** Set the user's status text. Pass empty string to clear. */
|
|
450
490
|
setUserStatusText: (text: string) => void;
|
|
@@ -494,9 +534,11 @@ export interface AbracadabraState {
|
|
|
494
534
|
* `getMe().hasPassword` after each successful auth event.
|
|
495
535
|
*/
|
|
496
536
|
hasPassword: Ref<boolean>;
|
|
497
|
-
/**
|
|
537
|
+
/**
|
|
538
|
+
* Force-refresh `hasPassword` from `getMe()`. Call after a successful
|
|
498
539
|
* `setPassword`/`changePassword` if the consumer wants to read the
|
|
499
|
-
* server's authoritative state instead of trusting the optimistic flip.
|
|
540
|
+
* server's authoritative state instead of trusting the optimistic flip.
|
|
541
|
+
*/
|
|
500
542
|
refreshHasPassword: () => Promise<void>;
|
|
501
543
|
reconnect: () => void;
|
|
502
544
|
addServer: (url: string) => Promise<void>;
|