@geosynk/vertigis-web-sdk 1.0.10 → 1.1.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/README.md +72 -9
- package/package.json +6 -6
- package/scripts/create.js +12 -2
- package/template/app/favicon.ico +20 -0
- package/template/app/favicon.svg +20 -0
- package/template/package.json +1 -1
- package/template-custom/AGENTS.md +86 -33
- package/template-custom/Dockerfile.build +46 -0
- package/template-custom/app/favicon.ico +20 -0
- package/template-custom/app/favicon.svg +20 -0
- package/template-custom/build.bat +84 -5
- package/template-custom/build.sh +82 -2
- package/template-custom/certs/generate-cert.bat +10 -9
- package/template-custom/certs/generate-cert.sh +1 -0
- package/template-custom/project.config +107 -0
- package/template-custom/scripts/configure-portal.js +56 -7
- package/template-custom/scripts/load-config.bat +12 -0
- package/template-custom/scripts/load-config.sh +26 -0
- package/template-custom/scripts/remote-sync.bat +12 -0
- package/template-custom/scripts/remote-sync.sh +42 -0
- package/template-custom/scripts/verify_zero_cosmetic_sx.py +419 -0
- package/template-custom/src/auth/index.ts +18 -1
- package/template-custom/src/components/CustomWidget/CustomWidget.css +1 -0
- package/template-custom/src/components/CustomWidget/CustomWidget.tsx +28 -49
- package/template-custom/src/components/CustomWidget/components/CustomWidgetErrorBoundary.css +0 -0
- package/template-custom/src/components/CustomWidget/components/CustomWidgetErrorBoundary.tsx +12 -19
- package/template-custom/src/index.ts +4 -1
- package/template-custom/src/tokens/VertiGisThemeProvider.tsx +14 -0
- package/template-custom/src/tokens/index.ts +3 -0
- package/template-custom/src/tokens/muiTheme.ts +61 -0
- package/template-custom/src/tokens/spacing.ts +24 -0
- package/template-custom/src/tokens/typography.ts +0 -4
- package/template-custom/src/tokens/ui.ts +58 -3
- package/template-custom/start.bat +24 -1
- package/template-custom/start.sh +35 -0
- package/template-custom/webpack.config.js +46 -146
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""verify_zero_cosmetic_sx.py - Zero-Cosmetic-SX, 8px spacing grid and non-MUI containment.
|
|
3
|
+
|
|
4
|
+
Single implementation of three rules:
|
|
5
|
+
NO_COSMETIC_SX cosmetic keys (borders, radii, backgrounds, shadows, colour, typography) in
|
|
6
|
+
sx / style / styles dictionaries / styled(); they belong in src/tokens/muiTheme.ts.
|
|
7
|
+
STANDARDIZED_SPACING spacing values off the MUI 8px grid (0, 0.5, 1, 1.5, 2, 2.5, 3, 4), raw lengths.
|
|
8
|
+
NON_MUI_CONTAINMENT <canvas>, <img>, <iframe> whose nearest JSX parent is not Paper or Card.
|
|
9
|
+
|
|
10
|
+
The skill validators (checks_tsx.py) import check_source() from this file, and projects run it
|
|
11
|
+
standalone via `npm run verify:styles`, so both always agree. Identical copy in both VertiGIS SDK
|
|
12
|
+
skills and both SDK templates. Standard library only.
|
|
13
|
+
|
|
14
|
+
Usage: python scripts/verify_zero_cosmetic_sx.py [project-dir-or-file] (default: .)
|
|
15
|
+
Suppress: // vertigis-rule-disable RULE_ID -- <reason> (this or the previous line)
|
|
16
|
+
/* vertigis-rule-disable-file RULE_ID -- <reason> */
|
|
17
|
+
Exit: 0 clean, 1 violations, 2 bad arguments.
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import sys
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
BANNED_COSMETIC_PROPERTIES = frozenset({
|
|
27
|
+
# Borders & outlines
|
|
28
|
+
"border", "borderWidth", "borderStyle", "borderColor",
|
|
29
|
+
"borderTop", "borderBottom", "borderLeft", "borderRight",
|
|
30
|
+
"borderTopWidth", "borderBottomWidth", "borderLeftWidth", "borderRightWidth",
|
|
31
|
+
"borderTopStyle", "borderBottomStyle", "borderLeftStyle", "borderRightStyle",
|
|
32
|
+
"borderTopColor", "borderBottomColor", "borderLeftColor", "borderRightColor",
|
|
33
|
+
"outline", "outlineColor", "outlineWidth", "outlineStyle",
|
|
34
|
+
# Corner radii
|
|
35
|
+
"borderRadius", "borderTopLeftRadius", "borderTopRightRadius",
|
|
36
|
+
"borderBottomLeftRadius", "borderBottomRightRadius",
|
|
37
|
+
# Backgrounds & layers
|
|
38
|
+
"background", "backgroundColor", "bgcolor", "bgColor",
|
|
39
|
+
"backgroundImage", "backgroundSize", "backgroundPosition", "backgroundRepeat",
|
|
40
|
+
"backdropFilter",
|
|
41
|
+
# Shadows & elevation
|
|
42
|
+
"boxShadow", "textShadow", "filter",
|
|
43
|
+
# Colour & typography (use <Typography variant=...> and the color prop)
|
|
44
|
+
"color", "textColor", "textDecoration", "textTransform",
|
|
45
|
+
"fontFamily", "fontSize", "fontWeight", "lineHeight", "letterSpacing",
|
|
46
|
+
})
|
|
47
|
+
SPACING_PROPERTIES = frozenset({
|
|
48
|
+
"p", "px", "py", "pt", "pb", "pl", "pr",
|
|
49
|
+
"padding", "paddingTop", "paddingBottom", "paddingLeft", "paddingRight", "paddingX", "paddingY",
|
|
50
|
+
"gap", "rowGap", "columnGap",
|
|
51
|
+
"m", "mx", "my", "mt", "mb", "ml", "mr",
|
|
52
|
+
"margin", "marginTop", "marginBottom", "marginLeft", "marginRight", "marginX", "marginY",
|
|
53
|
+
})
|
|
54
|
+
SPACING_ATTRIBUTES = SPACING_PROPERTIES | {"spacing", "rowSpacing", "columnSpacing"}
|
|
55
|
+
SYSTEM_PROP_TAGS = frozenset({"Box", "Stack", "Grid", "Container"})
|
|
56
|
+
ALLOWED_SPACING_STEPS = (0, 0.5, 1, 1.5, 2, 2.5, 3, 4)
|
|
57
|
+
SPACING_KEYWORDS = {"auto", "0", "inherit", "initial", "unset"}
|
|
58
|
+
NON_MUI_ELEMENTS = frozenset({"canvas", "img", "iframe"})
|
|
59
|
+
MUI_CONTAINERS = frozenset({"Paper", "Card", "CardContent", "CardMedia", "CardActionArea"})
|
|
60
|
+
RULES = ("NO_COSMETIC_SX", "STANDARDIZED_SPACING", "NON_MUI_CONTAINMENT", "MARGIN_LEAKAGE")
|
|
61
|
+
|
|
62
|
+
SKIP_DIRS = {"node_modules", "dist", "build", "coverage", ".git", ".tgrep", ".venv", "__pycache__"}
|
|
63
|
+
NUMBER = re.compile(r"-?(\d+(\.\d+)?|\.\d+)")
|
|
64
|
+
QUOTED = re.compile(r"([\"'`])(.*)\1", re.S)
|
|
65
|
+
LENGTH = re.compile(r"(?<![\w.-])-?(\d*\.\d+|\d+)(px|rem|em|%|vh|vw|vmin|vmax|ch|ex|pt)(?![\w.%])")
|
|
66
|
+
VAR_CALL = re.compile(r"var\((?:[^()]|\([^()]*\))*\)")
|
|
67
|
+
SPACING_CALL = re.compile(r"\bspacing\(([^()]*)\)")
|
|
68
|
+
ENTRY = re.compile(r"(?:([\"'])(.*?)\1|(\[[^\]]*\])|([\w$]+))\s*:(?!:)\s*(.*)", re.S)
|
|
69
|
+
IDENT = re.compile(r"[\w$]+")
|
|
70
|
+
TAG_START = re.compile(r"<([A-Za-z][\w.]*)")
|
|
71
|
+
CLOSE_TAG = re.compile(r"</([A-Za-z][\w.]*)\s*>")
|
|
72
|
+
STYLE_ATTR = re.compile(r"(?<![\w$.-])(sx|style)\s*=\s*(?=\{)")
|
|
73
|
+
SX_PROPERTY = re.compile(r"(?<![\w$.])[\"']?sx[\"']?\s*:\s*(?=[{\[(])")
|
|
74
|
+
STYLE_DICT = re.compile(r"\b(?:const|let|var)\s+(?:[\w$]*(?:[sS]tyles|Sx|SX)|sx[A-Z][\w$]*)\b[^=;]*=\s*")
|
|
75
|
+
ANY_CONST = re.compile(r"\b(?:const|let|var)\s+[\w$]+\b[^=;]*=\s*")
|
|
76
|
+
STYLED_CALL = re.compile(r"\bstyled\s*\(")
|
|
77
|
+
SUPPRESSION = re.compile(r"vertigis-rule-disable(-file)?\s+([A-Z_]+)\s*--\s*\S")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# ---------------------------------------------------------------- lexical helpers
|
|
81
|
+
|
|
82
|
+
def blank_comments(text: str) -> str:
|
|
83
|
+
"""Replace // and /* */ comments with spaces, keeping offsets and newlines."""
|
|
84
|
+
out, i, n, quote = list(text), 0, len(text), None
|
|
85
|
+
while i < n:
|
|
86
|
+
c, nxt = text[i], text[i + 1] if i + 1 < n else ""
|
|
87
|
+
if quote is None and c == "/" and nxt and nxt in "*/":
|
|
88
|
+
end = text.find("*/", i + 2) + 2 if nxt == "*" else text.find("\n", i)
|
|
89
|
+
end = n if end < (2 if nxt == "*" else 0) else end
|
|
90
|
+
for k in range(i, end):
|
|
91
|
+
if out[k] != "\n":
|
|
92
|
+
out[k] = " "
|
|
93
|
+
i = end
|
|
94
|
+
continue
|
|
95
|
+
if quote is None and c in "\"'`":
|
|
96
|
+
quote = c
|
|
97
|
+
elif quote is not None and c == "\\":
|
|
98
|
+
i += 1
|
|
99
|
+
elif c == quote or (c == "\n" and quote not in (None, "`")):
|
|
100
|
+
quote = None
|
|
101
|
+
i += 1
|
|
102
|
+
return "".join(out)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def skip_string(text: str, i: int) -> int:
|
|
106
|
+
quote, j = text[i], i + 1
|
|
107
|
+
while j < len(text) and text[j] != quote:
|
|
108
|
+
j += 2 if text[j] == "\\" else 1
|
|
109
|
+
return j + 1
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def matching_close(text: str, open_index: int) -> int:
|
|
113
|
+
"""Index of the bracket closing text[open_index]; -1 if unbalanced."""
|
|
114
|
+
pairs, stack, i = {"{": "}", "(": ")", "[": "]"}, [], open_index
|
|
115
|
+
while i < len(text):
|
|
116
|
+
c = text[i]
|
|
117
|
+
if c in "\"'`":
|
|
118
|
+
i = skip_string(text, i)
|
|
119
|
+
continue
|
|
120
|
+
if c in pairs:
|
|
121
|
+
stack.append(pairs[c])
|
|
122
|
+
elif stack and c == stack[-1]:
|
|
123
|
+
stack.pop()
|
|
124
|
+
if not stack:
|
|
125
|
+
return i
|
|
126
|
+
i += 1
|
|
127
|
+
return -1
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def split_top(text: str, base: int) -> list[tuple[int, str]]:
|
|
131
|
+
"""Split on top-level commas; returns (absolute offset, stripped part)."""
|
|
132
|
+
parts, depth, start, i = [], 0, 0, 0
|
|
133
|
+
while i <= len(text):
|
|
134
|
+
c = text[i] if i < len(text) else ","
|
|
135
|
+
if c in "\"'`" and i < len(text):
|
|
136
|
+
i = skip_string(text, i)
|
|
137
|
+
continue
|
|
138
|
+
if c in "{([":
|
|
139
|
+
depth += 1
|
|
140
|
+
elif c in "})]":
|
|
141
|
+
depth -= 1
|
|
142
|
+
elif c == "," and depth == 0:
|
|
143
|
+
chunk = text[start:i]
|
|
144
|
+
if chunk.strip():
|
|
145
|
+
parts.append((base + start + len(chunk) - len(chunk.lstrip()), chunk.strip()))
|
|
146
|
+
start = i + 1
|
|
147
|
+
i += 1
|
|
148
|
+
return parts
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def object_literals(code: str, start: int, end: int):
|
|
152
|
+
"""Yield (open_index, close_index) of the outermost {...} literals in code[start:end]."""
|
|
153
|
+
i = start
|
|
154
|
+
while i < end:
|
|
155
|
+
c = code[i]
|
|
156
|
+
if c in "\"'`":
|
|
157
|
+
i = skip_string(code, i)
|
|
158
|
+
continue
|
|
159
|
+
if c == "{":
|
|
160
|
+
close = matching_close(code, i)
|
|
161
|
+
if close < 0:
|
|
162
|
+
return
|
|
163
|
+
yield i, close
|
|
164
|
+
i = close
|
|
165
|
+
i += 1
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# ---------------------------------------------------------------- value checks
|
|
169
|
+
|
|
170
|
+
def strip_var_calls(text: str) -> str:
|
|
171
|
+
previous = None
|
|
172
|
+
while previous != text:
|
|
173
|
+
previous, text = text, VAR_CALL.sub("", text)
|
|
174
|
+
return text
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def off_grid(number: str) -> bool:
|
|
178
|
+
return abs(float(number)) not in ALLOWED_SPACING_STEPS
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def spacing_problem(value: str) -> str | None:
|
|
182
|
+
"""Why a spacing value breaks the 8px grid, or None when it is fine or not statically known."""
|
|
183
|
+
v = value.strip().rstrip(";").strip()
|
|
184
|
+
if re.search(r"\bSPACING\.\w+", v):
|
|
185
|
+
return None
|
|
186
|
+
if v.startswith(("[", "{")) and matching_close(v, 0) == len(v) - 1:
|
|
187
|
+
items = [p for _, p in split_top(v[1:-1], 0)]
|
|
188
|
+
items = [ENTRY.fullmatch(p).group(5) if v[0] == "{" and ENTRY.fullmatch(p) else p for p in items]
|
|
189
|
+
return next((problem for problem in map(spacing_problem, items) if problem), None)
|
|
190
|
+
if NUMBER.fullmatch(v):
|
|
191
|
+
return f"{v} is not a grid step {ALLOWED_SPACING_STEPS}" if off_grid(v) else None
|
|
192
|
+
quoted = QUOTED.fullmatch(v)
|
|
193
|
+
if quoted:
|
|
194
|
+
text = quoted.group(2).strip()
|
|
195
|
+
if text in SPACING_KEYWORDS:
|
|
196
|
+
return None
|
|
197
|
+
if any(float(n) != 0 for n, _ in LENGTH.findall(strip_var_calls(text))) or NUMBER.fullmatch(text):
|
|
198
|
+
return f"raw length {v}; use a grid step number {ALLOWED_SPACING_STEPS}"
|
|
199
|
+
return None
|
|
200
|
+
for call in SPACING_CALL.finditer(v):
|
|
201
|
+
bad = [n for n in re.split(r"\s*,\s*", call.group(1).strip()) if NUMBER.fullmatch(n) and off_grid(n)]
|
|
202
|
+
if bad:
|
|
203
|
+
return f"spacing({call.group(1)}) is off the grid"
|
|
204
|
+
return None
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def walk_object(code: str, open_index: int, close_index: int, found: list) -> None:
|
|
208
|
+
"""Check every key of an sx/style object literal, descending into selectors, breakpoints and spreads."""
|
|
209
|
+
for offset, part in split_top(code[open_index + 1:close_index], open_index + 1):
|
|
210
|
+
entry = ENTRY.fullmatch(part)
|
|
211
|
+
if not entry:
|
|
212
|
+
if IDENT.fullmatch(part) and part in BANNED_COSMETIC_PROPERTIES:
|
|
213
|
+
found.append(("NO_COSMETIC_SX", offset, f"{part} (shorthand)"))
|
|
214
|
+
else:
|
|
215
|
+
walk_expression(code, offset, offset + len(part), found)
|
|
216
|
+
continue
|
|
217
|
+
key, value = entry.group(2) if entry.group(1) else entry.group(4), entry.group(5).strip()
|
|
218
|
+
value_start = offset + len(part) - len(value)
|
|
219
|
+
if key in BANNED_COSMETIC_PROPERTIES:
|
|
220
|
+
found.append(("NO_COSMETIC_SX", offset, f"{key}: {value[:60]}"))
|
|
221
|
+
elif key in SPACING_PROPERTIES:
|
|
222
|
+
problem = spacing_problem(value)
|
|
223
|
+
if problem:
|
|
224
|
+
found.append(("STANDARDIZED_SPACING", offset, f"{key}: {problem}"))
|
|
225
|
+
else:
|
|
226
|
+
walk_expression(code, value_start, offset + len(part), found)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def walk_expression(code: str, start: int, end: int, found: list) -> None:
|
|
230
|
+
for open_index, close_index in object_literals(code, start, end):
|
|
231
|
+
walk_object(code, open_index, close_index, found)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
# ---------------------------------------------------------------- JSX helpers
|
|
235
|
+
|
|
236
|
+
def jsx_tags(code: str):
|
|
237
|
+
"""Yield (name, start, end, attrs) for opening and self-closing JSX tags."""
|
|
238
|
+
for m in TAG_START.finditer(code):
|
|
239
|
+
i = m.start()
|
|
240
|
+
if i and (code[i - 1].isalnum() or code[i - 1] in "_$."):
|
|
241
|
+
continue
|
|
242
|
+
j, depth = m.end(), 0
|
|
243
|
+
while j < len(code) and j - i < 20000:
|
|
244
|
+
c = code[j]
|
|
245
|
+
if c in "\"'`":
|
|
246
|
+
j = skip_string(code, j)
|
|
247
|
+
continue
|
|
248
|
+
if c == "{":
|
|
249
|
+
depth += 1
|
|
250
|
+
elif c == "}":
|
|
251
|
+
depth -= 1
|
|
252
|
+
elif c == ">" and depth == 0:
|
|
253
|
+
break
|
|
254
|
+
elif c == ";" and depth == 0:
|
|
255
|
+
j = len(code)
|
|
256
|
+
break
|
|
257
|
+
j += 1
|
|
258
|
+
if j < len(code):
|
|
259
|
+
yield m.group(1), i, j, code[m.end():j]
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def blank_nested(text: str) -> str:
|
|
263
|
+
"""Blank string and {...} contents so only top-level attribute names stay visible."""
|
|
264
|
+
out, i = list(text), 0
|
|
265
|
+
while i < len(text):
|
|
266
|
+
if text[i] in "\"'`{":
|
|
267
|
+
close = skip_string(text, i) - 1 if text[i] != "{" else matching_close(text, i)
|
|
268
|
+
close = len(text) - 1 if close < 0 else close
|
|
269
|
+
for k in range(i + 1, close):
|
|
270
|
+
out[k] = " "
|
|
271
|
+
i = close
|
|
272
|
+
i += 1
|
|
273
|
+
return "".join(out)
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def attribute(attrs: str, name: str) -> tuple[int, str] | None:
|
|
277
|
+
"""(offset, value) of a JSX attribute; braces are stripped from {expr}."""
|
|
278
|
+
m = re.search(rf"(?<![\w$.-]){re.escape(name)}\s*=\s*", blank_nested(attrs))
|
|
279
|
+
if not m:
|
|
280
|
+
return None
|
|
281
|
+
k = m.end()
|
|
282
|
+
if attrs[k:k + 1] == "{":
|
|
283
|
+
close = matching_close(attrs, k)
|
|
284
|
+
return (k + 1, attrs[k + 1:close]) if close > 0 else None
|
|
285
|
+
if attrs[k:k + 1] in ("\"", "'"):
|
|
286
|
+
return k, attrs[k:skip_string(attrs, k)]
|
|
287
|
+
return None
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def check_jsx(code: str, found: list) -> None:
|
|
291
|
+
tags = list(jsx_tags(code))
|
|
292
|
+
events = [(start, "open", (name, end, attrs)) for name, start, end, attrs in tags]
|
|
293
|
+
events += [(m.start(), "close", m.group(1)) for m in CLOSE_TAG.finditer(code)]
|
|
294
|
+
stack: list[str] = []
|
|
295
|
+
for start, kind, item in sorted(events, key=lambda e: e[0]):
|
|
296
|
+
if kind == "close":
|
|
297
|
+
if item in stack:
|
|
298
|
+
del stack[len(stack) - 1 - stack[::-1].index(item):]
|
|
299
|
+
continue
|
|
300
|
+
name, end, attrs = item
|
|
301
|
+
if name in NON_MUI_ELEMENTS and (not stack or stack[-1] not in MUI_CONTAINERS):
|
|
302
|
+
parent = stack[-1] if stack else "no parent in this file"
|
|
303
|
+
found.append(("NON_MUI_CONTAINMENT", start, f"<{name}> inside <{parent}>; wrap it in <Paper variant=\"outlined\"> or <Card>"))
|
|
304
|
+
if name in SYSTEM_PROP_TAGS:
|
|
305
|
+
for prop in sorted(SPACING_ATTRIBUTES):
|
|
306
|
+
attr = attribute(attrs, prop)
|
|
307
|
+
problem = spacing_problem(attr[1]) if attr else None
|
|
308
|
+
if problem:
|
|
309
|
+
found.append(("STANDARDIZED_SPACING", start + len(name) + 1 + attr[0], f"<{name} {prop}>: {problem}"))
|
|
310
|
+
if name == "Stack":
|
|
311
|
+
for m_prop in ("m", "mt", "mb", "my", "mx", "ml", "mr"):
|
|
312
|
+
if attribute(attrs, m_prop):
|
|
313
|
+
found.append(("MARGIN_LEAKAGE", start, f"<Stack {m_prop}>: external margin on Stack; manage spacing on the parent container"))
|
|
314
|
+
sx_attr = attribute(attrs, "sx")
|
|
315
|
+
if sx_attr:
|
|
316
|
+
for m_prop in ("m", "mt", "mb", "my", "mx", "ml", "mr"):
|
|
317
|
+
if re.search(rf"(?<![\w$]){m_prop}\s*:", sx_attr[1]):
|
|
318
|
+
found.append(("MARGIN_LEAKAGE", start, f"<Stack sx.{{{m_prop}}}>: external margin on Stack; manage spacing on the parent container"))
|
|
319
|
+
if name == "Divider" and stack and stack[-1] == "Stack":
|
|
320
|
+
for m_prop in ("m", "mt", "mb", "my"):
|
|
321
|
+
if attribute(attrs, m_prop):
|
|
322
|
+
found.append(("MARGIN_LEAKAGE", start, f"<Divider {m_prop}>: vertical margin on Divider inside Stack; parent Stack spacing manages separation"))
|
|
323
|
+
sx_attr = attribute(attrs, "sx")
|
|
324
|
+
if sx_attr:
|
|
325
|
+
for m_prop in ("m", "mt", "mb", "my"):
|
|
326
|
+
if re.search(rf"(?<![\w$]){m_prop}\s*:", sx_attr[1]):
|
|
327
|
+
found.append(("MARGIN_LEAKAGE", start, f"<Divider sx.{{{m_prop}}}>: vertical margin on Divider inside Stack; parent Stack spacing manages separation"))
|
|
328
|
+
if not code[end - 1] == "/":
|
|
329
|
+
stack.append(name)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
# ---------------------------------------------------------------- entry points
|
|
333
|
+
|
|
334
|
+
def expression_end(code: str, i: int) -> int:
|
|
335
|
+
"""Index just past the expression starting at i (stops at a top-level , ; or closing bracket)."""
|
|
336
|
+
depth = 0
|
|
337
|
+
while i < len(code):
|
|
338
|
+
c = code[i]
|
|
339
|
+
if c in "\"'`":
|
|
340
|
+
i = skip_string(code, i)
|
|
341
|
+
continue
|
|
342
|
+
if c in "{([":
|
|
343
|
+
depth += 1
|
|
344
|
+
elif c in "})]":
|
|
345
|
+
if depth == 0:
|
|
346
|
+
return i
|
|
347
|
+
depth -= 1
|
|
348
|
+
elif c in ",;" and depth == 0:
|
|
349
|
+
return i
|
|
350
|
+
i += 1
|
|
351
|
+
return len(code)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def check_source(code: str, rel: str) -> list[tuple[str, int, str]]:
|
|
355
|
+
"""Return (rule, index, detail) for comment-blanked TS/TSX source outside src/tokens/."""
|
|
356
|
+
found: list = []
|
|
357
|
+
for m in STYLE_ATTR.finditer(code):
|
|
358
|
+
close = matching_close(code, m.end())
|
|
359
|
+
if close > 0:
|
|
360
|
+
walk_expression(code, m.end() + 1, close, found)
|
|
361
|
+
dictionaries = ANY_CONST if rel.endswith((".styles.ts", ".styles.tsx")) else STYLE_DICT
|
|
362
|
+
for pattern in (SX_PROPERTY, dictionaries):
|
|
363
|
+
for m in pattern.finditer(code):
|
|
364
|
+
walk_expression(code, m.end(), expression_end(code, m.end()), found)
|
|
365
|
+
for m in STYLED_CALL.finditer(code):
|
|
366
|
+
first_close = matching_close(code, m.end() - 1)
|
|
367
|
+
if first_close > 0 and code[first_close + 1:first_close + 2] == "(":
|
|
368
|
+
walk_expression(code, first_close + 1, matching_close(code, first_close + 1), found)
|
|
369
|
+
if rel.endswith(".tsx"):
|
|
370
|
+
check_jsx(code, found)
|
|
371
|
+
unique = {(rule, index): (rule, index, detail) for rule, index, detail in found}
|
|
372
|
+
return sorted(unique.values(), key=lambda v: v[1])
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def suppressed(raw: str, rule: str, line: int) -> bool:
|
|
376
|
+
for m in SUPPRESSION.finditer(raw):
|
|
377
|
+
if m.group(2) == rule and (m.group(1) or raw.count("\n", 0, m.start()) + 1 in (line, line - 1)):
|
|
378
|
+
return True
|
|
379
|
+
return False
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def source_files(root: Path):
|
|
383
|
+
if root.is_file():
|
|
384
|
+
yield root, root.name
|
|
385
|
+
return
|
|
386
|
+
scan = root / "src" if (root / "src").is_dir() else root
|
|
387
|
+
for dirpath, dirnames, filenames in os.walk(scan):
|
|
388
|
+
dirnames[:] = sorted(d for d in dirnames if d not in SKIP_DIRS and d != "tokens")
|
|
389
|
+
for name in sorted(filenames):
|
|
390
|
+
rel = (Path(dirpath) / name).relative_to(root).as_posix()
|
|
391
|
+
if name.endswith((".ts", ".tsx")) and not name.endswith(".d.ts") \
|
|
392
|
+
and not re.search(r"\.(test|spec)\.tsx?$|(^|/)__tests__/", rel):
|
|
393
|
+
yield Path(dirpath) / name, rel
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
def main(argv: list[str]) -> int:
|
|
397
|
+
root = Path(argv[0] if argv else ".")
|
|
398
|
+
if not root.exists():
|
|
399
|
+
print(f"path not found: {root}", file=sys.stderr)
|
|
400
|
+
return 2
|
|
401
|
+
violations = []
|
|
402
|
+
for path, rel in source_files(root):
|
|
403
|
+
raw = path.read_text(encoding="utf-8", errors="replace")
|
|
404
|
+
for rule, index, detail in check_source(blank_comments(raw), rel):
|
|
405
|
+
line = raw.count("\n", 0, index) + 1
|
|
406
|
+
if not suppressed(raw, rule, line):
|
|
407
|
+
violations.append(f"{rel}:{line} {rule} {detail}")
|
|
408
|
+
if violations:
|
|
409
|
+
print(f"FAIL Zero-Cosmetic-SX audit: {len(violations)} violation(s)")
|
|
410
|
+
print("\n".join(f" {v}" for v in violations))
|
|
411
|
+
print("fix: cosmetics -> src/tokens/muiTheme.ts styleOverrides (data-status for state); "
|
|
412
|
+
f"spacing -> grid steps {ALLOWED_SPACING_STEPS}; canvas/img/iframe -> <Paper variant=\"outlined\">.")
|
|
413
|
+
return 1
|
|
414
|
+
print("PASS Zero-Cosmetic-SX audit: layout-only sx, 8px-grid spacing, non-MUI elements contained.")
|
|
415
|
+
return 0
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
if __name__ == "__main__":
|
|
419
|
+
sys.exit(main(sys.argv[1:]))
|
|
@@ -8,6 +8,10 @@ import portalConfig from "./portalConfig.json";
|
|
|
8
8
|
* if a portal is configured. If disabled, maintains default standard unauthenticated behavior.
|
|
9
9
|
*/
|
|
10
10
|
export function initPortalAuth(): void {
|
|
11
|
+
if (process.env.NODE_ENV === "production") {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
if (!portalConfig || !portalConfig.enabled || !portalConfig.portal || !portalConfig.appId) {
|
|
12
16
|
return;
|
|
13
17
|
}
|
|
@@ -17,6 +21,19 @@ export function initPortalAuth(): void {
|
|
|
17
21
|
const portalVariants = Array.from(new Set([cleanPortalUrl, cleanPortalUrl.toLowerCase()]));
|
|
18
22
|
|
|
19
23
|
esriConfig.request.trustedServers = esriConfig.request.trustedServers ?? [];
|
|
24
|
+
|
|
25
|
+
// Also trust the portal host origin (ensures feature services at /server receive credentials/tokens)
|
|
26
|
+
try {
|
|
27
|
+
const portalOrigin = new URL(cleanPortalUrl).origin;
|
|
28
|
+
if (!esriConfig.request.trustedServers.includes(portalOrigin)) {
|
|
29
|
+
esriConfig.request.trustedServers.push(portalOrigin);
|
|
30
|
+
}
|
|
31
|
+
} catch {}
|
|
32
|
+
|
|
33
|
+
const callbackOrigin = typeof window !== "undefined" && window.location?.origin
|
|
34
|
+
? window.location.origin
|
|
35
|
+
: "https://localhost:3001";
|
|
36
|
+
|
|
20
37
|
for (const url of portalVariants) {
|
|
21
38
|
if (!esriConfig.request.trustedServers.includes(url)) {
|
|
22
39
|
esriConfig.request.trustedServers.push(url);
|
|
@@ -25,7 +42,7 @@ export function initPortalAuth(): void {
|
|
|
25
42
|
appId,
|
|
26
43
|
portalUrl: url,
|
|
27
44
|
popup: true,
|
|
28
|
-
popupCallbackUrl:
|
|
45
|
+
popupCallbackUrl: `${callbackOrigin}/oauth_callback.html`,
|
|
29
46
|
});
|
|
30
47
|
esriId.registerOAuthInfos([oauthInfo]);
|
|
31
48
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* Co-located component styles: namespaced classes only (for example .CustomWidget-body). The theme owns MUI chrome. */
|
|
@@ -1,70 +1,49 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { Card, CardContent, Paper, Stack, Typography } from "@mui/material";
|
|
3
3
|
import type { LayoutElementProperties } from "@vertigis/web/components";
|
|
4
4
|
import { LayoutElement } from "@vertigis/web/components";
|
|
5
|
-
import {
|
|
5
|
+
import { useWatchAndRerender } from "@vertigis/web/ui";
|
|
6
|
+
import { VertiGisThemeProvider } from "../../tokens/VertiGisThemeProvider";
|
|
6
7
|
import type { CustomWidgetModel } from "./CustomWidgetModel";
|
|
7
8
|
import { CustomWidgetErrorBoundary } from "./components/CustomWidgetErrorBoundary";
|
|
9
|
+
import "./CustomWidget.css";
|
|
8
10
|
|
|
9
11
|
export interface CustomWidgetProps extends LayoutElementProperties<CustomWidgetModel> {}
|
|
10
12
|
|
|
11
13
|
function CustomWidgetView(props: CustomWidgetProps): React.ReactElement {
|
|
12
14
|
const { model } = props;
|
|
15
|
+
useWatchAndRerender(model, "title");
|
|
13
16
|
|
|
14
17
|
return (
|
|
15
18
|
<LayoutElement {...props}>
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
>
|
|
33
|
-
|
|
34
|
-
</Typography>
|
|
35
|
-
|
|
36
|
-
<Typography
|
|
37
|
-
variant="subtitle2"
|
|
38
|
-
sx={{
|
|
39
|
-
color: tokens.ui.text.secondary,
|
|
40
|
-
fontFamily: tokens.typography.fontFamily.primary,
|
|
41
|
-
mb: 1.5,
|
|
42
|
-
}}
|
|
43
|
-
>
|
|
44
|
-
Enterprise VertiGIS Component Architecture
|
|
45
|
-
</Typography>
|
|
46
|
-
|
|
47
|
-
<Box
|
|
48
|
-
sx={{
|
|
49
|
-
p: 1.5,
|
|
50
|
-
backgroundColor: tokens.ui.surface.secondary,
|
|
51
|
-
border: `1px solid ${tokens.ui.border.secondary}`,
|
|
52
|
-
borderRadius: tokens.ui.shape.borderRadius,
|
|
53
|
-
}}
|
|
54
|
-
>
|
|
55
|
-
<Typography variant="body2" sx={{ color: tokens.ui.text.primary }}>
|
|
56
|
-
This widget demonstrates centralized tokens, safe fallbacks, and error boundary encapsulation.
|
|
57
|
-
</Typography>
|
|
58
|
-
</Box>
|
|
59
|
-
</Box>
|
|
19
|
+
<Card>
|
|
20
|
+
<CardContent>
|
|
21
|
+
<Stack spacing={1.5}>
|
|
22
|
+
<Stack spacing={0.5}>
|
|
23
|
+
<Typography variant="h6">{model.title}</Typography>
|
|
24
|
+
<Typography variant="subtitle2" color="text.secondary">
|
|
25
|
+
Enterprise VertiGIS Component Architecture
|
|
26
|
+
</Typography>
|
|
27
|
+
</Stack>
|
|
28
|
+
<Paper variant="outlined" sx={{ p: 1.5 }}>
|
|
29
|
+
<Typography variant="body2">
|
|
30
|
+
This widget demonstrates host-first theming: layout-only sx, 8px-grid spacing and
|
|
31
|
+
cosmetics centralised in src/tokens/muiTheme.ts.
|
|
32
|
+
</Typography>
|
|
33
|
+
</Paper>
|
|
34
|
+
</Stack>
|
|
35
|
+
</CardContent>
|
|
36
|
+
</Card>
|
|
60
37
|
</LayoutElement>
|
|
61
38
|
);
|
|
62
39
|
}
|
|
63
40
|
|
|
64
41
|
export default function CustomWidget(props: CustomWidgetProps): React.ReactElement {
|
|
65
42
|
return (
|
|
66
|
-
<
|
|
67
|
-
<
|
|
68
|
-
|
|
43
|
+
<VertiGisThemeProvider>
|
|
44
|
+
<CustomWidgetErrorBoundary>
|
|
45
|
+
<CustomWidgetView {...props} />
|
|
46
|
+
</CustomWidgetErrorBoundary>
|
|
47
|
+
</VertiGisThemeProvider>
|
|
69
48
|
);
|
|
70
49
|
}
|
|
File without changes
|
package/template-custom/src/components/CustomWidget/components/CustomWidgetErrorBoundary.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { Alert, AlertTitle, Button } from "@mui/material";
|
|
3
|
+
import "./CustomWidgetErrorBoundary.css";
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
6
|
children: React.ReactNode;
|
|
@@ -32,24 +32,17 @@ export class CustomWidgetErrorBoundary extends React.Component<Props, State> {
|
|
|
32
32
|
render(): React.ReactNode {
|
|
33
33
|
if (this.state.hasError) {
|
|
34
34
|
return (
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
35
|
+
<Alert
|
|
36
|
+
severity="error"
|
|
37
|
+
action={
|
|
38
|
+
<Button size="small" color="inherit" onClick={this.handleRetry}>
|
|
39
|
+
Retry
|
|
40
|
+
</Button>
|
|
41
|
+
}
|
|
42
42
|
>
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<Typography variant="caption" sx={{ color: tokens.ui.text.primary, display: "block", my: 1 }}>
|
|
47
|
-
{this.state.errorMessage}
|
|
48
|
-
</Typography>
|
|
49
|
-
<Button size="small" variant="outlined" onClick={this.handleRetry}>
|
|
50
|
-
Retry
|
|
51
|
-
</Button>
|
|
52
|
-
</Box>
|
|
43
|
+
<AlertTitle>Widget Display Error</AlertTitle>
|
|
44
|
+
{this.state.errorMessage}
|
|
45
|
+
</Alert>
|
|
53
46
|
);
|
|
54
47
|
}
|
|
55
48
|
return this.props.children;
|
|
@@ -3,7 +3,10 @@ import CustomWidget, { CustomWidgetModel } from "./components/CustomWidget";
|
|
|
3
3
|
import { initPortalAuth } from "./auth";
|
|
4
4
|
|
|
5
5
|
// Automatically initialize ArcGIS Enterprise Portal OAuth if configured via `npm run auth:portal`
|
|
6
|
-
|
|
6
|
+
// Guarded for development only: guest extension libraries must never register OAuth callbacks in production
|
|
7
|
+
if (process.env.NODE_ENV !== "production") {
|
|
8
|
+
initPortalAuth();
|
|
9
|
+
}
|
|
7
10
|
|
|
8
11
|
const LAYOUT_NAMESPACE = "custom.foo";
|
|
9
12
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ThemeProvider } from "@mui/material/styles";
|
|
3
|
+
|
|
4
|
+
import { useIsDarkTheme } from "../hooks/useIsDarkTheme";
|
|
5
|
+
import { createVertiGisTheme } from "./muiTheme";
|
|
6
|
+
|
|
7
|
+
/** Applies src/tokens/muiTheme.ts, following the shell's light/dark mode. */
|
|
8
|
+
export function VertiGisThemeProvider({ children }: { children: React.ReactNode }): React.ReactElement {
|
|
9
|
+
const isDark = useIsDarkTheme();
|
|
10
|
+
const theme = React.useMemo(() => createVertiGisTheme(isDark), [isDark]);
|
|
11
|
+
return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default VertiGisThemeProvider;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { UI_TOKENS } from "./ui";
|
|
2
2
|
import { TYPOGRAPHY_TOKENS } from "./typography";
|
|
3
|
+
import { SPACING } from "./spacing";
|
|
3
4
|
|
|
4
5
|
export { UI_TOKENS } from "./ui";
|
|
5
6
|
export { TYPOGRAPHY_TOKENS } from "./typography";
|
|
7
|
+
export { SPACING } from "./spacing";
|
|
6
8
|
|
|
7
9
|
export function alphaMix(token: string, opacityPercent: number): string {
|
|
8
10
|
const clamped = Math.max(0, Math.min(100, opacityPercent));
|
|
@@ -17,6 +19,7 @@ export function surfaceMix(fgToken: string, bgToken: string, weightPercent: numb
|
|
|
17
19
|
export const tokens = {
|
|
18
20
|
ui: UI_TOKENS,
|
|
19
21
|
typography: TYPOGRAPHY_TOKENS,
|
|
22
|
+
spacing: SPACING,
|
|
20
23
|
alphaMix,
|
|
21
24
|
surfaceMix,
|
|
22
25
|
};
|