xmlui 0.9.78 → 0.9.80

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.
Files changed (38) hide show
  1. package/dist/lib/{index-j0JcJZMC.mjs → index-DO8H2Odv.mjs} +19070 -14106
  2. package/dist/lib/index.css +1 -1
  3. package/dist/lib/{initMock-Co9BqeUA.mjs → initMock-CYAkCVnp.mjs} +1 -1
  4. package/dist/lib/xmlui.d.ts +11 -9
  5. package/dist/lib/xmlui.mjs +1 -1
  6. package/dist/metadata/{collectedComponentMetadata-tSxX8HKm.mjs → collectedComponentMetadata-uE4L7cM3.mjs} +23626 -18671
  7. package/dist/metadata/{initMock-B7VL6XTr.mjs → initMock-CqvnqrIU.mjs} +1 -1
  8. package/dist/metadata/style.css +1 -1
  9. package/dist/metadata/xmlui-metadata.mjs +1 -1
  10. package/dist/metadata/xmlui-metadata.umd.js +135 -123
  11. package/dist/scripts/bin/build.js +6 -1
  12. package/dist/scripts/bin/index.js +4 -4
  13. package/dist/scripts/package.json +1 -1
  14. package/dist/scripts/src/components/ComponentProvider.js +6 -2
  15. package/dist/scripts/src/components/EmojiSelector/DefaultProps.js +9 -0
  16. package/dist/scripts/src/components/EmojiSelector/EmojiSelector.js +2 -1
  17. package/dist/scripts/src/components/EmojiSelector/EmojiSelectorNative.js +5 -8
  18. package/dist/scripts/src/components/FormItem/FormItem.js +21 -2
  19. package/dist/scripts/src/components/FormItem/FormItemNative.js +2 -2
  20. package/dist/scripts/src/components/Markdown/MarkdownNative.js +4 -3
  21. package/dist/scripts/src/components/NestedApp/AppWithCodeViewNative.js +7 -6
  22. package/dist/scripts/src/components/NumberBox/NumberBox.js +6 -1
  23. package/dist/scripts/src/components/NumberBox/NumberBoxNative.js +1 -0
  24. package/dist/scripts/src/components/TableEditor/TableEditor.js +2 -132
  25. package/dist/scripts/src/components/TableEditor/TableEditorNative.js +133 -5
  26. package/dist/scripts/src/components-core/ComponentViewer.js +66 -0
  27. package/dist/scripts/src/components-core/InspectorContext.js +0 -15
  28. package/dist/scripts/src/components-core/abstractions/standalone.js +2 -0
  29. package/dist/scripts/src/components-core/devtools/InspectorDialog.js +135 -0
  30. package/dist/scripts/src/components-core/rendering/AppWrapper.js +5 -2
  31. package/dist/scripts/src/language-server/services/common/metadata-utils.js +157 -0
  32. package/dist/scripts/src/parsers/xmlui-parser/index.js +29 -0
  33. package/dist/scripts/src/parsers/xmlui-parser/lint.js +165 -0
  34. package/dist/scripts/src/parsers/xmlui-parser/xmlui-serializer.js +582 -0
  35. package/dist/scripts/src/parsers/xmlui-parser/xmlui-tree.js +2 -0
  36. package/dist/standalone/xmlui-standalone.es.d.ts +11 -9
  37. package/dist/standalone/xmlui-standalone.umd.js +277 -265
  38. package/package.json +1 -1
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ComponentViewer = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const InspectorDialog_1 = require("./devtools/InspectorDialog");
9
+ const AppWithCodeViewNative_1 = __importDefault(require("../components/NestedApp/AppWithCodeViewNative"));
10
+ const react_1 = require("react");
11
+ const InspectorContext_1 = require("./InspectorContext");
12
+ const Tooltip_1 = require("../components/NestedApp/Tooltip");
13
+ const NestedApp_module_scss_1 = __importDefault(require("../components/NestedApp/NestedApp.module.scss"));
14
+ const ai_1 = require("react-icons/ai");
15
+ const ComponentViewer = () => {
16
+ const { mockApi, setIsOpen, isOpen, inspectedNode, clickPosition, projectCompilation, sources } = (0, InspectorContext_1.useDevTools)();
17
+ const components = (0, react_1.useMemo)(() => {
18
+ if (!projectCompilation) {
19
+ return [];
20
+ }
21
+ return projectCompilation.components.map((component) => {
22
+ return component.markupSource;
23
+ });
24
+ }, [projectCompilation]);
25
+ const value = (0, react_1.useMemo)(() => {
26
+ var _a;
27
+ const compSrc = (_a = inspectedNode === null || inspectedNode === void 0 ? void 0 : inspectedNode.debug) === null || _a === void 0 ? void 0 : _a.source;
28
+ if (!compSrc) {
29
+ return "";
30
+ }
31
+ if (!sources) {
32
+ return "";
33
+ }
34
+ const { start, end, fileId } = compSrc;
35
+ const slicedSrc = sources[fileId].slice(start, end);
36
+ let dropEmptyLines = true;
37
+ const prunedLines = [];
38
+ let trimBeginCount = undefined;
39
+ slicedSrc.split("\n").forEach((line) => {
40
+ if (line.trim() === "" && dropEmptyLines) {
41
+ //drop empty lines from the beginning
42
+ return;
43
+ }
44
+ else {
45
+ dropEmptyLines = false;
46
+ prunedLines.push(line);
47
+ const startingWhiteSpaces = line.search(/\S|$/);
48
+ if (line.trim() !== "" &&
49
+ (trimBeginCount === undefined || startingWhiteSpaces < trimBeginCount)) {
50
+ trimBeginCount = startingWhiteSpaces;
51
+ }
52
+ }
53
+ });
54
+ return prunedLines
55
+ .map((line) => line.slice(trimBeginCount).replace(/inspect="true"/g, ""))
56
+ .join("\n");
57
+ }, [inspectedNode, sources]);
58
+ return process.env.VITE_USER_COMPONENTS_Inspect !== "false" &&
59
+ isOpen &&
60
+ inspectedNode !== null ? ((0, jsx_runtime_1.jsx)(InspectorDialog_1.InspectorDialog, { isOpen: isOpen, setIsOpen: setIsOpen, clickPosition: clickPosition, children: (0, jsx_runtime_1.jsx)(AppWithCodeViewNative_1.default, { height: "500px", allowPlaygroundPopup: true, splitView: true, controlsWidth: "120px", closeButton: (0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { trigger: (0, jsx_runtime_1.jsx)("button", { className: NestedApp_module_scss_1.default.headerButton, onClick: () => {
61
+ setIsOpen(false);
62
+ }, children: (0, jsx_runtime_1.jsx)(ai_1.AiOutlineClose, {}) }), label: "Close" }), markdown: `\`\`\`xmlui
63
+ ${value}
64
+ \`\`\``, api: mockApi, app: value, components: components }) })) : null;
65
+ };
66
+ exports.ComponentViewer = ComponentViewer;
@@ -16,23 +16,17 @@ const ThemeContext_1 = require("./theming/ThemeContext");
16
16
  const classnames_1 = __importDefault(require("classnames"));
17
17
  const ButtonNative_1 = require("../components/Button/ButtonNative");
18
18
  const InspectorButton_module_scss_1 = __importDefault(require("./InspectorButton.module.scss"));
19
- const ComponentRegistryContext_1 = require("../components/ComponentRegistryContext");
20
19
  // --- The context object that is used to store the inspector information.
21
20
  exports.InspectorContext = (0, react_1.createContext)(null);
22
21
  function InspectorProvider({ children, sources, projectCompilation, mockApi, }) {
23
- const { root } = (0, ThemeContext_1.useTheme)();
24
22
  const [inspectable, setInspectable] = (0, react_1.useState)({});
25
23
  const [inspectedNode, setInspectedNode] = (0, react_1.useState)(null);
26
24
  const [showCode, setShowCode] = (0, react_1.useState)(false);
27
- const [devToolsSize, setDevToolsSize] = (0, react_1.useState)(0);
28
- const [devToolsSide, setDevToolsSide] = (0, react_1.useState)("bottom");
29
25
  const [inspectMode, setInspectMode] = (0, react_1.useState)(false);
30
26
  const [clickPosition, setClickPosition] = (0, react_1.useState)({
31
27
  x: 0,
32
28
  y: 0,
33
29
  });
34
- const componentRegistry = (0, ComponentRegistryContext_1.useComponentRegistry)();
35
- const devToolsEntry = componentRegistry.lookupComponentRenderer("XMLUIDevtools.DevTools");
36
30
  const contextValue = (0, react_1.useMemo)(() => {
37
31
  return {
38
32
  sources,
@@ -61,10 +55,6 @@ function InspectorProvider({ children, sources, projectCompilation, mockApi, })
61
55
  inspectedNode,
62
56
  setIsOpen: setShowCode,
63
57
  isOpen: showCode,
64
- devToolsSize,
65
- setDevToolsSize,
66
- devToolsSide,
67
- setDevToolsSide,
68
58
  devToolsEnabled: showCode,
69
59
  projectCompilation: projectCompilation,
70
60
  setInspectMode,
@@ -73,8 +63,6 @@ function InspectorProvider({ children, sources, projectCompilation, mockApi, })
73
63
  clickPosition,
74
64
  };
75
65
  }, [
76
- devToolsSide,
77
- devToolsSize,
78
66
  sources,
79
67
  inspectedNode,
80
68
  showCode,
@@ -85,9 +73,6 @@ function InspectorProvider({ children, sources, projectCompilation, mockApi, })
85
73
  mockApi,
86
74
  ]);
87
75
  return ((0, jsx_runtime_1.jsxs)(exports.InspectorContext.Provider, { value: contextValue, children: [children, process.env.VITE_USER_COMPONENTS_Inspect !== "false" &&
88
- showCode &&
89
- inspectedNode !== null &&
90
- (0, react_dom_1.createPortal)(devToolsEntry === null || devToolsEntry === void 0 ? void 0 : devToolsEntry.renderer({}), root), process.env.VITE_USER_COMPONENTS_Inspect !== "false" &&
91
76
  inspectable &&
92
77
  Object.values(inspectable).map((item) => {
93
78
  return ((0, jsx_runtime_1.jsx)(InspectButton, { inspectedNode: inspectedNode, setShowCode: setShowCode, setClickPosition: setClickPosition, inspectId: item.inspectId, node: item.node, setInspectedNode: setInspectedNode, inspectMode: inspectMode }, item.inspectId + +"-" + item.key));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.InspectorDialog = void 0;
40
+ const jsx_runtime_1 = require("react/jsx-runtime");
41
+ const react_1 = __importStar(require("react"));
42
+ const react_compose_refs_1 = require("@radix-ui/react-compose-refs");
43
+ const classnames_1 = __importDefault(require("classnames"));
44
+ const Dialog = __importStar(require("@radix-ui/react-dialog"));
45
+ const InspectorDialog_module_scss_1 = __importDefault(require("./InspectorDialog.module.scss"));
46
+ const xmlui_1 = require("xmlui");
47
+ const framer_motion_1 = require("framer-motion");
48
+ // =====================================================================================================================
49
+ // React component definition
50
+ const MotionContent = framer_motion_1.motion.create(Dialog.Content);
51
+ const overlayVariants = {
52
+ visible: { opacity: 1 },
53
+ hidden: { opacity: 0 },
54
+ };
55
+ const contentVariants = {
56
+ initial: (custom) => ({
57
+ opacity: 0,
58
+ scale: 0.2,
59
+ x: custom.x - window.innerWidth / 2,
60
+ y: custom.y - window.innerHeight / 2,
61
+ }),
62
+ animate: {
63
+ opacity: 1,
64
+ scale: 1,
65
+ x: 0,
66
+ y: 0,
67
+ },
68
+ exit: {
69
+ opacity: 0,
70
+ scale: 0.2,
71
+ transition: { duration: 0.2 },
72
+ },
73
+ };
74
+ function durationToSeconds(durationString) {
75
+ if (!durationString) {
76
+ return undefined;
77
+ }
78
+ const trimmedString = durationString.trim();
79
+ if (trimmedString.endsWith("ms")) {
80
+ const milliseconds = parseFloat(trimmedString);
81
+ return milliseconds / 1000;
82
+ }
83
+ else if (trimmedString.endsWith("s")) {
84
+ return parseFloat(trimmedString);
85
+ }
86
+ else {
87
+ return parseFloat(trimmedString);
88
+ }
89
+ }
90
+ exports.InspectorDialog = react_1.default.forwardRef(({ children, style, isOpen, setIsOpen, clickPosition }, ref) => {
91
+ const { root, getThemeVar } = (0, xmlui_1.useTheme)();
92
+ const modalRef = (0, react_1.useRef)(null);
93
+ const composedRef = ref ? (0, react_compose_refs_1.composeRefs)(ref, modalRef) : modalRef;
94
+ const [rendered, setRendered] = (0, react_1.useState)(true);
95
+ (0, react_1.useEffect)(() => {
96
+ var _a;
97
+ if (isOpen) {
98
+ (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.focus();
99
+ }
100
+ }, [isOpen]);
101
+ // https://github.com/radix-ui/primitives/issues/2122#issuecomment-2140827998
102
+ (0, react_1.useEffect)(() => {
103
+ if (isOpen) {
104
+ // Pushing the change to the end of the call stack
105
+ const timer = setTimeout(() => {
106
+ document.body.style.pointerEvents = "";
107
+ }, 0);
108
+ return () => clearTimeout(timer);
109
+ }
110
+ else {
111
+ document.body.style.pointerEvents = "auto";
112
+ }
113
+ }, [isOpen]);
114
+ if (!root) {
115
+ return null;
116
+ }
117
+ const onExitComplete = () => {
118
+ setIsOpen(false);
119
+ };
120
+ return ((0, jsx_runtime_1.jsx)(Dialog.Root, { defaultOpen: false, open: isOpen, onOpenChange: setRendered, children: (0, jsx_runtime_1.jsx)(Dialog.Portal, { container: root, children: (0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { onExitComplete: onExitComplete, children: rendered && ((0, jsx_runtime_1.jsxs)(Dialog.Overlay, { className: InspectorDialog_module_scss_1.default.overlay, forceMount: true, children: [(0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { className: InspectorDialog_module_scss_1.default.overlayBg, variants: overlayVariants, initial: "hidden", animate: "visible", exit: "hidden", transition: {
121
+ duration: 0.2,
122
+ ease: [0.16, 1, 0.3, 1],
123
+ } }, "overlay"), (0, jsx_runtime_1.jsx)(MotionContent, { forceMount: true, onPointerDownOutside: (event) => {
124
+ if (event.target instanceof Element &&
125
+ event.target.closest("._debug-inspect-button") !== null) {
126
+ //we prevent the auto modal close on clicking the inspect button
127
+ event.preventDefault();
128
+ }
129
+ }, children: (0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { ref: composedRef, className: (0, classnames_1.default)(InspectorDialog_module_scss_1.default.content, InspectorDialog_module_scss_1.default.contentWrapper), variants: contentVariants, custom: { x: clickPosition.x, y: clickPosition.y }, initial: "initial", animate: "animate", exit: "exit", transition: {
130
+ duration: durationToSeconds(getThemeVar("duration-startAnimation-ModalDialog")) ||
131
+ 0.8,
132
+ ease: [0.16, 1, 0.3, 1],
133
+ }, style: Object.assign(Object.assign({}, style), { gap: undefined }), children: children }) })] })) }) }) }));
134
+ });
135
+ exports.InspectorDialog.displayName = "InspectorDialog";
@@ -19,6 +19,7 @@ const AppContent_1 = require("./AppContent");
19
19
  const ErrorBoundary_1 = require("./ErrorBoundary");
20
20
  const LoggerContext_1 = require("../../logging/LoggerContext");
21
21
  const LoggerInitializer_1 = require("../../logging/LoggerInitializer");
22
+ const ComponentViewer_1 = require("../ComponentViewer");
22
23
  /**
23
24
  * This component wraps the application into other layers of (nested) components
24
25
  * that provide app functionality and services requiring unique interaction with
@@ -38,10 +39,12 @@ const AppWrapper = ({ node, previewMode = false, routerBaseName: baseName = "",
38
39
  // --- provide the app functionality and services. These components are
39
40
  // --- wrapped in other components that provide the necessary environment
40
41
  // --- for the app to run.
41
- const dynamicChildren = ((0, jsx_runtime_1.jsxs)(react_helmet_async_1.HelmetProvider, { children: [(0, jsx_runtime_1.jsx)(react_helmet_async_1.Helmet, { defaultTitle: siteName, titleTemplate: `%s | ${siteName}` }), (0, jsx_runtime_1.jsxs)(LoggerContext_1.LoggerProvider, { children: [(0, jsx_runtime_1.jsx)(LoggerInitializer_1.LoggerInitializer, {}), (0, jsx_runtime_1.jsx)(IconProvider_1.IconProvider, { children: (0, jsx_runtime_1.jsx)(ThemeProvider_1.default, { resourceMap: resourceMap, themes: contributes.themes, defaultTheme: defaultTheme, defaultTone: defaultTone, resources: resources, children: (0, jsx_runtime_1.jsx)(InspectorContext_1.InspectorProvider, { sources: sources, projectCompilation: projectCompilation, mockApi: globalProps === null || globalProps === void 0 ? void 0 : globalProps.demoMockApi, children: (0, jsx_runtime_1.jsx)(ConfirmationModalContextProvider_1.ConfirmationModalContextProvider, { children: (0, jsx_runtime_1.jsx)(AppContent_1.AppContent, { onInit: onInit, rootContainer: node, routerBaseName: baseName, globalProps: globalProps, standalone: standalone, decorateComponentsWithTestId: decorateComponentsWithTestId, debugEnabled: debugEnabled, trackContainerHeight: trackContainerHeight, children: children }) }) }) }) })] })] }));
42
+ const dynamicChildren = ((0, jsx_runtime_1.jsxs)(react_helmet_async_1.HelmetProvider, { children: [(0, jsx_runtime_1.jsx)(react_helmet_async_1.Helmet, { defaultTitle: siteName, titleTemplate: `%s | ${siteName}` }), (0, jsx_runtime_1.jsxs)(LoggerContext_1.LoggerProvider, { children: [(0, jsx_runtime_1.jsx)(LoggerInitializer_1.LoggerInitializer, {}), (0, jsx_runtime_1.jsx)(IconProvider_1.IconProvider, { children: (0, jsx_runtime_1.jsx)(ThemeProvider_1.default, { resourceMap: resourceMap, themes: contributes.themes, defaultTheme: defaultTheme, defaultTone: defaultTone, resources: resources, children: (0, jsx_runtime_1.jsx)(InspectorContext_1.InspectorProvider, { sources: sources, projectCompilation: projectCompilation, mockApi: globalProps === null || globalProps === void 0 ? void 0 : globalProps.demoMockApi, children: (0, jsx_runtime_1.jsx)(ConfirmationModalContextProvider_1.ConfirmationModalContextProvider, { children: (0, jsx_runtime_1.jsxs)(AppContent_1.AppContent, { onInit: onInit, rootContainer: node, routerBaseName: baseName, globalProps: globalProps, standalone: standalone, decorateComponentsWithTestId: decorateComponentsWithTestId, debugEnabled: debugEnabled, trackContainerHeight: trackContainerHeight, children: [(0, jsx_runtime_1.jsx)(ComponentViewer_1.ComponentViewer, {}), children] }) }) }) }) })] })] }));
42
43
  // --- Select the router type for the app
43
44
  const Router = previewMode ? react_router_dom_1.MemoryRouter : useHashBasedRouting ? react_router_dom_1.HashRouter : react_router_dom_1.BrowserRouter;
44
- const shouldSkipClientRouter = previewMode ? false : (typeof window === "undefined" || process.env.VITE_REMIX);
45
+ const shouldSkipClientRouter = previewMode
46
+ ? false
47
+ : typeof window === "undefined" || process.env.VITE_REMIX;
45
48
  return ((0, jsx_runtime_1.jsx)(react_1.default.StrictMode, { children: (0, jsx_runtime_1.jsx)(ErrorBoundary_1.ErrorBoundary, { node: node, location: "root-outer", children: (0, jsx_runtime_1.jsxs)(react_query_1.QueryClientProvider, { client: AppRoot_1.queryClient, children: [!!shouldSkipClientRouter && dynamicChildren, !shouldSkipClientRouter && ((0, jsx_runtime_1.jsx)(Router, { basename: Router === react_router_dom_1.HashRouter ? undefined : baseName, children: dynamicChildren }))] }) }) }));
46
49
  };
47
50
  exports.AppWrapper = AppWrapper;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComponentMetadataProvider = exports.MetadataProvider = void 0;
4
+ exports.addOnPrefix = addOnPrefix;
5
+ const descriptorHelper_1 = require("../../../components-core/descriptorHelper");
6
+ const xmlui_parser_1 = require("../../../parsers/xmlui-parser");
7
+ const abstractions_1 = require("../../../components/abstractions");
8
+ class MetadataProvider {
9
+ constructor(metadataCollection) {
10
+ this.metadataCollection = metadataCollection;
11
+ }
12
+ componentNames() {
13
+ return Object.keys(this.metadataCollection);
14
+ }
15
+ getComponent(componentName) {
16
+ const providerData = this.metadataCollection[componentName];
17
+ if (!providerData) {
18
+ return null;
19
+ }
20
+ return new ComponentMetadataProvider(providerData);
21
+ }
22
+ }
23
+ exports.MetadataProvider = MetadataProvider;
24
+ class ComponentMetadataProvider {
25
+ constructor(metadata) {
26
+ this.metadata = metadata;
27
+ }
28
+ /**
29
+ * Retrieves the metadata for a given property, explicit or implicit.
30
+ * @param name The name of the property.
31
+ * @returns The metadata for the property, or `undefined` if not found.
32
+ */
33
+ getProp(name) {
34
+ var _a;
35
+ return (_a = this.metadata.props[name]) !== null && _a !== void 0 ? _a : implicitPropsMetadata[name];
36
+ }
37
+ getAttr(name) {
38
+ var _a, _b, _c;
39
+ if (xmlui_parser_1.onPrefixRegex.test(name)) {
40
+ const eventName = (0, xmlui_parser_1.stripOnPrefix)(name);
41
+ const event = (_a = this.metadata.events) === null || _a === void 0 ? void 0 : _a[eventName];
42
+ if (event) {
43
+ return event;
44
+ }
45
+ }
46
+ const explicitProp = (_b = this.metadata.props) === null || _b === void 0 ? void 0 : _b[name];
47
+ if (explicitProp) {
48
+ return explicitProp;
49
+ }
50
+ const api = (_c = this.metadata.apis) === null || _c === void 0 ? void 0 : _c[name];
51
+ if (api) {
52
+ return api;
53
+ }
54
+ const layout = layoutMdForKey(name);
55
+ if (layout) {
56
+ return layout;
57
+ }
58
+ return implicitPropsMetadata[name];
59
+ }
60
+ getAttrForKind({ name, kind }) {
61
+ switch (kind) {
62
+ case "api":
63
+ return this.metadata.apis[name];
64
+ case "event":
65
+ return this.metadata.events[name];
66
+ case "prop":
67
+ return this.metadata.props[name];
68
+ case "implicit":
69
+ return implicitPropsMetadata[name];
70
+ case "layout":
71
+ return layoutMdForKey(name);
72
+ }
73
+ }
74
+ getAllAttributes() {
75
+ var _a, _b, _c;
76
+ const attrNames = [];
77
+ for (const key of Object.keys((_a = this.metadata.props) !== null && _a !== void 0 ? _a : {})) {
78
+ attrNames.push({ name: key, kind: "prop" });
79
+ }
80
+ for (const key of Object.keys((_b = this.metadata.events) !== null && _b !== void 0 ? _b : {})) {
81
+ attrNames.push({ name: key, kind: "event" });
82
+ }
83
+ for (const key of Object.keys((_c = this.metadata.apis) !== null && _c !== void 0 ? _c : {})) {
84
+ attrNames.push({ name: key, kind: "api" });
85
+ }
86
+ for (const layoutKey of descriptorHelper_1.layoutOptionKeys) {
87
+ attrNames.push({ name: layoutKey, kind: "layout" });
88
+ }
89
+ for (const implicitPropKey of Object.keys(implicitPropsMetadata)) {
90
+ attrNames.push({ name: implicitPropKey, kind: "implicit" });
91
+ }
92
+ return attrNames;
93
+ }
94
+ getEvent(name) {
95
+ var _a;
96
+ return (_a = this.metadata.events) === null || _a === void 0 ? void 0 : _a[name];
97
+ }
98
+ getApi(name) {
99
+ var _a;
100
+ return (_a = this.metadata.apis) === null || _a === void 0 ? void 0 : _a[name];
101
+ }
102
+ get events() {
103
+ return this.metadata.events;
104
+ }
105
+ get apis() {
106
+ return this.metadata.apis;
107
+ }
108
+ get contextVars() {
109
+ return this.metadata.contextVars;
110
+ }
111
+ get allowArbitraryProps() {
112
+ return this.metadata.allowArbitraryProps;
113
+ }
114
+ get shortDescription() {
115
+ return this.metadata.shortDescription;
116
+ }
117
+ getMetadata() {
118
+ return this.metadata;
119
+ }
120
+ }
121
+ exports.ComponentMetadataProvider = ComponentMetadataProvider;
122
+ function layoutMdForKey(name) {
123
+ const metadata = {
124
+ description: "Layout property. Not yet documented",
125
+ };
126
+ if (descriptorHelper_1.layoutOptionKeys.includes(name)) {
127
+ return metadata;
128
+ }
129
+ for (const size of abstractions_1.viewportSizeMd) {
130
+ const suffix = "-" + (size.value);
131
+ if (name.endsWith(suffix)) {
132
+ const nameWithoutSize = name.slice(0, -suffix.length);
133
+ if (descriptorHelper_1.layoutOptionKeys.includes(nameWithoutSize)) {
134
+ return metadata;
135
+ }
136
+ }
137
+ }
138
+ return null;
139
+ }
140
+ const implicitPropsMetadata = {
141
+ inspect: {
142
+ description: "Determines whether the component can be inspected or not",
143
+ defaultValue: false,
144
+ valueType: "boolean",
145
+ },
146
+ data: {
147
+ description: "Specifies the data source for a component. Can be a URL string (fetched automatically), a DataSource or an expression to evaluate. Changes to this property trigger UI updates once data is loaded.",
148
+ },
149
+ when: {
150
+ description: "Specifies a condition that must be met for the component to be displayed",
151
+ defaultValue: true,
152
+ valueType: "boolean",
153
+ }
154
+ };
155
+ function addOnPrefix(name) {
156
+ return "on" + name[0].toUpperCase() + name.substring(1);
157
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./CharacterCodes"), exports);
18
+ __exportStar(require("./diagnostics"), exports);
19
+ __exportStar(require("./fileExtensions"), exports);
20
+ __exportStar(require("./lint"), exports);
21
+ __exportStar(require("./parser"), exports);
22
+ __exportStar(require("./ParserError"), exports);
23
+ __exportStar(require("./scanner"), exports);
24
+ __exportStar(require("./syntax-kind"), exports);
25
+ __exportStar(require("./syntax-node"), exports);
26
+ __exportStar(require("./transform"), exports);
27
+ __exportStar(require("./utils"), exports);
28
+ __exportStar(require("./xmlui-serializer"), exports);
29
+ __exportStar(require("./xmlui-tree"), exports);
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LintDiagKind = exports.LintSeverity = void 0;
4
+ exports.getLintSeverity = getLintSeverity;
5
+ exports.lintApp = lintApp;
6
+ exports.printComponentLints = printComponentLints;
7
+ exports.lintErrorsComponent = lintErrorsComponent;
8
+ exports.lint = lint;
9
+ const descriptorHelper_1 = require("../../components-core/descriptorHelper");
10
+ const transform_1 = require("./transform");
11
+ var LintSeverity;
12
+ (function (LintSeverity) {
13
+ LintSeverity[LintSeverity["Skip"] = 0] = "Skip";
14
+ LintSeverity[LintSeverity["Warning"] = 1] = "Warning";
15
+ LintSeverity[LintSeverity["Error"] = 2] = "Error";
16
+ })(LintSeverity || (exports.LintSeverity = LintSeverity = {}));
17
+ var LintDiagKind;
18
+ (function (LintDiagKind) {
19
+ LintDiagKind[LintDiagKind["UnrecognisedProp"] = 0] = "UnrecognisedProp";
20
+ })(LintDiagKind || (exports.LintDiagKind = LintDiagKind = {}));
21
+ function getLintSeverity(lintSeverityOption) {
22
+ if (!lintSeverityOption) {
23
+ return LintSeverity.Warning;
24
+ }
25
+ let lintSeverity = LintSeverity.Warning;
26
+ switch (lintSeverityOption.toLowerCase()) {
27
+ case "warning":
28
+ return LintSeverity.Warning;
29
+ break;
30
+ case "error":
31
+ return LintSeverity.Error;
32
+ break;
33
+ case "skip":
34
+ return LintSeverity.Skip;
35
+ break;
36
+ default:
37
+ console.warn(`Invalid lint severity option '${lintSeverityOption}'. Must be one of: 'warning', 'error', 'skip'. Defaulting to 'warning'.`);
38
+ return LintSeverity.Warning;
39
+ break;
40
+ }
41
+ }
42
+ function lintApp({ appDef, metadataProvider, }) {
43
+ var _a;
44
+ const entryPointLints = {
45
+ componentName: "Main",
46
+ lints: lint({
47
+ component: appDef.entryPoint,
48
+ metadataProvider,
49
+ }),
50
+ };
51
+ const compoundCompLints = ((_a = appDef.components) !== null && _a !== void 0 ? _a : []).map((c) => {
52
+ const lints = lint({
53
+ component: c,
54
+ metadataProvider,
55
+ });
56
+ return { lints, componentName: c.name };
57
+ });
58
+ return [entryPointLints, ...compoundCompLints].filter((diags) => diags.lints.length > 0);
59
+ }
60
+ function printComponentLints(lintDiags) {
61
+ console.group(`Validation on '${lintDiags.componentName}':`);
62
+ lintDiags.lints.forEach(({ message }) => {
63
+ console.warn(message);
64
+ });
65
+ console.groupEnd();
66
+ }
67
+ function lintErrorsComponent(lints) {
68
+ function makeComponent() {
69
+ const errList = lints.map((lint, idx) => {
70
+ return {
71
+ type: "VStack",
72
+ props: { gap: "0px" },
73
+ children: [
74
+ {
75
+ type: "VStack",
76
+ props: { backgroundColor: "lightgrey", padding: "10px" },
77
+ children: [
78
+ {
79
+ type: "H2",
80
+ props: {
81
+ value: `#${idx + 1}: In component '${lint.componentName}':`,
82
+ color: "$color-info",
83
+ },
84
+ },
85
+ {
86
+ type: "VStack",
87
+ children: lint.lints.map(({ message }, msgIdx) => {
88
+ return {
89
+ type: "Text",
90
+ props: { value: `${idx + 1}.${msgIdx + 1}: ${message}`, fontWeight: "bold" },
91
+ };
92
+ }),
93
+ },
94
+ ],
95
+ },
96
+ ],
97
+ };
98
+ });
99
+ const comp = {
100
+ type: "VStack",
101
+ props: { padding: "$padding-normal", gap: 0 },
102
+ children: [
103
+ {
104
+ type: "H1",
105
+ props: {
106
+ value: `Errors found while checking Xmlui markup`,
107
+ padding: "$padding-normal",
108
+ backgroundColor: "$color-error",
109
+ color: "white",
110
+ },
111
+ },
112
+ {
113
+ type: "VStack",
114
+ props: {
115
+ gap: "$gap-tight",
116
+ padding: "$padding-normal",
117
+ },
118
+ children: errList,
119
+ },
120
+ ],
121
+ };
122
+ return comp;
123
+ }
124
+ return makeComponent();
125
+ }
126
+ function lint({ component, metadataProvider, }) {
127
+ if ("component" in component) {
128
+ return lintHelp(component.component, metadataProvider, []);
129
+ }
130
+ return lintHelp(component, metadataProvider, []);
131
+ }
132
+ function lintHelp(component, metadataProvider, acc) {
133
+ const componentName = component.type.startsWith(transform_1.CORE_NAMESPACE_VALUE)
134
+ ? component.type.slice(transform_1.CORE_NAMESPACE_VALUE.length + 1)
135
+ : component.type;
136
+ const componentMdProvider = metadataProvider.getComponent(componentName);
137
+ if (componentMdProvider !== null && !componentMdProvider.allowArbitraryProps) {
138
+ lintAttrs(component, componentMdProvider, acc);
139
+ }
140
+ if (!component.children) {
141
+ return acc;
142
+ }
143
+ for (const child of component.children) {
144
+ lintHelp(child, metadataProvider, acc);
145
+ }
146
+ return acc;
147
+ }
148
+ const implicitPropNames = descriptorHelper_1.layoutOptionKeys;
149
+ function lintAttrs(component, metadataForCurrentComponent, diags) {
150
+ var _a, _b, _c;
151
+ const invalidAttrNames = Object.keys((_a = component.props) !== null && _a !== void 0 ? _a : {}).filter((name) => !metadataForCurrentComponent.getAttr(name));
152
+ const invalidEvents = Object.keys((_b = component.events) !== null && _b !== void 0 ? _b : {}).filter((event) => !metadataForCurrentComponent.getEvent(event));
153
+ const invalidApis = Object.keys((_c = component.api) !== null && _c !== void 0 ? _c : {}).filter((api) => !metadataForCurrentComponent.getApi(api));
154
+ invalidAttrNames.push(...invalidEvents);
155
+ invalidAttrNames.push(...invalidApis);
156
+ for (const invalidAttrName of invalidAttrNames) {
157
+ diags.push(toUnrecognisedAttrDiag(component, invalidAttrName));
158
+ }
159
+ }
160
+ function toUnrecognisedAttrDiag(component, attr) {
161
+ return {
162
+ message: `Unrecognised property '${attr}' on component '${component.type}'.`,
163
+ kind: LintDiagKind.UnrecognisedProp,
164
+ };
165
+ }