@khsura/sui-mcp 0.1.0 → 0.3.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 +17 -6
- package/dist/guides/packages/app/docs/classes.md +1 -1
- package/dist/guides/plugins/sui-plugin/skills/sui-getting-started/SKILL.md +32 -7
- package/dist/index.js +697 -92
- package/dist/recipes/activator-overlays.md +1 -0
- package/dist/recipes/activator-overlays.vue +1 -1
- package/dist/recipes/app-shell.md +1 -1
- package/dist/recipes/centered-page.md +11 -0
- package/dist/recipes/centered-page.vue +44 -0
- package/dist/recipes/filter-bar.md +11 -0
- package/dist/recipes/filter-bar.vue +70 -0
- package/dist/recipes/responsive-grid.md +4 -1
- package/dist/recipes/responsive-grid.vue +37 -2
- package/dist/recipes/validated-form.md +6 -2
- package/dist/recipes/validated-form.vue +28 -8
- package/dist/sui-api.json +115 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -150,7 +150,8 @@ var FALLTHROUGH_ATTRIBUTES = [
|
|
|
150
150
|
"autofocus",
|
|
151
151
|
"placeholder",
|
|
152
152
|
"alt",
|
|
153
|
-
"src"
|
|
153
|
+
"src",
|
|
154
|
+
"novalidate"
|
|
154
155
|
];
|
|
155
156
|
/** A bound expression that is just a string literal (`:size="'small'"`), so its value is still known statically. */
|
|
156
157
|
var STRING_LITERAL_EXPRESSION = /^\s*(['"`])([^'"`$\\]*)\1\s*$/;
|
|
@@ -159,11 +160,28 @@ var RULE_LAYOUT_FOR = "layout-for";
|
|
|
159
160
|
var RULE_FORM_RULES_OUTSIDE_FORM = "form-rules-outside-form";
|
|
160
161
|
var RULE_ICON_BUTTON_LABEL = "icon-button-label";
|
|
161
162
|
var RULE_NO_RAW_REPLACEMENT = "no-raw-replacement";
|
|
163
|
+
var RULE_NATIVE_VALIDATION_IN_FORM = "native-validation-in-form";
|
|
164
|
+
var RULE_HIDE_DETAILS_HIDES_LABEL = "hide-details-hides-label";
|
|
165
|
+
var RULE_SNACKBAR_ACTION_CONTRAST = "snackbar-action-contrast";
|
|
166
|
+
var RULE_BLOCK_BUTTONS_IN_ROW = "block-buttons-in-row";
|
|
167
|
+
var RULE_CARD_TITLE_TEXT_ALIGN = "card-title-text-align";
|
|
168
|
+
var RULE_DATE_PICKER_EMPTY_STRING = "date-picker-empty-string";
|
|
169
|
+
var RULE_FIELD_BUTTON_ROW = "field-button-row";
|
|
170
|
+
var RULE_FILL_HEIGHT_UNDER_APP = "fill-height-under-app";
|
|
171
|
+
/**
|
|
172
|
+
* The first `@khsura/sui` release with the M2 hardening fixes (SForm `novalidate`, SCheckbox label with
|
|
173
|
+
* `hide-details`, `''` as "no date", snackbar action colour, SCardTitle `s_textAlign__*`). Rules for
|
|
174
|
+
* those behaviours set it as `fixedIn`, so they only warn for projects on an older version.
|
|
175
|
+
*/
|
|
176
|
+
var SUI_M2_FIXES_VERSION = "1.20.0";
|
|
162
177
|
var RULE_TARGET_ANY_ELEMENT = "any-element";
|
|
163
178
|
/** Recipe names an issue points to; the recipes are published under these exact names. */
|
|
164
179
|
var RECIPE_APP_SHELL = "app-shell";
|
|
165
180
|
var RECIPE_VALIDATED_FORM = "validated-form";
|
|
166
181
|
var RECIPE_ACTIVATOR_OVERLAYS = "activator-overlays";
|
|
182
|
+
var RECIPE_RESPONSIVE_GRID = "responsive-grid";
|
|
183
|
+
var RECIPE_FILTER_BAR = "filter-bar";
|
|
184
|
+
var RECIPE_CENTERED_PAGE = "centered-page";
|
|
167
185
|
var ACTIVATOR_SLOT_NAME = "activator";
|
|
168
186
|
var ACTIVATOR_ATTRS_KEY = "attrs";
|
|
169
187
|
/** Overlays whose `#activator` slot passes `{ on, attrs }` for the caller to bind. */
|
|
@@ -174,9 +192,13 @@ var SLOT_PROP_ACTIVATOR_COMPONENTS = [
|
|
|
174
192
|
];
|
|
175
193
|
/** STooltip wraps the activator in its own listening element and passes no slot props. */
|
|
176
194
|
var SLOTLESS_ACTIVATOR_COMPONENTS = ["STooltip"];
|
|
195
|
+
/** `height: 100%`; a direct child of SApp with it grows into SApp's flex column (since 1.20.0). */
|
|
196
|
+
var HEIGHT_FILL_CLASS = "s_height--fill";
|
|
177
197
|
var LAYOUT_COMPONENT = "SLayout";
|
|
178
198
|
var LAYOUT_NAME_ATTRIBUTE = "name";
|
|
199
|
+
var FORM_COMPONENT = "SForm";
|
|
179
200
|
var RULES_ATTRIBUTE = "rules";
|
|
201
|
+
var BUTTON_COMPONENT = "SButton";
|
|
180
202
|
var ACCESSIBLE_LABEL_ATTRIBUTES = [
|
|
181
203
|
"aria-label",
|
|
182
204
|
"aria-labelledby",
|
|
@@ -198,6 +220,67 @@ var RAW_INPUT_TYPE_REPLACEMENTS = /* @__PURE__ */ new Map([["checkbox", "SCheckb
|
|
|
198
220
|
/** A bare JavaScript identifier (`props` in `#activator="props"`). */
|
|
199
221
|
var IDENTIFIER_PATTERN = /^[A-Za-z_$][\w$]*$/;
|
|
200
222
|
var WHITESPACE_PATTERN = /\s+/g;
|
|
223
|
+
var NATIVE_VALIDATING_INPUT_TYPES = [
|
|
224
|
+
"email",
|
|
225
|
+
"url",
|
|
226
|
+
"number"
|
|
227
|
+
];
|
|
228
|
+
var HIDE_DETAILS_ATTRIBUTE = "hide-details";
|
|
229
|
+
/** Inputs whose only visible text is the `label` prop, which `hide-details` hides as well. */
|
|
230
|
+
var HIDE_DETAILS_LABEL_COMPONENTS = ["SCheckbox"];
|
|
231
|
+
var SNACKBAR_ACTION_SLOT_NAME = "action";
|
|
232
|
+
var COLOR_ATTRIBUTE = "color";
|
|
233
|
+
var VARIANT_ATTRIBUTE = "variant";
|
|
234
|
+
/** Action variants that, before the M2 fix, kept the page's dark text colour on the dark snackbar when no `color` was set. */
|
|
235
|
+
var SNACKBAR_UNCOLOURED_ACTION_VARIANTS = ["text", "icon"];
|
|
236
|
+
/**
|
|
237
|
+
* Preset colours below 4.5:1 as text on the default `#424242` snackbar before `SUI_M2_FIXES_VERSION` (primary is
|
|
238
|
+
* 2.18:1). From that version a preset text colour inside the snackbar uses a variant tuned to the snackbar.
|
|
239
|
+
*/
|
|
240
|
+
var SNACKBAR_UNREADABLE_PRESET_COLORS = [
|
|
241
|
+
"primary",
|
|
242
|
+
"secondary",
|
|
243
|
+
"success",
|
|
244
|
+
"info",
|
|
245
|
+
"error"
|
|
246
|
+
];
|
|
247
|
+
/** The theme's default `snackbar` colour, dark in both themes: CSS-colour actions are measured against it. */
|
|
248
|
+
var SNACKBAR_DEFAULT_BACKGROUND = "#424242";
|
|
249
|
+
var SNACKBAR_LIGHT_ACTION_COLOR_HINT = `\`color="warning"\` or a CSS colour such as \`color="#ffffff"\``;
|
|
250
|
+
/** Components whose root is a `display: flex` row. */
|
|
251
|
+
var FLEX_ROW_COMPONENTS = ["SCardActions"];
|
|
252
|
+
/** Text fields that render a label above their box and an error line under it. */
|
|
253
|
+
var LABELLED_FIELD_COMPONENTS = [
|
|
254
|
+
"SInput",
|
|
255
|
+
"SSelect",
|
|
256
|
+
"SDatePickerInput",
|
|
257
|
+
"SAutocomplete",
|
|
258
|
+
"STextarea"
|
|
259
|
+
];
|
|
260
|
+
/** `s_display__flex`, `s_display--md__inlineFlex`: the utility classes that make an element a flex row. */
|
|
261
|
+
var FLEX_DISPLAY_CLASS_PATTERN = /^s_display(?:--[a-z]+)?__(?:flex|inlineFlex)$/;
|
|
262
|
+
var FLEX_DISPLAY_STYLE_PATTERN = /(?:^|;)\s*display\s*:\s*(?:inline-)?flex\b/;
|
|
263
|
+
/** `s_textAlign__center`, `s_textAlign--md__center`. */
|
|
264
|
+
var TEXT_ALIGN_CLASS_PATTERN = /^s_textAlign(?:--[a-z]+)?__([a-z]+)$/;
|
|
265
|
+
/** The `justify` utility for each text-align value, which does centre a flex container's content. */
|
|
266
|
+
var TEXT_ALIGN_JUSTIFY_CLASSES = /* @__PURE__ */ new Map([
|
|
267
|
+
["left", "s_justify__start"],
|
|
268
|
+
["start", "s_justify__start"],
|
|
269
|
+
["center", "s_justify__center"],
|
|
270
|
+
["right", "s_justify__end"],
|
|
271
|
+
["end", "s_justify__end"]
|
|
272
|
+
]);
|
|
273
|
+
var DATE_PICKER_EMPTY_STRING_COMPONENTS = ["SDatePickerInput"];
|
|
274
|
+
/** `''` or `""` as a whole expression. */
|
|
275
|
+
var EMPTY_STRING_EXPRESSION = /^\s*(['"])\1\s*$/;
|
|
276
|
+
/** A dotted model path (`draft.from`, `startDate`) whose last segment can be looked up in the script. */
|
|
277
|
+
var MODEL_PATH_PATTERN = /^\s*[A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*)*\s*$/;
|
|
278
|
+
var MODEL_PATH_SEPARATOR = /\??\./;
|
|
279
|
+
var REGEX_SPECIAL_CHARACTERS = /[$]/g;
|
|
280
|
+
/** Placeholder in the script patterns below, replaced by the model's last path segment. */
|
|
281
|
+
var MODEL_NAME_PLACEHOLDER = "__name__";
|
|
282
|
+
/** `from: ''` in an object literal, or `startDate = ref('')` / `ref<string>("")`. */
|
|
283
|
+
var EMPTY_STRING_INITIAL_PATTERNS = [`(?:^|[^\\w$.])${MODEL_NAME_PLACEHOLDER}\\s*:\\s*(['"])\\1`, `(?:^|[^\\w$.])${MODEL_NAME_PLACEHOLDER}\\s*=\\s*(?:ref|shallowRef)\\s*(?:<[^>]*>)?\\s*\\(\\s*(['"])\\1\\s*\\)`];
|
|
201
284
|
var ACTIVATOR_BINDING_FIX = "Write `#activator=\"{ on, attrs }\"` and put both `v-on=\"on\"` and `v-bind=\"attrs\"` on the activator's root element.";
|
|
202
285
|
//#endregion
|
|
203
286
|
//#region src/constants/recipes.ts
|
|
@@ -208,7 +291,9 @@ var RECIPE_NAMES = [
|
|
|
208
291
|
"activator-overlays",
|
|
209
292
|
"data-table",
|
|
210
293
|
"responsive-grid",
|
|
211
|
-
"theme-setup"
|
|
294
|
+
"theme-setup",
|
|
295
|
+
"filter-bar",
|
|
296
|
+
"centered-page"
|
|
212
297
|
];
|
|
213
298
|
var RECIPES_DIRNAME = "recipes";
|
|
214
299
|
/** Repo-relative folder that holds the recipe sources (Storybook renders the same files). */
|
|
@@ -261,6 +346,194 @@ var CONFIG_STATUS_UPDATED = "updated";
|
|
|
261
346
|
var CONFIG_STATUS_UNCHANGED = "unchanged";
|
|
262
347
|
var CONFIG_ACTION_WRITE = "write";
|
|
263
348
|
var CONFIG_ACTION_PRINT = "print";
|
|
349
|
+
/**
|
|
350
|
+
* Component names from Vuetify, Quasar, Element and similar libraries that are not in @khsura/sui,
|
|
351
|
+
* with the SUI component(s) to use instead and a short hint. An empty `suiNames` means SUI has no
|
|
352
|
+
* equivalent yet. Keys are matched like component names (case, `-` and the `S` prefix are ignored),
|
|
353
|
+
* and an alias is never used when the name is a real component in the resolved `sui-api.json`.
|
|
354
|
+
*/
|
|
355
|
+
var COMPONENT_ALIASES = {
|
|
356
|
+
SCol: {
|
|
357
|
+
suiNames: ["SColumn"],
|
|
358
|
+
hint: "The grid column is `SColumn`, inside an `SRow` (`:cols`, `:md`, … set its width)."
|
|
359
|
+
},
|
|
360
|
+
SCols: {
|
|
361
|
+
suiNames: ["SColumn"],
|
|
362
|
+
hint: "The grid column is `SColumn`, inside an `SRow`."
|
|
363
|
+
},
|
|
364
|
+
SColumns: {
|
|
365
|
+
suiNames: ["SColumn"],
|
|
366
|
+
hint: "The grid column is `SColumn`, one per column, inside an `SRow`."
|
|
367
|
+
},
|
|
368
|
+
STextField: {
|
|
369
|
+
suiNames: ["SInput"],
|
|
370
|
+
hint: "The text field is `SInput` (`label`, `type`, `rules`, `v-model`)."
|
|
371
|
+
},
|
|
372
|
+
STextInput: {
|
|
373
|
+
suiNames: ["SInput"],
|
|
374
|
+
hint: "The text field is `SInput` (`label`, `type`, `rules`, `v-model`)."
|
|
375
|
+
},
|
|
376
|
+
SInputText: {
|
|
377
|
+
suiNames: ["SInput"],
|
|
378
|
+
hint: "The text field is `SInput`."
|
|
379
|
+
},
|
|
380
|
+
SBtn: {
|
|
381
|
+
suiNames: ["SButton"],
|
|
382
|
+
hint: "The button is `SButton` (`variant`, `color`, `size`)."
|
|
383
|
+
},
|
|
384
|
+
SIconButton: {
|
|
385
|
+
suiNames: ["SButton"],
|
|
386
|
+
hint: "An icon-only button is `<SButton variant=\"icon\" aria-label=\"…\">` with an `SIcon` inside."
|
|
387
|
+
},
|
|
388
|
+
SBtnToggle: {
|
|
389
|
+
suiNames: ["SToggleButtonGroup", "SToggleButton"],
|
|
390
|
+
hint: "Use `SToggleButtonGroup` with `SToggleButton` children."
|
|
391
|
+
},
|
|
392
|
+
SDataTable: {
|
|
393
|
+
suiNames: ["STable"],
|
|
394
|
+
hint: "The data table is `STable` (`headers`, `items`, `item.<key>` slots)."
|
|
395
|
+
},
|
|
396
|
+
SSimpleTable: {
|
|
397
|
+
suiNames: ["STable"],
|
|
398
|
+
hint: "The table is `STable`."
|
|
399
|
+
},
|
|
400
|
+
STabsWindow: {
|
|
401
|
+
suiNames: ["SWindow"],
|
|
402
|
+
hint: "Tab content is an `SWindow` bound to the same `v-model` as `STabs`, with one `SWindowItem` per tab."
|
|
403
|
+
},
|
|
404
|
+
STabsWindowItem: {
|
|
405
|
+
suiNames: ["SWindowItem"],
|
|
406
|
+
hint: "Each tab panel is an `SWindowItem` inside an `SWindow`."
|
|
407
|
+
},
|
|
408
|
+
STabsItems: {
|
|
409
|
+
suiNames: ["SWindow"],
|
|
410
|
+
hint: "Tab content is an `SWindow` bound to the same `v-model` as `STabs`."
|
|
411
|
+
},
|
|
412
|
+
STabItem: {
|
|
413
|
+
suiNames: ["SWindowItem"],
|
|
414
|
+
hint: "Each tab panel is an `SWindowItem` inside an `SWindow`; the tab itself is `STab`."
|
|
415
|
+
},
|
|
416
|
+
STabPanels: {
|
|
417
|
+
suiNames: ["SWindow"],
|
|
418
|
+
hint: "Tab content is an `SWindow` bound to the same `v-model` as `STabs`."
|
|
419
|
+
},
|
|
420
|
+
STabPanel: {
|
|
421
|
+
suiNames: ["SWindowItem"],
|
|
422
|
+
hint: "Each tab panel is an `SWindowItem` inside an `SWindow`."
|
|
423
|
+
},
|
|
424
|
+
STabPane: {
|
|
425
|
+
suiNames: ["STab", "SWindowItem"],
|
|
426
|
+
hint: "Put an `STab` in `STabs` and its content in an `SWindowItem` inside an `SWindow`."
|
|
427
|
+
},
|
|
428
|
+
SAvatar: {
|
|
429
|
+
suiNames: [],
|
|
430
|
+
hint: "There is no avatar component yet (planned for M3). For a photo use `<SImage src=\"…\" :aspect-ratio=\"1\" object-fit=\"cover\" :width=\"40\" style=\"border-radius: 50%\" />`; for initials use a fixed-size element with `border-radius: 50%`, a background colour and centred text."
|
|
431
|
+
},
|
|
432
|
+
SModal: {
|
|
433
|
+
suiNames: ["SDialog"],
|
|
434
|
+
hint: "The modal is `SDialog`, opened from its `#activator` slot or a `v-model`."
|
|
435
|
+
},
|
|
436
|
+
SDrawer: {
|
|
437
|
+
suiNames: ["SNavigationDrawer"],
|
|
438
|
+
hint: "The side drawer is `SNavigationDrawer`, a child of `SLayout`."
|
|
439
|
+
},
|
|
440
|
+
SHeader: {
|
|
441
|
+
suiNames: ["SAppBar"],
|
|
442
|
+
hint: "The page header bar is `SAppBar`, a child of `SLayout`."
|
|
443
|
+
},
|
|
444
|
+
SPage: {
|
|
445
|
+
suiNames: ["SMain"],
|
|
446
|
+
hint: "The page content area is `SMain`, a child of `SLayout`."
|
|
447
|
+
},
|
|
448
|
+
SContent: {
|
|
449
|
+
suiNames: ["SMain"],
|
|
450
|
+
hint: "The page content area is `SMain`, a child of `SLayout`."
|
|
451
|
+
},
|
|
452
|
+
SToast: {
|
|
453
|
+
suiNames: ["SSnackbar"],
|
|
454
|
+
hint: "The toast is `SSnackbar` (`v-model`, `timeout`, `#action` slot)."
|
|
455
|
+
},
|
|
456
|
+
SNotification: {
|
|
457
|
+
suiNames: ["SSnackbar"],
|
|
458
|
+
hint: "A transient message is `SSnackbar`; a static one is `SAlert`."
|
|
459
|
+
},
|
|
460
|
+
SDropdown: {
|
|
461
|
+
suiNames: ["SMenu"],
|
|
462
|
+
hint: "The dropdown is `SMenu`, opened from its `#activator` slot."
|
|
463
|
+
},
|
|
464
|
+
SSpinner: {
|
|
465
|
+
suiNames: ["SProgressCircular"],
|
|
466
|
+
hint: "The spinner is `<SProgressCircular indeterminate />`."
|
|
467
|
+
},
|
|
468
|
+
SProgressBar: {
|
|
469
|
+
suiNames: ["SProgressLinear"],
|
|
470
|
+
hint: "The progress bar is `SProgressLinear`."
|
|
471
|
+
},
|
|
472
|
+
SToggle: {
|
|
473
|
+
suiNames: ["SSwitch"],
|
|
474
|
+
hint: "The on/off toggle is `SSwitch`."
|
|
475
|
+
},
|
|
476
|
+
SCombobox: {
|
|
477
|
+
suiNames: ["SAutocomplete"],
|
|
478
|
+
hint: "A searchable select is `SAutocomplete`."
|
|
479
|
+
},
|
|
480
|
+
SImg: {
|
|
481
|
+
suiNames: ["SImage"],
|
|
482
|
+
hint: "The image is `SImage`."
|
|
483
|
+
},
|
|
484
|
+
SCardHeader: {
|
|
485
|
+
suiNames: ["SCardTitle"],
|
|
486
|
+
hint: "The card heading is `SCardTitle` (with `SCardSubtitle` below it)."
|
|
487
|
+
},
|
|
488
|
+
SCardBody: {
|
|
489
|
+
suiNames: ["SCardText"],
|
|
490
|
+
hint: "The card body is `SCardText`."
|
|
491
|
+
},
|
|
492
|
+
SCardContent: {
|
|
493
|
+
suiNames: ["SCardText"],
|
|
494
|
+
hint: "The card body is `SCardText`."
|
|
495
|
+
},
|
|
496
|
+
SCardSection: {
|
|
497
|
+
suiNames: ["SCardText"],
|
|
498
|
+
hint: "The card body is `SCardText`."
|
|
499
|
+
},
|
|
500
|
+
SCardFooter: {
|
|
501
|
+
suiNames: ["SCardActions"],
|
|
502
|
+
hint: "The card footer with buttons is `SCardActions`."
|
|
503
|
+
},
|
|
504
|
+
SExpansionPanelTitle: {
|
|
505
|
+
suiNames: ["SExpansionPanelHeader"],
|
|
506
|
+
hint: "The clickable row of a panel is `SExpansionPanelHeader`."
|
|
507
|
+
},
|
|
508
|
+
SExpansionPanelText: {
|
|
509
|
+
suiNames: ["SExpansionPanelContent"],
|
|
510
|
+
hint: "The body of a panel is `SExpansionPanelContent`."
|
|
511
|
+
},
|
|
512
|
+
SAccordion: {
|
|
513
|
+
suiNames: ["SExpansionPanels"],
|
|
514
|
+
hint: "The accordion is `SExpansionPanels` with `SExpansionPanel` children."
|
|
515
|
+
},
|
|
516
|
+
SStepperItem: {
|
|
517
|
+
suiNames: ["SStepperStep"],
|
|
518
|
+
hint: "Each step is an `SStepperStep` inside `SStepper`."
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/constants/semver.ts
|
|
523
|
+
/** `1.20.0`, `v1.20.0`, `1.20.0-beta.1`: major, minor, patch and an optional pre-release tag. */
|
|
524
|
+
var SEMVER_PATTERN = /^\s*v?(\d+)\.(\d+)\.(\d+)(?:-([\w.-]+))?(?:\+[\w.-]+)?\s*$/;
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/constants/contrast.ts
|
|
527
|
+
/** `#rgb` or `#rrggbb` (case-insensitive): the hex digits. */
|
|
528
|
+
var HEX_COLOR_PATTERN = /^#([\da-f]{3}|[\da-f]{6})$/i;
|
|
529
|
+
var SRGB_LINEAR_DIVISOR = 12.92;
|
|
530
|
+
var SRGB_GAMMA_OFFSET = .055;
|
|
531
|
+
var SRGB_GAMMA_DIVISOR = 1.055;
|
|
532
|
+
var SRGB_GAMMA = 2.4;
|
|
533
|
+
var LUMINANCE_WEIGHT_RED = .2126;
|
|
534
|
+
var LUMINANCE_WEIGHT_GREEN = .7152;
|
|
535
|
+
var LUMINANCE_WEIGHT_BLUE = .0722;
|
|
536
|
+
var CONTRAST_FLARE = .05;
|
|
264
537
|
//#endregion
|
|
265
538
|
//#region src/schemas/componentTools.schema.ts
|
|
266
539
|
var getComponentApiInputSchema = z.object({ name: z.string().trim().min(1).describe("Component name: `SButton`, `s-button` or `button` (case-insensitive).") });
|
|
@@ -371,14 +644,19 @@ var toParseError = (error) => {
|
|
|
371
644
|
*/
|
|
372
645
|
var parseVueTemplate = (source) => {
|
|
373
646
|
const { descriptor, errors: sfcErrors } = parse$1(source);
|
|
374
|
-
if (Boolean(descriptor.template ?? descriptor.script ?? descriptor.scriptSetup))
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
647
|
+
if (Boolean(descriptor.template ?? descriptor.script ?? descriptor.scriptSetup)) {
|
|
648
|
+
const scriptSource = [descriptor.script, descriptor.scriptSetup].map((block) => block?.content ?? "").join("\n");
|
|
649
|
+
return {
|
|
650
|
+
root: descriptor.template?.ast ?? null,
|
|
651
|
+
errors: sfcErrors.map(toParseError),
|
|
652
|
+
scriptSource
|
|
653
|
+
};
|
|
654
|
+
}
|
|
378
655
|
const fragmentErrors = [];
|
|
379
656
|
return {
|
|
380
657
|
root: parse(source, { onError: (error) => fragmentErrors.push(toParseError(error)) }),
|
|
381
|
-
errors: fragmentErrors
|
|
658
|
+
errors: fragmentErrors,
|
|
659
|
+
scriptSource: ""
|
|
382
660
|
};
|
|
383
661
|
};
|
|
384
662
|
//#endregion
|
|
@@ -489,6 +767,156 @@ var mergeMcpServerEntry = ({ existingText, serversKey, entryName, entry }) => {
|
|
|
489
767
|
/** The snippet a user pastes into a config file they edit by hand. */
|
|
490
768
|
var mcpServerSnippet = ({ serversKey, entryName, entry }) => serializeJson({ [serversKey]: { [entryName]: entry } });
|
|
491
769
|
//#endregion
|
|
770
|
+
//#region src/lib/semver.ts
|
|
771
|
+
var parseVersion = (version) => {
|
|
772
|
+
const match = SEMVER_PATTERN.exec(version);
|
|
773
|
+
if (!match) return;
|
|
774
|
+
const [, major, minor, patch, preRelease] = match;
|
|
775
|
+
return {
|
|
776
|
+
core: [
|
|
777
|
+
Number(major),
|
|
778
|
+
Number(minor),
|
|
779
|
+
Number(patch)
|
|
780
|
+
],
|
|
781
|
+
preRelease
|
|
782
|
+
};
|
|
783
|
+
};
|
|
784
|
+
/**
|
|
785
|
+
* Orders two semver strings: negative when `left` is older, positive when newer, 0 when equal.
|
|
786
|
+
* A pre-release sorts before its release (`1.20.0-beta.1` < `1.20.0`); pre-release tags compare as text.
|
|
787
|
+
* Returns `undefined` when either string is not a semver version.
|
|
788
|
+
*/
|
|
789
|
+
var compareVersions = (left, right) => {
|
|
790
|
+
const leftVersion = parseVersion(left);
|
|
791
|
+
const rightVersion = parseVersion(right);
|
|
792
|
+
if (!leftVersion || !rightVersion) return;
|
|
793
|
+
const coreDifference = leftVersion.core.map((part, index) => part - rightVersion.core[index]).find((difference) => difference !== 0);
|
|
794
|
+
if (coreDifference !== void 0) return coreDifference;
|
|
795
|
+
if (leftVersion.preRelease === rightVersion.preRelease) return 0;
|
|
796
|
+
if (leftVersion.preRelease === void 0 || rightVersion.preRelease === void 0) return leftVersion.preRelease === void 0 ? 1 : -1;
|
|
797
|
+
return leftVersion.preRelease.localeCompare(rightVersion.preRelease);
|
|
798
|
+
};
|
|
799
|
+
/** True when `version` is `minimum` or newer; false when either is not a semver version. */
|
|
800
|
+
var isVersionAtLeast = (version, minimum) => (compareVersions(version, minimum) ?? -1) >= 0;
|
|
801
|
+
//#endregion
|
|
802
|
+
//#region src/lib/contrast.ts
|
|
803
|
+
/** `#rgb` / `#rrggbb` as `[r, g, b]` (0-255), or `undefined` for anything else (named colours, `rgb()`, bindings). */
|
|
804
|
+
var parseHexColor = (color) => {
|
|
805
|
+
const match = HEX_COLOR_PATTERN.exec(color.trim());
|
|
806
|
+
if (!match) return;
|
|
807
|
+
const [red, green, blue] = (match[1].length === 3 ? [...match[1]].map((digit) => digit + digit) : [
|
|
808
|
+
match[1].slice(0, 2),
|
|
809
|
+
match[1].slice(2, 4),
|
|
810
|
+
match[1].slice(4, 6)
|
|
811
|
+
]).map((pair) => Number.parseInt(pair, 16));
|
|
812
|
+
return [
|
|
813
|
+
red,
|
|
814
|
+
green,
|
|
815
|
+
blue
|
|
816
|
+
];
|
|
817
|
+
};
|
|
818
|
+
var linearizeChannel = (channel) => {
|
|
819
|
+
const ratio = channel / 255;
|
|
820
|
+
return ratio <= .04045 ? ratio / SRGB_LINEAR_DIVISOR : ((ratio + SRGB_GAMMA_OFFSET) / SRGB_GAMMA_DIVISOR) ** SRGB_GAMMA;
|
|
821
|
+
};
|
|
822
|
+
var relativeLuminance = ([red, green, blue]) => LUMINANCE_WEIGHT_RED * linearizeChannel(red) + LUMINANCE_WEIGHT_GREEN * linearizeChannel(green) + LUMINANCE_WEIGHT_BLUE * linearizeChannel(blue);
|
|
823
|
+
/** WCAG 2.x contrast ratio (1 to 21) between two hex colours, or `undefined` when either is not `#rgb`/`#rrggbb`. */
|
|
824
|
+
var getHexContrastRatio = (first, second) => {
|
|
825
|
+
const firstRgb = parseHexColor(first);
|
|
826
|
+
const secondRgb = parseHexColor(second);
|
|
827
|
+
if (!firstRgb || !secondRgb) return;
|
|
828
|
+
const firstLuminance = relativeLuminance(firstRgb);
|
|
829
|
+
const secondLuminance = relativeLuminance(secondRgb);
|
|
830
|
+
return (Math.max(firstLuminance, secondLuminance) + CONTRAST_FLARE) / (Math.min(firstLuminance, secondLuminance) + CONTRAST_FLARE);
|
|
831
|
+
};
|
|
832
|
+
//#endregion
|
|
833
|
+
//#region src/utils/componentName.ts
|
|
834
|
+
var NAME_SEPARATORS = /[\s_-]/g;
|
|
835
|
+
/** Lowercase key with separators removed: `SButton`, `s-button` and `sbutton` all map to `sbutton`. */
|
|
836
|
+
var toComponentKey = (name) => name.trim().toLowerCase().replaceAll(NAME_SEPARATORS, "");
|
|
837
|
+
/** Keys a query may refer to, most specific first: as typed, then with the `S` prefix added. */
|
|
838
|
+
var candidateComponentKeys = (query) => {
|
|
839
|
+
const queryKey = toComponentKey(query);
|
|
840
|
+
return [queryKey, `s${queryKey}`];
|
|
841
|
+
};
|
|
842
|
+
/** `SNavigationDrawer` → `Navigation drawer`. */
|
|
843
|
+
var humanizeComponentName = (name) => {
|
|
844
|
+
const sentence = name.replace(/^S(?=[A-Z])/, "").split(/(?=[A-Z])/).map((word) => word.toLowerCase()).join(" ");
|
|
845
|
+
return sentence.charAt(0).toUpperCase() + sentence.slice(1);
|
|
846
|
+
};
|
|
847
|
+
/** True for tags the validator treats as SUI components: `SButton` or `s-button`. Native tags such as `select` never match. */
|
|
848
|
+
var isSuiComponentTag = (tag) => SUI_PASCAL_TAG_PATTERN.test(tag) || SUI_KEBAB_TAG_PATTERN.test(tag);
|
|
849
|
+
//#endregion
|
|
850
|
+
//#region src/utils/templateAst.ts
|
|
851
|
+
var positionOf = (node) => ({
|
|
852
|
+
line: node.loc.start.line,
|
|
853
|
+
column: node.loc.start.column
|
|
854
|
+
});
|
|
855
|
+
var codeList = (names) => names.map((name) => `\`${name}\``).join(", ");
|
|
856
|
+
/** The argument of a directive when it is a static name (`:size`, `#header`); `undefined` for none or `[dynamic]`. */
|
|
857
|
+
var staticArgument = (argument) => argument?.type === NodeTypes.SIMPLE_EXPRESSION && argument.isStatic ? argument.content : void 0;
|
|
858
|
+
/** The source of a directive's value (`on` in `v-on="on"`), trimmed; `undefined` when it has none. */
|
|
859
|
+
var expressionSource = (directive) => {
|
|
860
|
+
const source = directive.exp?.loc.source.trim() ?? "";
|
|
861
|
+
return source.length ? source : void 0;
|
|
862
|
+
};
|
|
863
|
+
var isDirective = (prop) => prop.type === NodeTypes.DIRECTIVE;
|
|
864
|
+
/** True when `tag` names `componentName` in either case style: `SAppBar`, `s-app-bar`. */
|
|
865
|
+
var isComponentTag = (tag, componentName) => toComponentKey(tag) === toComponentKey(componentName);
|
|
866
|
+
var isOneOfComponentTags = (tag, componentNames) => componentNames.some((componentName) => isComponentTag(tag, componentName));
|
|
867
|
+
var childElementsOf = (element) => element.children.filter((child) => child.type === NodeTypes.ELEMENT);
|
|
868
|
+
/** `name="x"` or `:name="x"` / `v-bind:name="x"` on `element`; a quoted literal binding still has a static value. */
|
|
869
|
+
var findAttribute = (element, name) => {
|
|
870
|
+
for (const prop of element.props) {
|
|
871
|
+
if (!isDirective(prop)) {
|
|
872
|
+
if (prop.name === name) return {
|
|
873
|
+
node: prop,
|
|
874
|
+
staticValue: prop.value?.content,
|
|
875
|
+
isBound: false
|
|
876
|
+
};
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
if (prop.name === "bind" && staticArgument(prop.arg) === name) {
|
|
880
|
+
const literal = STRING_LITERAL_EXPRESSION.exec(expressionSource(prop) ?? "");
|
|
881
|
+
return {
|
|
882
|
+
node: prop,
|
|
883
|
+
staticValue: literal?.[2],
|
|
884
|
+
isBound: !literal
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
/** `v-bind="object"`: it may carry any attribute, so presence checks cannot be sure. */
|
|
890
|
+
var hasObjectSpread = (element) => element.props.some((prop) => isDirective(prop) && prop.name === "bind" && !prop.arg);
|
|
891
|
+
/** Slots `element` fills: `v-slot` / `#name` on the element itself or on its direct `<template>` children. */
|
|
892
|
+
var slotFills = (element) => {
|
|
893
|
+
return [element, ...childElementsOf(element).filter((child) => child.tag === TEMPLATE_TAG)].flatMap((owner) => owner.props.filter(isDirective).filter((directive) => directive.name === DIRECTIVE_SLOT).map((directive) => ({
|
|
894
|
+
directive,
|
|
895
|
+
owner
|
|
896
|
+
})));
|
|
897
|
+
};
|
|
898
|
+
var slotDirectives = (element) => slotFills(element).map((fill) => fill.directive);
|
|
899
|
+
/** Every element below `element`, depth first. */
|
|
900
|
+
var descendantElementsOf = (element) => childElementsOf(element).flatMap((child) => [child, ...descendantElementsOf(child)]);
|
|
901
|
+
/** A prop written in either case style: `hide-details`, `hideDetails`, `:hide-details`. */
|
|
902
|
+
var findPropAttribute = (element, kebabName) => findAttribute(element, kebabName) ?? findAttribute(element, toCamelCase(kebabName));
|
|
903
|
+
/** A boolean prop that is set and not statically `false` (`block`, `:block="true"`, `:block="isWide"`). */
|
|
904
|
+
var isBooleanPropOn = (element, kebabName) => {
|
|
905
|
+
const attribute = findPropAttribute(element, kebabName);
|
|
906
|
+
if (!attribute) return false;
|
|
907
|
+
return !isDirective(attribute.node) || expressionSource(attribute.node) !== "false";
|
|
908
|
+
};
|
|
909
|
+
/** The static `class` tokens of `element` (a plain `class` or a string-literal `:class`); bound classes are unknown. */
|
|
910
|
+
var staticClassNames = (element) => element.props.flatMap((prop) => {
|
|
911
|
+
if (!isDirective(prop)) return prop.name === "class" ? [prop.value?.content ?? ""] : [];
|
|
912
|
+
const literal = prop.name === "bind" && staticArgument(prop.arg) === "class" ? STRING_LITERAL_EXPRESSION.exec(expressionSource(prop) ?? "") : null;
|
|
913
|
+
return literal ? [literal[2]] : [];
|
|
914
|
+
}).flatMap((value) => value.split(WHITESPACE_PATTERN)).filter(Boolean);
|
|
915
|
+
//#endregion
|
|
916
|
+
//#region src/utils/componentAliasMarkdown.ts
|
|
917
|
+
/** `SUI equivalent: \`SColumn\`. <hint>`, or just the hint when SUI has no equivalent yet. */
|
|
918
|
+
var formatComponentAlias = (alias) => alias.suiNames.length ? `SUI equivalent: ${codeList(alias.suiNames)}. ${alias.hint}` : alias.hint;
|
|
919
|
+
//#endregion
|
|
492
920
|
//#region src/utils/componentMarkdown.ts
|
|
493
921
|
var OPTIONAL_TYPE_SUFFIX = / \| undefined$/;
|
|
494
922
|
var EMPTY_CELL = "—";
|
|
@@ -577,8 +1005,19 @@ var formatComponentApi = (resolved, component) => [
|
|
|
577
1005
|
"",
|
|
578
1006
|
formatNamedTypes(component.events, "Payload")
|
|
579
1007
|
].join("\n");
|
|
580
|
-
|
|
581
|
-
|
|
1008
|
+
/** An unknown name: the other-library alias mapping first (when there is one), then the closest names. */
|
|
1009
|
+
var formatUnknownComponent = (resolved, query, suggestions, alias) => {
|
|
1010
|
+
const suggestionText = suggestions.map(inlineCode).join(", ");
|
|
1011
|
+
const listHint = `Call ${inlineCode(LIST_COMPONENTS_TOOL_NAME)} to see every component.`;
|
|
1012
|
+
if (alias) {
|
|
1013
|
+
const otherNames = suggestions.length ? ` Other close names: ${suggestionText}.` : "";
|
|
1014
|
+
return [
|
|
1015
|
+
formatSourceHeader(resolved),
|
|
1016
|
+
"",
|
|
1017
|
+
`Unknown component ${inlineCode(query)} (a name from another UI library). ${formatComponentAlias(alias)}${otherNames}`
|
|
1018
|
+
].join("\n");
|
|
1019
|
+
}
|
|
1020
|
+
const hint = suggestions.length ? `Did you mean: ${suggestionText}?` : listHint;
|
|
582
1021
|
return [
|
|
583
1022
|
formatSourceHeader(resolved),
|
|
584
1023
|
"",
|
|
@@ -594,23 +1033,6 @@ var formatComponentNeedsUpgrade = (resolved, bundled, componentName) => [
|
|
|
594
1033
|
`Upgrade first (for example \`yarn up @khsura/sui\` or \`npm install @khsura/sui@latest\`), or build the UI from components this version has (call ${inlineCode(LIST_COMPONENTS_TOOL_NAME)}).`
|
|
595
1034
|
].join("\n");
|
|
596
1035
|
//#endregion
|
|
597
|
-
//#region src/utils/componentName.ts
|
|
598
|
-
var NAME_SEPARATORS = /[\s_-]/g;
|
|
599
|
-
/** Lowercase key with separators removed: `SButton`, `s-button` and `sbutton` all map to `sbutton`. */
|
|
600
|
-
var toComponentKey = (name) => name.trim().toLowerCase().replaceAll(NAME_SEPARATORS, "");
|
|
601
|
-
/** Keys a query may refer to, most specific first: as typed, then with the `S` prefix added. */
|
|
602
|
-
var candidateComponentKeys = (query) => {
|
|
603
|
-
const queryKey = toComponentKey(query);
|
|
604
|
-
return [queryKey, `s${queryKey}`];
|
|
605
|
-
};
|
|
606
|
-
/** `SNavigationDrawer` → `Navigation drawer`. */
|
|
607
|
-
var humanizeComponentName = (name) => {
|
|
608
|
-
const sentence = name.replace(/^S(?=[A-Z])/, "").split(/(?=[A-Z])/).map((word) => word.toLowerCase()).join(" ");
|
|
609
|
-
return sentence.charAt(0).toUpperCase() + sentence.slice(1);
|
|
610
|
-
};
|
|
611
|
-
/** True for tags the validator treats as SUI components: `SButton` or `s-button`. Native tags such as `select` never match. */
|
|
612
|
-
var isSuiComponentTag = (tag) => SUI_PASCAL_TAG_PATTERN.test(tag) || SUI_KEBAB_TAG_PATTERN.test(tag);
|
|
613
|
-
//#endregion
|
|
614
1036
|
//#region src/utils/componentPurpose.ts
|
|
615
1037
|
var familyPurpose = (family) => Object.entries(FAMILY_PURPOSES).find(([familyName]) => familyName === family)?.[1] ?? "SUI component";
|
|
616
1038
|
/**
|
|
@@ -658,56 +1080,6 @@ var formatTemplateValidation = (resolved, issues) => [
|
|
|
658
1080
|
...issues.length ? ["", ...issues.map((issue) => `- ${formatTemplateIssue(issue)}`)] : []
|
|
659
1081
|
].join("\n");
|
|
660
1082
|
//#endregion
|
|
661
|
-
//#region src/utils/templateAst.ts
|
|
662
|
-
var positionOf = (node) => ({
|
|
663
|
-
line: node.loc.start.line,
|
|
664
|
-
column: node.loc.start.column
|
|
665
|
-
});
|
|
666
|
-
var codeList = (names) => names.map((name) => `\`${name}\``).join(", ");
|
|
667
|
-
/** The argument of a directive when it is a static name (`:size`, `#header`); `undefined` for none or `[dynamic]`. */
|
|
668
|
-
var staticArgument = (argument) => argument?.type === NodeTypes.SIMPLE_EXPRESSION && argument.isStatic ? argument.content : void 0;
|
|
669
|
-
/** The source of a directive's value (`on` in `v-on="on"`), trimmed; `undefined` when it has none. */
|
|
670
|
-
var expressionSource = (directive) => {
|
|
671
|
-
const source = directive.exp?.loc.source.trim() ?? "";
|
|
672
|
-
return source.length ? source : void 0;
|
|
673
|
-
};
|
|
674
|
-
var isDirective = (prop) => prop.type === NodeTypes.DIRECTIVE;
|
|
675
|
-
/** True when `tag` names `componentName` in either case style: `SAppBar`, `s-app-bar`. */
|
|
676
|
-
var isComponentTag = (tag, componentName) => toComponentKey(tag) === toComponentKey(componentName);
|
|
677
|
-
var isOneOfComponentTags = (tag, componentNames) => componentNames.some((componentName) => isComponentTag(tag, componentName));
|
|
678
|
-
var childElementsOf = (element) => element.children.filter((child) => child.type === NodeTypes.ELEMENT);
|
|
679
|
-
/** `name="x"` or `:name="x"` / `v-bind:name="x"` on `element`; a quoted literal binding still has a static value. */
|
|
680
|
-
var findAttribute = (element, name) => {
|
|
681
|
-
for (const prop of element.props) {
|
|
682
|
-
if (!isDirective(prop)) {
|
|
683
|
-
if (prop.name === name) return {
|
|
684
|
-
node: prop,
|
|
685
|
-
staticValue: prop.value?.content,
|
|
686
|
-
isBound: false
|
|
687
|
-
};
|
|
688
|
-
continue;
|
|
689
|
-
}
|
|
690
|
-
if (prop.name === "bind" && staticArgument(prop.arg) === name) {
|
|
691
|
-
const literal = STRING_LITERAL_EXPRESSION.exec(expressionSource(prop) ?? "");
|
|
692
|
-
return {
|
|
693
|
-
node: prop,
|
|
694
|
-
staticValue: literal?.[2],
|
|
695
|
-
isBound: !literal
|
|
696
|
-
};
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
};
|
|
700
|
-
/** `v-bind="object"`: it may carry any attribute, so presence checks cannot be sure. */
|
|
701
|
-
var hasObjectSpread = (element) => element.props.some((prop) => isDirective(prop) && prop.name === "bind" && !prop.arg);
|
|
702
|
-
/** Slots `element` fills: `v-slot` / `#name` on the element itself or on its direct `<template>` children. */
|
|
703
|
-
var slotFills = (element) => {
|
|
704
|
-
return [element, ...childElementsOf(element).filter((child) => child.tag === TEMPLATE_TAG)].flatMap((owner) => owner.props.filter(isDirective).filter((directive) => directive.name === DIRECTIVE_SLOT).map((directive) => ({
|
|
705
|
-
directive,
|
|
706
|
-
owner
|
|
707
|
-
})));
|
|
708
|
-
};
|
|
709
|
-
var slotDirectives = (element) => slotFills(element).map((fill) => fill.directive);
|
|
710
|
-
//#endregion
|
|
711
1083
|
//#region src/utils/recipeMarkdown.ts
|
|
712
1084
|
var recipeStoryUrl = (name) => `${LIVE_EXAMPLES_URL}${RECIPE_STORY_PATH_PREFIX}${name}`;
|
|
713
1085
|
/** A fence one backtick longer than the longest backtick run in `code`, so the code can never close it early. */
|
|
@@ -743,19 +1115,36 @@ var formatUnknownRecipe = (query, names) => `Unknown recipe ${inlineCode(query)}
|
|
|
743
1115
|
//#endregion
|
|
744
1116
|
//#region src/services/componentCatalog.ts
|
|
745
1117
|
var useComponentCatalogService = (api) => {
|
|
1118
|
+
const componentKeys = new Set(api.components.map((component) => toComponentKey(component.name)));
|
|
746
1119
|
const listComponents = () => api.components.map((component) => ({
|
|
747
1120
|
name: component.name,
|
|
748
1121
|
family: component.family,
|
|
749
1122
|
purpose: componentPurpose(component)
|
|
750
1123
|
}));
|
|
751
|
-
const suggestNames = (query) => {
|
|
1124
|
+
const suggestNames = (query, excludedNames = []) => {
|
|
752
1125
|
const queryKeys = candidateComponentKeys(query);
|
|
753
1126
|
const distanceTo = (name) => Math.min(...queryKeys.map((queryKey) => levenshteinDistance(queryKey, toComponentKey(name))));
|
|
754
|
-
return api.components.map((component) => ({
|
|
1127
|
+
return api.components.filter((component) => !excludedNames.includes(component.name)).map((component) => ({
|
|
755
1128
|
name: component.name,
|
|
756
1129
|
distance: distanceTo(component.name)
|
|
757
1130
|
})).sort((left, right) => left.distance - right.distance || left.name.localeCompare(right.name)).slice(0, 3).map((candidate) => candidate.name);
|
|
758
1131
|
};
|
|
1132
|
+
/**
|
|
1133
|
+
* The other-library alias for a name that is not a component. An alias whose SUI targets are all
|
|
1134
|
+
* missing from this API version is skipped, so the Levenshtein suggestions answer instead.
|
|
1135
|
+
*/
|
|
1136
|
+
const findAlias = (query) => {
|
|
1137
|
+
const queryKeys = candidateComponentKeys(query);
|
|
1138
|
+
const entry = Object.entries(COMPONENT_ALIASES).find(([alias]) => queryKeys.includes(toComponentKey(alias)));
|
|
1139
|
+
if (!entry) return;
|
|
1140
|
+
const [alias, { suiNames, hint }] = entry;
|
|
1141
|
+
const availableNames = suiNames.filter((name) => componentKeys.has(toComponentKey(name)));
|
|
1142
|
+
return suiNames.length && !availableNames.length ? void 0 : {
|
|
1143
|
+
alias,
|
|
1144
|
+
suiNames: availableNames,
|
|
1145
|
+
hint
|
|
1146
|
+
};
|
|
1147
|
+
};
|
|
759
1148
|
const findComponent = (query) => {
|
|
760
1149
|
for (const candidateKey of candidateComponentKeys(query)) {
|
|
761
1150
|
const component = api.components.find((entry) => toComponentKey(entry.name) === candidateKey);
|
|
@@ -764,9 +1153,11 @@ var useComponentCatalogService = (api) => {
|
|
|
764
1153
|
component
|
|
765
1154
|
};
|
|
766
1155
|
}
|
|
1156
|
+
const alias = findAlias(query);
|
|
767
1157
|
return {
|
|
768
1158
|
found: false,
|
|
769
|
-
suggestions: suggestNames(query)
|
|
1159
|
+
suggestions: suggestNames(query, alias?.suiNames),
|
|
1160
|
+
alias
|
|
770
1161
|
};
|
|
771
1162
|
};
|
|
772
1163
|
return {
|
|
@@ -921,7 +1312,7 @@ var serverInfo = {
|
|
|
921
1312
|
name: SERVER_NAME,
|
|
922
1313
|
version: {
|
|
923
1314
|
name: "@khsura/sui-mcp",
|
|
924
|
-
version: "0.
|
|
1315
|
+
version: "0.3.0",
|
|
925
1316
|
repository: {
|
|
926
1317
|
"type": "git",
|
|
927
1318
|
"url": "git+https://github.com/khsura/sui.git",
|
|
@@ -1104,6 +1495,214 @@ var useGuideCatalogService = ({ sourceRoot = resolveGuideSourceRoot() } = {}) =>
|
|
|
1104
1495
|
}
|
|
1105
1496
|
});
|
|
1106
1497
|
//#endregion
|
|
1498
|
+
//#region src/services/behaviourRules.ts
|
|
1499
|
+
var nativeValidationInFormRule = {
|
|
1500
|
+
id: RULE_NATIVE_VALIDATION_IN_FORM,
|
|
1501
|
+
fixedIn: SUI_M2_FIXES_VERSION,
|
|
1502
|
+
check: ({ element, ancestors }) => {
|
|
1503
|
+
const typeAttribute = findAttribute(element, INPUT_TYPE_ATTRIBUTE);
|
|
1504
|
+
const inputType = typeAttribute?.staticValue?.toLowerCase();
|
|
1505
|
+
const form = ancestors.filter((ancestor) => isComponentTag(ancestor.tag, FORM_COMPONENT)).at(-1);
|
|
1506
|
+
if (!typeAttribute || !inputType || !NATIVE_VALIDATING_INPUT_TYPES.includes(inputType) || !form) return [];
|
|
1507
|
+
if (findAttribute(form, "novalidate")) return [];
|
|
1508
|
+
return [{
|
|
1509
|
+
...positionOf(typeAttribute.node),
|
|
1510
|
+
rule: RULE_NATIVE_VALIDATION_IN_FORM,
|
|
1511
|
+
severity: SEVERITY_WARNING,
|
|
1512
|
+
message: `\`type="${inputType}"\` on \`${element.tag}\` inside \`SForm\` turns on the browser's own validation: on submit its bubble covers SUI's error text and blocks the submit handler.`,
|
|
1513
|
+
fixHint: inputType === "number" ? "Add `novalidate` to the `SForm` (it reaches the rendered `<form>`) and validate with `rules`." : `Use \`type="text" inputmode="${inputType}" autocomplete="${inputType}"\` and check the format with a rule, or add \`novalidate\` to the \`SForm\`.`,
|
|
1514
|
+
recipe: RECIPE_VALIDATED_FORM
|
|
1515
|
+
}];
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
var hideDetailsHidesLabelRule = {
|
|
1519
|
+
id: RULE_HIDE_DETAILS_HIDES_LABEL,
|
|
1520
|
+
fixedIn: SUI_M2_FIXES_VERSION,
|
|
1521
|
+
check: ({ element }) => {
|
|
1522
|
+
const hideDetails = findPropAttribute(element, HIDE_DETAILS_ATTRIBUTE);
|
|
1523
|
+
if (!isOneOfComponentTags(element.tag, HIDE_DETAILS_LABEL_COMPONENTS) || !hideDetails || !isBooleanPropOn(element, "hide-details") || !findAttribute(element, "label")) return [];
|
|
1524
|
+
return [{
|
|
1525
|
+
...positionOf(hideDetails.node),
|
|
1526
|
+
rule: RULE_HIDE_DETAILS_HIDES_LABEL,
|
|
1527
|
+
severity: SEVERITY_WARNING,
|
|
1528
|
+
message: `\`hide-details\` on \`${element.tag}\` hides its \`label\` as well as the error line, so the checkbox shows no text.`,
|
|
1529
|
+
fixHint: "Use `hide-error` to drop only the error line and keep the label.",
|
|
1530
|
+
recipe: RECIPE_VALIDATED_FORM
|
|
1531
|
+
}];
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
var isUnreadablePresetAction = (button) => {
|
|
1535
|
+
const color = findAttribute(button, COLOR_ATTRIBUTE)?.staticValue;
|
|
1536
|
+
return findAttribute(button, "variant")?.staticValue === "text" && color !== void 0 && SNACKBAR_UNREADABLE_PRESET_COLORS.includes(color);
|
|
1537
|
+
};
|
|
1538
|
+
/** A text or icon action with a hex CSS colour below 4.5:1 on the default snackbar: used as is, in every version. */
|
|
1539
|
+
var lowContrastCssColorOf = (button) => {
|
|
1540
|
+
const color = findAttribute(button, COLOR_ATTRIBUTE)?.staticValue;
|
|
1541
|
+
const variant = findAttribute(button, VARIANT_ATTRIBUTE)?.staticValue;
|
|
1542
|
+
if (color === void 0 || variant === void 0 || !SNACKBAR_UNCOLOURED_ACTION_VARIANTS.includes(variant)) return;
|
|
1543
|
+
const contrast = getHexContrastRatio(color, SNACKBAR_DEFAULT_BACKGROUND);
|
|
1544
|
+
return contrast !== void 0 && contrast < 4.5 ? {
|
|
1545
|
+
color,
|
|
1546
|
+
contrast
|
|
1547
|
+
} : void 0;
|
|
1548
|
+
};
|
|
1549
|
+
/** A text or icon action with no colour at all: dark page text on the dark snackbar before the M2 fix. */
|
|
1550
|
+
var isUncolouredAction = (button) => {
|
|
1551
|
+
const variant = findAttribute(button, VARIANT_ATTRIBUTE)?.staticValue;
|
|
1552
|
+
return variant !== void 0 && SNACKBAR_UNCOLOURED_ACTION_VARIANTS.includes(variant) && !findAttribute(button, "color") && !staticClassNames(button).some((name) => name.startsWith("s_textColor__"));
|
|
1553
|
+
};
|
|
1554
|
+
var snackbarActionIssue = (button, hasSnackbarColorFix) => {
|
|
1555
|
+
const base = {
|
|
1556
|
+
...positionOf(button),
|
|
1557
|
+
rule: RULE_SNACKBAR_ACTION_CONTRAST,
|
|
1558
|
+
severity: SEVERITY_WARNING,
|
|
1559
|
+
recipe: RECIPE_ACTIVATOR_OVERLAYS
|
|
1560
|
+
};
|
|
1561
|
+
const lowContrastCssColor = lowContrastCssColorOf(button);
|
|
1562
|
+
if (lowContrastCssColor) return {
|
|
1563
|
+
...base,
|
|
1564
|
+
message: `A \`color="${lowContrastCssColor.color}"\` action in the \`SSnackbar\` is ${lowContrastCssColor.contrast.toFixed(2)}:1 on the dark snackbar background (below 4.5:1), so the action is hard to read. A CSS colour is used as is.`,
|
|
1565
|
+
fixHint: hasSnackbarColorFix ? "Remove `color` (an action without a colour uses the snackbar text colour), or use a light CSS colour such as `color=\"#ffffff\"`." : `Use a light colour: ${SNACKBAR_LIGHT_ACTION_COLOR_HINT}.`
|
|
1566
|
+
};
|
|
1567
|
+
if (hasSnackbarColorFix) return;
|
|
1568
|
+
if (isUnreadablePresetAction(button)) {
|
|
1569
|
+
const color = findAttribute(button, "color")?.staticValue ?? "";
|
|
1570
|
+
return {
|
|
1571
|
+
...base,
|
|
1572
|
+
message: `Before @khsura/sui ${SUI_M2_FIXES_VERSION}, a \`color="${color}"\` text button in the \`SSnackbar\` action is below 4.5:1 on the dark snackbar background, so the action is hard to read.`,
|
|
1573
|
+
fixHint: `Use a light colour: ${SNACKBAR_LIGHT_ACTION_COLOR_HINT}, or upgrade to ${SUI_M2_FIXES_VERSION} or later and remove \`color\`.`
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
if (isUncolouredAction(button)) return {
|
|
1577
|
+
...base,
|
|
1578
|
+
message: `Before @khsura/sui ${SUI_M2_FIXES_VERSION}, a text or icon button without \`color\` in the \`SSnackbar\` action keeps the page's dark text colour (about 1.3:1 on the dark snackbar), so the action is hard to read.`,
|
|
1579
|
+
fixHint: `Set a light colour: ${SNACKBAR_LIGHT_ACTION_COLOR_HINT}, or upgrade to ${SUI_M2_FIXES_VERSION} or later.`
|
|
1580
|
+
};
|
|
1581
|
+
};
|
|
1582
|
+
/**
|
|
1583
|
+
* A hex CSS colour below 4.5:1 on the snackbar always warns: the snackbar cannot adjust it. Before
|
|
1584
|
+
* `SUI_M2_FIXES_VERSION` a low-contrast preset colour or no colour at all warns too; from that version an action
|
|
1585
|
+
* without a colour takes the snackbar's light text colour and a preset colour uses a variant tuned to the snackbar.
|
|
1586
|
+
*/
|
|
1587
|
+
var snackbarActionContrastRule = {
|
|
1588
|
+
id: RULE_SNACKBAR_ACTION_CONTRAST,
|
|
1589
|
+
check: ({ element, apiVersion }) => {
|
|
1590
|
+
if (!isComponentTag(element.tag, "SSnackbar")) return [];
|
|
1591
|
+
const hasSnackbarColorFix = isVersionAtLeast(apiVersion, SUI_M2_FIXES_VERSION);
|
|
1592
|
+
return slotFills(element).filter((fill) => staticArgument(fill.directive.arg) === SNACKBAR_ACTION_SLOT_NAME).flatMap((fill) => descendantElementsOf(fill.owner)).filter((descendant) => isComponentTag(descendant.tag, BUTTON_COMPONENT)).flatMap((button) => snackbarActionIssue(button, hasSnackbarColorFix) ?? []);
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
var isFlexRow = (element) => isOneOfComponentTags(element.tag, FLEX_ROW_COMPONENTS) || staticClassNames(element).some((name) => FLEX_DISPLAY_CLASS_PATTERN.test(name)) || FLEX_DISPLAY_STYLE_PATTERN.test(findAttribute(element, "style")?.staticValue ?? "");
|
|
1596
|
+
var isBlockButton = (element) => isComponentTag(element.tag, "SButton") && isBooleanPropOn(element, "block");
|
|
1597
|
+
var blockButtonsInRowRule = {
|
|
1598
|
+
id: RULE_BLOCK_BUTTONS_IN_ROW,
|
|
1599
|
+
target: RULE_TARGET_ANY_ELEMENT,
|
|
1600
|
+
check: ({ element }) => {
|
|
1601
|
+
const blockButtons = childElementsOf(element).filter(isBlockButton);
|
|
1602
|
+
if (blockButtons.length < 2 || !isFlexRow(element)) return [];
|
|
1603
|
+
const [, secondButton] = blockButtons;
|
|
1604
|
+
return [{
|
|
1605
|
+
...positionOf(secondButton),
|
|
1606
|
+
rule: RULE_BLOCK_BUTTONS_IN_ROW,
|
|
1607
|
+
severity: SEVERITY_WARNING,
|
|
1608
|
+
message: `${blockButtons.length} \`block\` buttons sit side by side in one flex row; each is \`width: 100%\` and does not shrink, so the later ones are pushed off screen.`,
|
|
1609
|
+
fixHint: "Put each button in its own `SColumn` of an `SRow` (e.g. `:cols=\"6\"`), or drop `block` from buttons that share a row.",
|
|
1610
|
+
recipe: RECIPE_RESPONSIVE_GRID
|
|
1611
|
+
}];
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
/** A text field whose label and error line are rendered, so its box sits between them. */
|
|
1615
|
+
var isDetailedField = (element) => isOneOfComponentTags(element.tag, LABELLED_FIELD_COMPONENTS) && !isBooleanPropOn(element, "hide-details");
|
|
1616
|
+
var fieldButtonRowRule = {
|
|
1617
|
+
id: RULE_FIELD_BUTTON_ROW,
|
|
1618
|
+
target: RULE_TARGET_ANY_ELEMENT,
|
|
1619
|
+
check: ({ element }) => {
|
|
1620
|
+
if (isComponentTag(element.tag, "SFormRow") || !isFlexRow(element)) return [];
|
|
1621
|
+
const children = childElementsOf(element);
|
|
1622
|
+
const field = children.find(isDetailedField);
|
|
1623
|
+
const button = children.find((child) => isComponentTag(child.tag, BUTTON_COMPONENT));
|
|
1624
|
+
if (!field || !button) return [];
|
|
1625
|
+
return [{
|
|
1626
|
+
...positionOf(button),
|
|
1627
|
+
rule: RULE_FIELD_BUTTON_ROW,
|
|
1628
|
+
severity: SEVERITY_WARNING,
|
|
1629
|
+
message: `\`${field.tag}\` and an \`SButton\` share a flex row: the field is a label, its box and an error line, so the button lines up with the label instead of the field box.`,
|
|
1630
|
+
fixHint: "Use `<SFormRow>` instead of the flex element (@khsura/sui 1.20.0+); it lines each button up with the field box. On an older version put `hide-details` on the field.",
|
|
1631
|
+
recipe: RECIPE_FILTER_BAR
|
|
1632
|
+
}];
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
var cardTitleTextAlignRule = {
|
|
1636
|
+
id: RULE_CARD_TITLE_TEXT_ALIGN,
|
|
1637
|
+
fixedIn: SUI_M2_FIXES_VERSION,
|
|
1638
|
+
check: ({ element }) => {
|
|
1639
|
+
if (!isComponentTag(element.tag, "SCardTitle")) return [];
|
|
1640
|
+
return staticClassNames(element).flatMap((className) => {
|
|
1641
|
+
const alignment = TEXT_ALIGN_CLASS_PATTERN.exec(className)?.[1];
|
|
1642
|
+
if (!alignment) return [];
|
|
1643
|
+
const justifyClass = TEXT_ALIGN_JUSTIFY_CLASSES.get(alignment);
|
|
1644
|
+
return [{
|
|
1645
|
+
...positionOf(findAttribute(element, "class")?.node ?? element),
|
|
1646
|
+
rule: RULE_CARD_TITLE_TEXT_ALIGN,
|
|
1647
|
+
severity: SEVERITY_WARNING,
|
|
1648
|
+
message: `\`${className}\` has no effect on \`SCardTitle\`: it is a flex container, so its text is placed by \`justify-content\`, not \`text-align\`.`,
|
|
1649
|
+
fixHint: justifyClass ? `Use \`${justifyClass}\` instead.` : "Use an `s_justify__*` class instead, or wrap the text in an element that has the `text-align` class."
|
|
1650
|
+
}];
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
/** The directive or `:model-value` binding that feeds the component's model. */
|
|
1655
|
+
var modelBinding = (element) => {
|
|
1656
|
+
return element.props.filter(isDirective).find((directive) => directive.name === "model" && !directive.arg) ?? findPropAttribute(element, "model-value")?.node;
|
|
1657
|
+
};
|
|
1658
|
+
var startsAsEmptyString = (modelPath, scriptSource) => {
|
|
1659
|
+
const escapedName = (modelPath.trim().split(MODEL_PATH_SEPARATOR).at(-1) ?? "").replaceAll(REGEX_SPECIAL_CHARACTERS, "\\$&");
|
|
1660
|
+
return EMPTY_STRING_INITIAL_PATTERNS.some((pattern) => new RegExp(pattern.replace(MODEL_NAME_PLACEHOLDER, escapedName)).test(scriptSource));
|
|
1661
|
+
};
|
|
1662
|
+
var behaviourRules = [
|
|
1663
|
+
nativeValidationInFormRule,
|
|
1664
|
+
hideDetailsHidesLabelRule,
|
|
1665
|
+
snackbarActionContrastRule,
|
|
1666
|
+
blockButtonsInRowRule,
|
|
1667
|
+
fieldButtonRowRule,
|
|
1668
|
+
cardTitleTextAlignRule,
|
|
1669
|
+
{
|
|
1670
|
+
id: RULE_DATE_PICKER_EMPTY_STRING,
|
|
1671
|
+
fixedIn: SUI_M2_FIXES_VERSION,
|
|
1672
|
+
check: ({ element, scriptSource }) => {
|
|
1673
|
+
const binding = isOneOfComponentTags(element.tag, DATE_PICKER_EMPTY_STRING_COMPONENTS) ? modelBinding(element) : void 0;
|
|
1674
|
+
const source = binding && isDirective(binding) ? expressionSource(binding) : binding?.value?.content;
|
|
1675
|
+
if (!binding || source === void 0) return [];
|
|
1676
|
+
const isEmptyLiteral = EMPTY_STRING_EXPRESSION.test(source) || !isDirective(binding) && source === "";
|
|
1677
|
+
const isEmptyInitial = MODEL_PATH_PATTERN.test(source) && startsAsEmptyString(source, scriptSource);
|
|
1678
|
+
if (!isEmptyLiteral && !isEmptyInitial) return [];
|
|
1679
|
+
return [{
|
|
1680
|
+
...positionOf(binding),
|
|
1681
|
+
rule: RULE_DATE_PICKER_EMPTY_STRING,
|
|
1682
|
+
severity: SEVERITY_WARNING,
|
|
1683
|
+
message: isEmptyLiteral ? `\`${element.tag}\` gets \`''\` as its value: the picker opens on "Invalid date" and a grid of NaN.` : `\`${source}\` starts as \`''\` and is bound to \`${element.tag}\`: the picker opens on "Invalid date" and a grid of NaN.`,
|
|
1684
|
+
fixHint: "Start an empty date as `null` (type the model `string | null`); `''` is not treated as \"no date\".",
|
|
1685
|
+
recipe: RECIPE_VALIDATED_FORM
|
|
1686
|
+
}];
|
|
1687
|
+
}
|
|
1688
|
+
},
|
|
1689
|
+
{
|
|
1690
|
+
id: RULE_FILL_HEIGHT_UNDER_APP,
|
|
1691
|
+
fixedIn: SUI_M2_FIXES_VERSION,
|
|
1692
|
+
check: ({ element }) => {
|
|
1693
|
+
if (!isComponentTag(element.tag, "SApp")) return [];
|
|
1694
|
+
return childElementsOf(element).filter((child) => staticClassNames(child).includes(HEIGHT_FILL_CLASS)).map((child) => ({
|
|
1695
|
+
...positionOf(child),
|
|
1696
|
+
rule: RULE_FILL_HEIGHT_UNDER_APP,
|
|
1697
|
+
severity: SEVERITY_WARNING,
|
|
1698
|
+
message: `\`${HEIGHT_FILL_CLASS}\` on a direct child of \`SApp\` resolves to the content height before @khsura/sui 1.20.0 (SApp only has a min-height), so content centred inside it sticks to the top.`,
|
|
1699
|
+
fixHint: "Upgrade @khsura/sui to 1.20.0 or later, or add `style=\"min-height: 100dvh\"` to this child.",
|
|
1700
|
+
recipe: RECIPE_CENTERED_PAGE
|
|
1701
|
+
}));
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
];
|
|
1705
|
+
//#endregion
|
|
1107
1706
|
//#region src/services/compositionRules.ts
|
|
1108
1707
|
var compactExpression = (source) => source.replaceAll(WHITESPACE_PATTERN, "");
|
|
1109
1708
|
/** Values of the argument-less `v-on="…"` or `v-bind="…"` directives on `element`, whitespace removed. */
|
|
@@ -1284,13 +1883,14 @@ var unknownComponentRule = {
|
|
|
1284
1883
|
id: RULE_UNKNOWN_COMPONENT,
|
|
1285
1884
|
check: ({ element, lookup }) => {
|
|
1286
1885
|
if (lookup.found) return [];
|
|
1287
|
-
const suggestion = lookup.suggestions.length ?
|
|
1886
|
+
const suggestion = lookup.suggestions.length ? `${lookup.alias ? "Other close names" : "Did you mean"} ${codeList(lookup.suggestions)}? ` : "";
|
|
1887
|
+
const aliasAdvice = lookup.alias ? `${formatComponentAlias(lookup.alias)} ` : "";
|
|
1288
1888
|
return [{
|
|
1289
1889
|
...positionOf(element),
|
|
1290
1890
|
rule: RULE_UNKNOWN_COMPONENT,
|
|
1291
1891
|
severity: SEVERITY_ERROR,
|
|
1292
|
-
message: `\`${element.tag}\` is not a @khsura/sui component.`,
|
|
1293
|
-
fixHint: `${suggestion}Check the exact names with ${LIST_COMPONENTS_TOOL_NAME}.`
|
|
1892
|
+
message: lookup.alias ? `\`${element.tag}\` is not a @khsura/sui component (it is a name from another UI library).` : `\`${element.tag}\` is not a @khsura/sui component.`,
|
|
1893
|
+
fixHint: `${aliasAdvice}${suggestion}Check the exact names with ${LIST_COMPONENTS_TOOL_NAME}.`
|
|
1294
1894
|
}];
|
|
1295
1895
|
}
|
|
1296
1896
|
};
|
|
@@ -1314,7 +1914,7 @@ var unknownModelIssue = (component, modelProp, node) => {
|
|
|
1314
1914
|
fixHint: supported.length ? `Bind one of its model props instead: ${supported.map((prop) => prop === "modelValue" ? "`v-model`" : `\`v-model:${prop}\``).join(", ")}.` : `\`${component.name}\` supports no v-model; remove it.`
|
|
1315
1915
|
};
|
|
1316
1916
|
};
|
|
1317
|
-
/** The rules this validator runs, in order: API checks first, then the composition rules. */
|
|
1917
|
+
/** The rules this validator runs, in order: API checks first, then the composition and behaviour rules. */
|
|
1318
1918
|
var templateRules = [
|
|
1319
1919
|
unknownComponentRule,
|
|
1320
1920
|
{
|
|
@@ -1369,7 +1969,8 @@ var templateRules = [
|
|
|
1369
1969
|
});
|
|
1370
1970
|
}
|
|
1371
1971
|
},
|
|
1372
|
-
...compositionRules
|
|
1972
|
+
...compositionRules,
|
|
1973
|
+
...behaviourRules
|
|
1373
1974
|
];
|
|
1374
1975
|
//#endregion
|
|
1375
1976
|
//#region src/services/templateValidator.ts
|
|
@@ -1391,16 +1992,20 @@ var byPosition = (left, right) => left.line - right.line || left.column - right.
|
|
|
1391
1992
|
/** Validates SUI usage in a `.vue` SFC or template fragment against one `sui-api.json`. */
|
|
1392
1993
|
var useTemplateValidatorService = (api, rules = templateRules) => {
|
|
1393
1994
|
const catalog = useComponentCatalogService(api);
|
|
1995
|
+
const apiVersion = api.version;
|
|
1996
|
+
const activeRules = rules.filter((rule) => !rule.fixedIn || !isVersionAtLeast(apiVersion, rule.fixedIn));
|
|
1394
1997
|
const validate = (code) => {
|
|
1395
|
-
const { root, errors } = parseVueTemplate(code);
|
|
1998
|
+
const { root, errors, scriptSource } = parseVueTemplate(code);
|
|
1396
1999
|
const ruleIssues = (root ? placedElements(root) : []).flatMap(({ element, ancestors }) => {
|
|
1397
|
-
const applicableRules =
|
|
2000
|
+
const applicableRules = activeRules.filter((rule) => appliesTo(rule, element.tag));
|
|
1398
2001
|
if (!applicableRules.length) return [];
|
|
1399
2002
|
const context = {
|
|
1400
2003
|
element,
|
|
1401
2004
|
ancestors,
|
|
1402
2005
|
lookup: catalog.findComponent(element.tag),
|
|
1403
|
-
api
|
|
2006
|
+
api,
|
|
2007
|
+
apiVersion,
|
|
2008
|
+
scriptSource
|
|
1404
2009
|
};
|
|
1405
2010
|
return applicableRules.flatMap((rule) => rule.check(context));
|
|
1406
2011
|
});
|
|
@@ -1538,13 +2143,13 @@ var findInBundled = (resolved, name, loadBundledSuiApi) => {
|
|
|
1538
2143
|
};
|
|
1539
2144
|
var registerGetComponentApiTool = (server, loadSuiApi, loadBundledSuiApi) => {
|
|
1540
2145
|
server.registerTool(GET_COMPONENT_API_TOOL_NAME, {
|
|
1541
|
-
description: "Returns the props, slots and events of one @khsura/sui component as markdown, with usage notes for activator and layout-child components. Unknown names return the closest matches; a component that only a newer @khsura/sui has says so.",
|
|
2146
|
+
description: "Returns the props, slots and events of one @khsura/sui component as markdown, with usage notes for activator and layout-child components. Unknown names return the SUI equivalent of a name from another UI library (SCol, STextField, SBtn, …) and the closest matches; a component that only a newer @khsura/sui has says so.",
|
|
1542
2147
|
inputSchema: getComponentApiInputSchema
|
|
1543
2148
|
}, ({ name }) => withSuiApi(loadSuiApi, (resolved) => {
|
|
1544
2149
|
const lookup = useComponentCatalogService(resolved.api).findComponent(name);
|
|
1545
2150
|
if (lookup.found) return textResult(formatComponentApi(resolved, lookup.component));
|
|
1546
2151
|
const newer = findInBundled(resolved, name, loadBundledSuiApi);
|
|
1547
|
-
return newer ? textResult(formatComponentNeedsUpgrade(resolved, newer.bundled, newer.component.name), true) : textResult(formatUnknownComponent(resolved, name, lookup.suggestions), true);
|
|
2152
|
+
return newer ? textResult(formatComponentNeedsUpgrade(resolved, newer.bundled, newer.component.name), true) : textResult(formatUnknownComponent(resolved, name, lookup.suggestions, lookup.alias), true);
|
|
1548
2153
|
}));
|
|
1549
2154
|
};
|
|
1550
2155
|
//#endregion
|
|
@@ -1592,7 +2197,7 @@ var registerValidateSuiTemplateTool = (server, loadSuiApi) => {
|
|
|
1592
2197
|
//#region src/handlers/getRecipe.ts
|
|
1593
2198
|
var registerGetRecipeTool = (server, recipeSourceOptions) => {
|
|
1594
2199
|
server.registerTool(GET_RECIPE_TOOL_NAME, {
|
|
1595
|
-
description: "Returns one tested @khsura/sui recipe: its notes (the rules it relies on) and the full copy-ready Vue SFC, plus a link to the live Storybook example. Names: app-shell, validated-form, activator-overlays, data-table, responsive-grid, theme-setup. Unknown names return the name list.",
|
|
2200
|
+
description: "Returns one tested @khsura/sui recipe: its notes (the rules it relies on) and the full copy-ready Vue SFC, plus a link to the live Storybook example. Names: app-shell, validated-form, activator-overlays, data-table, responsive-grid, theme-setup, filter-bar, centered-page. Unknown names return the name list.",
|
|
1596
2201
|
inputSchema: getRecipeInputSchema
|
|
1597
2202
|
}, ({ name }) => {
|
|
1598
2203
|
try {
|
|
@@ -1606,7 +2211,7 @@ var registerGetRecipeTool = (server, recipeSourceOptions) => {
|
|
|
1606
2211
|
//#endregion
|
|
1607
2212
|
//#region src/handlers/listRecipes.ts
|
|
1608
2213
|
var registerListRecipesTool = (server, recipeSourceOptions) => {
|
|
1609
|
-
server.registerTool(LIST_RECIPES_TOOL_NAME, { description: "Lists the tested, copy-ready @khsura/sui recipes (app shell, validated form, dialog/menu/tooltip/snackbar activators, data table, responsive grid, theme and dark mode) with when to use each and the name to pass to get_recipe. Start a page from a recipe instead of composing SUI components from scratch." }, () => {
|
|
2214
|
+
server.registerTool(LIST_RECIPES_TOOL_NAME, { description: "Lists the tested, copy-ready @khsura/sui recipes (app shell, validated form, dialog/menu/tooltip/snackbar activators, data table, responsive grid, theme and dark mode, filter bar, centered login-style page) with when to use each and the name to pass to get_recipe. Start a page from a recipe instead of composing SUI components from scratch." }, () => {
|
|
1610
2215
|
try {
|
|
1611
2216
|
return textResult(formatRecipeList(useRecipeCatalogService(recipeSourceOptions).listRecipes()));
|
|
1612
2217
|
} catch (error) {
|