@colixsystems/widget-sdk 0.337.0 → 0.337.2
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 +10 -2
- package/dist/datetimepicker-os-steps.js +29 -0
- package/dist/datetimepicker.native.js +37 -16
- package/dist/host.d.ts +7 -0
- package/dist/host.js +3 -0
- package/dist/linter.cjs +79 -7
- package/dist/linter.js +79 -7
- package/dist/navigation.cjs +23 -0
- package/dist/navigation.js +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,7 +91,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
91
|
|
|
92
92
|
## Status
|
|
93
93
|
|
|
94
|
-
`v0.337.
|
|
94
|
+
`v0.337.2` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
95
|
+
|
|
96
|
+
### What's new in 0.337.2 (contract 1.275.0)
|
|
97
|
+
|
|
98
|
+
**A `mode="datetime"` `<DateTimePicker>` works on Android.** Android has no combined date-and-time dialog, so the field opens the date dialog and then the time dialog, and emits once both are answered. Before, it showed only the date dialog, kept the time of day it opened with, and the widget crashed as the dialog closed (`Cannot read property 'dismiss' of undefined`). Cancelling either dialog changes nothing. iOS keeps its single date-and-time picker. Fix-only: no prop or export changed.
|
|
99
|
+
|
|
100
|
+
### What's new in 0.337.1 (contract 1.275.0)
|
|
101
|
+
|
|
102
|
+
**The two permission-gate lint rules accept the code the contract prescribes.** `row-action-not-gated` no longer flags an `update` or `delete` of the row the widget's own `create()` just returned, as in the record-file attach flow (`const row = await create(values)`, then `upload(file, { recordId: row.id })`, then `update(row.id, …)`). That row carries no `_capabilities`, and whether its creator may edit it is set by the table's permissions. The exemption holds only while that name is bound once, so a listed `row` elsewhere in the file still needs its per-row gate. `write-not-gated-on-user` now accepts a `_capabilities` read as the gate when the widget only edits or deletes existing rows; a widget that also creates rows still gates the create on `useCanWrite(tableId)` or `useUser()`. Both findings now name the fix for each case. Fix-only: no rule was added or renamed.
|
|
95
103
|
|
|
96
104
|
### What's new in 0.337.0 (contract 1.275.0)
|
|
97
105
|
|
|
@@ -4193,7 +4201,7 @@ Pass `--manifest` to enable `style-field-unread` and the three editability rules
|
|
|
4193
4201
|
|
|
4194
4202
|
`comment-as-jsx-text` refuses a `//` or `/* */` comment written between JSX tags, where it is text the web Player shows and the native app refuses. Write it as `{/* … */}`. An error.
|
|
4195
4203
|
|
|
4196
|
-
`row-action-not-gated` flags a widget that calls `update` or `delete` from `useDatastoreMutation` without a per-row permission check: no `_capabilities` read and no `useCanWrite(tableId, { recordId })`. The table-level `useCanWrite(tableId)` only answers "may create", so a list gated on it shows Edit / Delete on rows the server will refuse. A warning.
|
|
4204
|
+
`row-action-not-gated` flags a widget that calls `update` or `delete` from `useDatastoreMutation` without a per-row permission check: no `_capabilities` read and no `useCanWrite(tableId, { recordId })`. An `update` or `delete` of the row the widget's own `create()` just returned is exempt. The table-level `useCanWrite(tableId)` only answers "may create", so a list gated on it shows Edit / Delete on rows the server will refuse. A warning.
|
|
4197
4205
|
|
|
4198
4206
|
`no-html-in-content` flags an HTML tag inside a **string** — `"<strong>"`, `"<br>"`, `"<p>…</p>"`. There is no HTML renderer on either host, so the tag reaches the reader as literal text; author formatted text with `<MarkdownInput>` and render it with `<RichText>` instead. Only string and template content is scanned, so your own `<View>` / `<Text>` JSX can never trip it. A warning for a human author, blocking for the AI widget agent.
|
|
4199
4207
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// REQ-WSDK-PLATFORM §6 — the dialogs the native `<DateTimePicker>` walks
|
|
2
|
+
// through. Pure, so it is unit-tested without React Native.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The OS dialog modes one pick opens, in order. Android has no combined
|
|
6
|
+
* dialog, and its picker library cannot dismiss a "datetime" one.
|
|
7
|
+
*
|
|
8
|
+
* @param {"date" | "time" | "datetime"} mode
|
|
9
|
+
* @param {string} os — `Platform.OS`.
|
|
10
|
+
* @returns {Array<"date" | "time" | "datetime">}
|
|
11
|
+
*/
|
|
12
|
+
export function osDialogModes(mode, os) {
|
|
13
|
+
return mode === "datetime" && os === "android" ? ["date", "time"] : [mode];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The draft parts with the fields one dialog answered taken from `picked`.
|
|
18
|
+
*
|
|
19
|
+
* @param {{year: number, month: number, day: number, hours: number, minutes: number}} draft
|
|
20
|
+
* @param {Date} picked
|
|
21
|
+
* @param {"date" | "time" | "datetime"} dialogMode
|
|
22
|
+
*/
|
|
23
|
+
export function applyDialogPick(draft, picked, dialogMode) {
|
|
24
|
+
const date = { year: picked.getFullYear(), month: picked.getMonth(), day: picked.getDate() };
|
|
25
|
+
const time = { hours: picked.getHours(), minutes: picked.getMinutes() };
|
|
26
|
+
if (dialogMode === "date") return { ...draft, ...date };
|
|
27
|
+
if (dialogMode === "time") return { ...draft, ...time };
|
|
28
|
+
return { ...draft, ...date, ...time };
|
|
29
|
+
}
|
|
@@ -9,7 +9,8 @@ import RNDateTimePicker from "@react-native-community/datetimepicker";
|
|
|
9
9
|
import { View, Pressable, Platform } from "react-native";
|
|
10
10
|
import { Text } from "./bounded-text.native.js";
|
|
11
11
|
import { makeDateTimePicker } from "./datetimepicker-view.js";
|
|
12
|
-
import { nowParts, partsToDate
|
|
12
|
+
import { nowParts, partsToDate } from "./datetimepicker-format.js";
|
|
13
|
+
import { osDialogModes, applyDialogPick } from "./datetimepicker-os-steps.js";
|
|
13
14
|
import { clampToBounds } from "./datetimepicker-calendar.js";
|
|
14
15
|
|
|
15
16
|
function boundDate(parts, mode) {
|
|
@@ -17,23 +18,43 @@ function boundDate(parts, mode) {
|
|
|
17
18
|
return partsToDate(parts);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
function OsPicker({ open,
|
|
21
|
+
function OsPicker({ open, ...dialog }) {
|
|
21
22
|
if (!open) return null;
|
|
22
|
-
|
|
23
|
+
return React.createElement(OsDialogs, dialog);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Mounted per pick, so each one starts from the field's current value.
|
|
27
|
+
function OsDialogs({ onClose, mode, parts, bounds, onPick }) {
|
|
28
|
+
const modes = osDialogModes(mode, Platform.OS);
|
|
29
|
+
const [step, setStep] = React.useState(0);
|
|
30
|
+
const [draft, setDraft] = React.useState(() =>
|
|
31
|
+
parts ? { ...nowParts(), ...dropEmpty(parts) } : clampToBounds(nowParts(), bounds),
|
|
32
|
+
);
|
|
33
|
+
const latest = React.useRef(null);
|
|
34
|
+
latest.current = { onClose, onPick, bounds, modes, step, draft };
|
|
35
|
+
// Stable: Android reopens its dialog whenever onChange changes.
|
|
36
|
+
const onChange = React.useCallback((event, picked) => {
|
|
37
|
+
const { onClose, onPick, bounds, modes, step, draft } = latest.current;
|
|
38
|
+
// Android reports a cancelled dialog as "dismissed".
|
|
39
|
+
const cancelled = (event && event.type === "dismissed") || !(picked instanceof Date);
|
|
40
|
+
const next = cancelled ? null : applyDialogPick(draft, picked, modes[step]);
|
|
41
|
+
if (next && step + 1 < modes.length) {
|
|
42
|
+
setDraft(next);
|
|
43
|
+
setStep(step + 1);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
onClose();
|
|
47
|
+
// Android's time dialog cannot be bounded, so a pick is clamped here.
|
|
48
|
+
if (next) onPick(clampToBounds(next, bounds));
|
|
49
|
+
}, []);
|
|
50
|
+
const dialogMode = modes[step];
|
|
23
51
|
return React.createElement(RNDateTimePicker, {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
mode,
|
|
27
|
-
minimumDate: boundDate(bounds.min,
|
|
28
|
-
maximumDate: boundDate(bounds.max,
|
|
29
|
-
onChange
|
|
30
|
-
onClose();
|
|
31
|
-
// Android reports a cancelled dialog as "dismissed".
|
|
32
|
-
if (event && event.type === "dismissed") return;
|
|
33
|
-
if (!(picked instanceof Date)) return;
|
|
34
|
-
// Android's time dialog cannot be bounded, so a pick is clamped here.
|
|
35
|
-
onPick(clampToBounds(valueToParts(picked.toISOString(), "datetime"), bounds));
|
|
36
|
-
},
|
|
52
|
+
key: dialogMode,
|
|
53
|
+
value: partsToDate(draft),
|
|
54
|
+
mode: dialogMode,
|
|
55
|
+
minimumDate: boundDate(bounds.min, dialogMode),
|
|
56
|
+
maximumDate: boundDate(bounds.max, dialogMode),
|
|
57
|
+
onChange,
|
|
37
58
|
});
|
|
38
59
|
}
|
|
39
60
|
|
package/dist/host.d.ts
CHANGED
|
@@ -473,6 +473,13 @@ export function isDarkSurface(input?: {
|
|
|
473
473
|
theme?: unknown;
|
|
474
474
|
} | null): boolean;
|
|
475
475
|
|
|
476
|
+
/** sc-17703 — how the signed-in visitor's account button is drawn. */
|
|
477
|
+
export type AccountButtonStyle = "name" | "avatar";
|
|
478
|
+
export const ACCOUNT_BUTTON_STYLES: readonly AccountButtonStyle[];
|
|
479
|
+
export const DEFAULT_ACCOUNT_BUTTON_STYLE: AccountButtonStyle;
|
|
480
|
+
/** The account button's style from a whole `theme_config`; unset is "name". */
|
|
481
|
+
export function resolveAccountButtonStyle(theme: unknown): AccountButtonStyle;
|
|
482
|
+
|
|
476
483
|
/** The logo a surface draws: the dark-surface variant only beside an app logo. */
|
|
477
484
|
export function resolveAppLogo<T>(
|
|
478
485
|
logo: T | null | undefined,
|
package/dist/host.js
CHANGED
|
@@ -131,6 +131,9 @@ export {
|
|
|
131
131
|
topNavigationPageIds,
|
|
132
132
|
isDarkSurface,
|
|
133
133
|
resolveAppLogo,
|
|
134
|
+
ACCOUNT_BUTTON_STYLES,
|
|
135
|
+
DEFAULT_ACCOUNT_BUTTON_STYLE,
|
|
136
|
+
resolveAccountButtonStyle,
|
|
134
137
|
} from "./navigation.js";
|
|
135
138
|
|
|
136
139
|
// sc-5717: the codec behind `useWidgetRoute()` — how a widget's own internal
|
package/dist/linter.cjs
CHANGED
|
@@ -1803,6 +1803,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1803
1803
|
if (!call) return [];
|
|
1804
1804
|
if (/\buseCanWrite\s*\(/.test(code)) return [];
|
|
1805
1805
|
if (_IDENTITY_GUARD_RES.some((re) => re.test(code))) return [];
|
|
1806
|
+
// Story 17720 — a widget that only edits existing rows gates each on its
|
|
1807
|
+
// `_capabilities`, which is false for a visitor too; row-action-not-gated polices it.
|
|
1808
|
+
if (/\b_capabilities\b/.test(code) && _mutationCallSites(code, "create")?.length === 0) return [];
|
|
1806
1809
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
1807
1810
|
return [
|
|
1808
1811
|
{
|
|
@@ -1811,9 +1814,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1811
1814
|
// Kept under ~210 chars: a finding is truncated at 300 downstream, and
|
|
1812
1815
|
// the fix instruction is the half worth keeping.
|
|
1813
1816
|
label:
|
|
1814
|
-
`writes
|
|
1815
|
-
|
|
1816
|
-
`
|
|
1817
|
+
`writes but never checks who may write - gate a create on ` +
|
|
1818
|
+
`useCanWrite(tableId) (useUser() if it needs sign-in) and an existing ` +
|
|
1819
|
+
`row's edit on row._capabilities, never a live-but-doomed control.`,
|
|
1817
1820
|
line,
|
|
1818
1821
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
1819
1822
|
},
|
|
@@ -2251,21 +2254,88 @@ function _rowActionGatingRules(source) {
|
|
|
2251
2254
|
if (!call) return [];
|
|
2252
2255
|
if (/\b_capabilities\b/.test(code)) return [];
|
|
2253
2256
|
if (/\buseCanWrite\s*\([^)]*\brecordId\b/.test(code)) return [];
|
|
2257
|
+
if (_rowEditsTargetOnlyCreatedRows(code)) return [];
|
|
2254
2258
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
2255
2259
|
return [
|
|
2256
2260
|
{
|
|
2257
2261
|
rule: "row-action-not-gated",
|
|
2258
2262
|
severity: "warning",
|
|
2259
2263
|
label:
|
|
2260
|
-
`edits or deletes
|
|
2261
|
-
`with { includeCapabilities: true }
|
|
2262
|
-
`row._capabilities.can_write / can_delete
|
|
2264
|
+
`edits or deletes an existing row without checking its permission - read ` +
|
|
2265
|
+
`it with { includeCapabilities: true } (useDatastoreQuery or useDatastoreRecord) ` +
|
|
2266
|
+
`and offer the edit only when row._capabilities.can_write / can_delete.`,
|
|
2263
2267
|
line,
|
|
2264
2268
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
2265
2269
|
},
|
|
2266
2270
|
];
|
|
2267
2271
|
}
|
|
2268
2272
|
|
|
2273
|
+
/**
|
|
2274
|
+
* Story 17720 — every update/delete targets `<name>.id` of a row the widget's
|
|
2275
|
+
* own create() returned, as the record-file attach flow does. That row carries
|
|
2276
|
+
* no `_capabilities`, and whether its creator may edit it is the table ACL's
|
|
2277
|
+
* job, so no per-row gate exists to ask for.
|
|
2278
|
+
*/
|
|
2279
|
+
function _rowEditsTargetOnlyCreatedRows(code) {
|
|
2280
|
+
const [updates, deletes, creates] = ["update", "delete", "create"].map((verb) => _mutationCallSites(code, verb));
|
|
2281
|
+
if (!updates || !deletes || !creates) return false;
|
|
2282
|
+
const sites = [...updates, ...deletes];
|
|
2283
|
+
if (sites.length === 0) return false;
|
|
2284
|
+
const created = new Set();
|
|
2285
|
+
for (const site of creates) {
|
|
2286
|
+
const before = code.slice(Math.max(0, site - 200), site);
|
|
2287
|
+
const bound = /(?<![\w$.])([A-Za-z_$][\w$]*)\s*=\s*await\s+(?:[\w$]+\s*\.\s*)?[\w$]+\s*$/.exec(before);
|
|
2288
|
+
if (bound && _boundOnlyByCreate(code, bound[1])) created.add(bound[1]);
|
|
2289
|
+
}
|
|
2290
|
+
return sites.every((open) => {
|
|
2291
|
+
const target = /^\s*([A-Za-z_$][\w$]*)\s*\??\.\s*id\s*[,)]/.exec(code.slice(open + 1));
|
|
2292
|
+
return Boolean(target) && created.has(target[1]);
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
// One declaration, assigned only by that create (a `let row; try { row =
|
|
2297
|
+
// await create(…) }` too). Any other binding of the name, such as a
|
|
2298
|
+
// `.map((row) =>` parameter or a destructure, could be a listed row.
|
|
2299
|
+
function _boundOnlyByCreate(code, name) {
|
|
2300
|
+
const n = name.replace(/\$/g, "\\$");
|
|
2301
|
+
const count = (re) => (code.match(re) || []).length;
|
|
2302
|
+
const emptyDeclaration = new RegExp(`\\blet\\s+${n}\\s*(?:=\\s*(?:null|undefined)\\s*)?[;,]`);
|
|
2303
|
+
return (
|
|
2304
|
+
count(new RegExp(`\\b(?:const|let|var)\\s+${n}(?![\\w$])`, "g")) === 1 &&
|
|
2305
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*=(?![=>])`, "g")) ===
|
|
2306
|
+
1 + count(new RegExp(`\\blet\\s+${n}\\s*=\\s*(?:null|undefined)\\b`, "g")) &&
|
|
2307
|
+
(count(new RegExp(`\\bconst\\s+${n}\\s*=\\s*await\\b`, "g")) === 1 || emptyDeclaration.test(code)) &&
|
|
2308
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*(?:=>|[-+*/%&|^?]{1,3}=)`, "g")) === 0 &&
|
|
2309
|
+
count(new RegExp(`\\bfor\\s*\\(\\s*${n}\\s+(?:of|in)\\b`, "g")) === 0 &&
|
|
2310
|
+
count(new RegExp(`[({\\[,:]\\s*(?:\\.\\.\\.)?${n}\\s*[,)}\\]]`, "g")) === 0
|
|
2311
|
+
);
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
/**
|
|
2315
|
+
* Index of the `(` of each call the widget makes to `verb` on a
|
|
2316
|
+
* useDatastoreMutation() result: `verb(` through its destructured local, or
|
|
2317
|
+
* `name.verb(` on a named mutation object. Null when a local cannot be read.
|
|
2318
|
+
*/
|
|
2319
|
+
function _mutationCallSites(code, verb) {
|
|
2320
|
+
const callees = [];
|
|
2321
|
+
for (const call of _mutationHookCalls(code)) {
|
|
2322
|
+
if (!call.destructured) {
|
|
2323
|
+
callees.push(`(?<![\\w$])${call.name.replace(/\$/g, "\\$")}\\s*\\.\\s*${verb}`);
|
|
2324
|
+
continue;
|
|
2325
|
+
}
|
|
2326
|
+
for (const entry of call.destructured.split(",")) {
|
|
2327
|
+
const [key, local = key] = entry.split(":").map((part) => part.trim());
|
|
2328
|
+
if (key !== verb) continue;
|
|
2329
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(local)) return null;
|
|
2330
|
+
callees.push(`(?<![\\w$.])${local.replace(/\$/g, "\\$")}`);
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
if (callees.length === 0) return [];
|
|
2334
|
+
return [...code.matchAll(new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g"))].map(
|
|
2335
|
+
(m) => m.index + m[0].length - 1,
|
|
2336
|
+
);
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2269
2339
|
// The useDatastoreMutation() call whose update or delete the widget uses,
|
|
2270
2340
|
// either as `m.update(` / `m.delete(` or destructured `{ update, delete }`.
|
|
2271
2341
|
function _rowMutationCall(code) {
|
|
@@ -2314,7 +2384,9 @@ function _mutationHookCalls(code) {
|
|
|
2314
2384
|
tails.set(close, _MUTATION_TAIL_RE.test(code) ? _MUTATION_TAIL_RE.lastIndex : -1);
|
|
2315
2385
|
}
|
|
2316
2386
|
if (tails.get(close) !== -1) {
|
|
2317
|
-
|
|
2387
|
+
// The run from an enclosing body brace holds its statements too.
|
|
2388
|
+
const open = code.lastIndexOf("{", close);
|
|
2389
|
+
destructured = { index: open, destructured: code.slice(open + 1, close) };
|
|
2318
2390
|
break;
|
|
2319
2391
|
}
|
|
2320
2392
|
}
|
package/dist/linter.js
CHANGED
|
@@ -1798,6 +1798,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1798
1798
|
if (!call) return [];
|
|
1799
1799
|
if (/\buseCanWrite\s*\(/.test(code)) return [];
|
|
1800
1800
|
if (_IDENTITY_GUARD_RES.some((re) => re.test(code))) return [];
|
|
1801
|
+
// Story 17720 — a widget that only edits existing rows gates each on its
|
|
1802
|
+
// `_capabilities`, which is false for a visitor too; row-action-not-gated polices it.
|
|
1803
|
+
if (/\b_capabilities\b/.test(code) && _mutationCallSites(code, "create")?.length === 0) return [];
|
|
1801
1804
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
1802
1805
|
return [
|
|
1803
1806
|
{
|
|
@@ -1806,9 +1809,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1806
1809
|
// Kept under ~210 chars: a finding is truncated at 300 downstream, and
|
|
1807
1810
|
// the fix instruction is the half worth keeping.
|
|
1808
1811
|
label:
|
|
1809
|
-
`writes
|
|
1810
|
-
|
|
1811
|
-
`
|
|
1812
|
+
`writes but never checks who may write - gate a create on ` +
|
|
1813
|
+
`useCanWrite(tableId) (useUser() if it needs sign-in) and an existing ` +
|
|
1814
|
+
`row's edit on row._capabilities, never a live-but-doomed control.`,
|
|
1812
1815
|
line,
|
|
1813
1816
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
1814
1817
|
},
|
|
@@ -2246,21 +2249,88 @@ function _rowActionGatingRules(source) {
|
|
|
2246
2249
|
if (!call) return [];
|
|
2247
2250
|
if (/\b_capabilities\b/.test(code)) return [];
|
|
2248
2251
|
if (/\buseCanWrite\s*\([^)]*\brecordId\b/.test(code)) return [];
|
|
2252
|
+
if (_rowEditsTargetOnlyCreatedRows(code)) return [];
|
|
2249
2253
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
2250
2254
|
return [
|
|
2251
2255
|
{
|
|
2252
2256
|
rule: "row-action-not-gated",
|
|
2253
2257
|
severity: "warning",
|
|
2254
2258
|
label:
|
|
2255
|
-
`edits or deletes
|
|
2256
|
-
`with { includeCapabilities: true }
|
|
2257
|
-
`row._capabilities.can_write / can_delete
|
|
2259
|
+
`edits or deletes an existing row without checking its permission - read ` +
|
|
2260
|
+
`it with { includeCapabilities: true } (useDatastoreQuery or useDatastoreRecord) ` +
|
|
2261
|
+
`and offer the edit only when row._capabilities.can_write / can_delete.`,
|
|
2258
2262
|
line,
|
|
2259
2263
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
2260
2264
|
},
|
|
2261
2265
|
];
|
|
2262
2266
|
}
|
|
2263
2267
|
|
|
2268
|
+
/**
|
|
2269
|
+
* Story 17720 — every update/delete targets `<name>.id` of a row the widget's
|
|
2270
|
+
* own create() returned, as the record-file attach flow does. That row carries
|
|
2271
|
+
* no `_capabilities`, and whether its creator may edit it is the table ACL's
|
|
2272
|
+
* job, so no per-row gate exists to ask for.
|
|
2273
|
+
*/
|
|
2274
|
+
function _rowEditsTargetOnlyCreatedRows(code) {
|
|
2275
|
+
const [updates, deletes, creates] = ["update", "delete", "create"].map((verb) => _mutationCallSites(code, verb));
|
|
2276
|
+
if (!updates || !deletes || !creates) return false;
|
|
2277
|
+
const sites = [...updates, ...deletes];
|
|
2278
|
+
if (sites.length === 0) return false;
|
|
2279
|
+
const created = new Set();
|
|
2280
|
+
for (const site of creates) {
|
|
2281
|
+
const before = code.slice(Math.max(0, site - 200), site);
|
|
2282
|
+
const bound = /(?<![\w$.])([A-Za-z_$][\w$]*)\s*=\s*await\s+(?:[\w$]+\s*\.\s*)?[\w$]+\s*$/.exec(before);
|
|
2283
|
+
if (bound && _boundOnlyByCreate(code, bound[1])) created.add(bound[1]);
|
|
2284
|
+
}
|
|
2285
|
+
return sites.every((open) => {
|
|
2286
|
+
const target = /^\s*([A-Za-z_$][\w$]*)\s*\??\.\s*id\s*[,)]/.exec(code.slice(open + 1));
|
|
2287
|
+
return Boolean(target) && created.has(target[1]);
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
// One declaration, assigned only by that create (a `let row; try { row =
|
|
2292
|
+
// await create(…) }` too). Any other binding of the name, such as a
|
|
2293
|
+
// `.map((row) =>` parameter or a destructure, could be a listed row.
|
|
2294
|
+
function _boundOnlyByCreate(code, name) {
|
|
2295
|
+
const n = name.replace(/\$/g, "\\$");
|
|
2296
|
+
const count = (re) => (code.match(re) || []).length;
|
|
2297
|
+
const emptyDeclaration = new RegExp(`\\blet\\s+${n}\\s*(?:=\\s*(?:null|undefined)\\s*)?[;,]`);
|
|
2298
|
+
return (
|
|
2299
|
+
count(new RegExp(`\\b(?:const|let|var)\\s+${n}(?![\\w$])`, "g")) === 1 &&
|
|
2300
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*=(?![=>])`, "g")) ===
|
|
2301
|
+
1 + count(new RegExp(`\\blet\\s+${n}\\s*=\\s*(?:null|undefined)\\b`, "g")) &&
|
|
2302
|
+
(count(new RegExp(`\\bconst\\s+${n}\\s*=\\s*await\\b`, "g")) === 1 || emptyDeclaration.test(code)) &&
|
|
2303
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*(?:=>|[-+*/%&|^?]{1,3}=)`, "g")) === 0 &&
|
|
2304
|
+
count(new RegExp(`\\bfor\\s*\\(\\s*${n}\\s+(?:of|in)\\b`, "g")) === 0 &&
|
|
2305
|
+
count(new RegExp(`[({\\[,:]\\s*(?:\\.\\.\\.)?${n}\\s*[,)}\\]]`, "g")) === 0
|
|
2306
|
+
);
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
/**
|
|
2310
|
+
* Index of the `(` of each call the widget makes to `verb` on a
|
|
2311
|
+
* useDatastoreMutation() result: `verb(` through its destructured local, or
|
|
2312
|
+
* `name.verb(` on a named mutation object. Null when a local cannot be read.
|
|
2313
|
+
*/
|
|
2314
|
+
function _mutationCallSites(code, verb) {
|
|
2315
|
+
const callees = [];
|
|
2316
|
+
for (const call of _mutationHookCalls(code)) {
|
|
2317
|
+
if (!call.destructured) {
|
|
2318
|
+
callees.push(`(?<![\\w$])${call.name.replace(/\$/g, "\\$")}\\s*\\.\\s*${verb}`);
|
|
2319
|
+
continue;
|
|
2320
|
+
}
|
|
2321
|
+
for (const entry of call.destructured.split(",")) {
|
|
2322
|
+
const [key, local = key] = entry.split(":").map((part) => part.trim());
|
|
2323
|
+
if (key !== verb) continue;
|
|
2324
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(local)) return null;
|
|
2325
|
+
callees.push(`(?<![\\w$.])${local.replace(/\$/g, "\\$")}`);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
if (callees.length === 0) return [];
|
|
2329
|
+
return [...code.matchAll(new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g"))].map(
|
|
2330
|
+
(m) => m.index + m[0].length - 1,
|
|
2331
|
+
);
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2264
2334
|
// The useDatastoreMutation() call whose update or delete the widget uses,
|
|
2265
2335
|
// either as `m.update(` / `m.delete(` or destructured `{ update, delete }`.
|
|
2266
2336
|
function _rowMutationCall(code) {
|
|
@@ -2309,7 +2379,9 @@ function _mutationHookCalls(code) {
|
|
|
2309
2379
|
tails.set(close, _MUTATION_TAIL_RE.test(code) ? _MUTATION_TAIL_RE.lastIndex : -1);
|
|
2310
2380
|
}
|
|
2311
2381
|
if (tails.get(close) !== -1) {
|
|
2312
|
-
|
|
2382
|
+
// The run from an enclosing body brace holds its statements too.
|
|
2383
|
+
const open = code.lastIndexOf("{", close);
|
|
2384
|
+
destructured = { index: open, destructured: code.slice(open + 1, close) };
|
|
2313
2385
|
break;
|
|
2314
2386
|
}
|
|
2315
2387
|
}
|
package/dist/navigation.cjs
CHANGED
|
@@ -918,6 +918,26 @@ function borderWidthOr(...values) {
|
|
|
918
918
|
}
|
|
919
919
|
return BORDER_WIDTH_MIN;
|
|
920
920
|
}
|
|
921
|
+
|
|
922
|
+
// sc-17703: how the signed-in visitor's account button is drawn. `name` is the
|
|
923
|
+
// avatar, name and chevron pill. `avatar` is the bare avatar circle, which
|
|
924
|
+
// leaves the app's brand more room. Both open the same account menu.
|
|
925
|
+
const ACCOUNT_BUTTON_STYLES = ["name", "avatar"];
|
|
926
|
+
const DEFAULT_ACCOUNT_BUTTON_STYLE = "name";
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* The account button's style, resolved for every host.
|
|
930
|
+
*
|
|
931
|
+
* @param {unknown} theme — the whole `theme_config`.
|
|
932
|
+
* @returns {"name"|"avatar"}
|
|
933
|
+
*/
|
|
934
|
+
function resolveAccountButtonStyle(theme) {
|
|
935
|
+
const config = isPlainObject(theme) ? theme : {};
|
|
936
|
+
const account = isPlainObject(config.account) ? config.account : {};
|
|
937
|
+
return ACCOUNT_BUTTON_STYLES.includes(account.buttonStyle)
|
|
938
|
+
? account.buttonStyle
|
|
939
|
+
: DEFAULT_ACCOUNT_BUTTON_STYLE;
|
|
940
|
+
}
|
|
921
941
|
module.exports = {
|
|
922
942
|
normaliseNavigation,
|
|
923
943
|
menuItemCap,
|
|
@@ -950,4 +970,7 @@ module.exports = {
|
|
|
950
970
|
resolvePageBars,
|
|
951
971
|
drawsTopNavigation,
|
|
952
972
|
topNavigationPageIds,
|
|
973
|
+
ACCOUNT_BUTTON_STYLES,
|
|
974
|
+
DEFAULT_ACCOUNT_BUTTON_STYLE,
|
|
975
|
+
resolveAccountButtonStyle,
|
|
953
976
|
};
|
package/dist/navigation.js
CHANGED
|
@@ -913,3 +913,23 @@ function borderWidthOr(...values) {
|
|
|
913
913
|
}
|
|
914
914
|
return BORDER_WIDTH_MIN;
|
|
915
915
|
}
|
|
916
|
+
|
|
917
|
+
// sc-17703: how the signed-in visitor's account button is drawn. `name` is the
|
|
918
|
+
// avatar, name and chevron pill. `avatar` is the bare avatar circle, which
|
|
919
|
+
// leaves the app's brand more room. Both open the same account menu.
|
|
920
|
+
export const ACCOUNT_BUTTON_STYLES = ["name", "avatar"];
|
|
921
|
+
export const DEFAULT_ACCOUNT_BUTTON_STYLE = "name";
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* The account button's style, resolved for every host.
|
|
925
|
+
*
|
|
926
|
+
* @param {unknown} theme — the whole `theme_config`.
|
|
927
|
+
* @returns {"name"|"avatar"}
|
|
928
|
+
*/
|
|
929
|
+
export function resolveAccountButtonStyle(theme) {
|
|
930
|
+
const config = isPlainObject(theme) ? theme : {};
|
|
931
|
+
const account = isPlainObject(config.account) ? config.account : {};
|
|
932
|
+
return ACCOUNT_BUTTON_STYLES.includes(account.buttonStyle)
|
|
933
|
+
? account.buttonStyle
|
|
934
|
+
: DEFAULT_ACCOUNT_BUTTON_STYLE;
|
|
935
|
+
}
|
package/package.json
CHANGED