xmlui 0.7.27 → 0.7.29

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 (58) hide show
  1. package/dist/{apiInterceptorWorker-Ca5HMlfW.mjs → apiInterceptorWorker-BXh2BMZL.mjs} +1 -1
  2. package/dist/{index-BMOK5q0U.mjs → index-B3eDGXIR.mjs} +8488 -8166
  3. package/dist/scripts/src/components/APICall/APICall.js +31 -29
  4. package/dist/scripts/src/components/AppHeader/AppHeader.js +4 -4
  5. package/dist/scripts/src/components/Badge/Badge.js +2 -2
  6. package/dist/scripts/src/components/Bookmark/Bookmark.js +7 -7
  7. package/dist/scripts/src/components/Bookmark/BookmarkNative.js +2 -2
  8. package/dist/scripts/src/components/Button/Button.js +1 -7
  9. package/dist/scripts/src/components/Carousel/Carousel.js +3 -1
  10. package/dist/scripts/src/components/Checkbox/Checkbox.js +0 -1
  11. package/dist/scripts/src/components/ColorPicker/ColorPicker.js +1 -1
  12. package/dist/scripts/src/components/DropdownMenu/DropdownMenu.js +2 -1
  13. package/dist/scripts/src/components/FileUploadDropZone/FileUploadDropZone.js +13 -4
  14. package/dist/scripts/src/components/FlowLayout/FlowLayout.js +18 -8
  15. package/dist/scripts/src/components/FlowLayout/FlowLayoutNative.js +5 -1
  16. package/dist/scripts/src/components/Form/Form.js +53 -17
  17. package/dist/scripts/src/components/Form/FormContext.js +103 -1
  18. package/dist/scripts/src/components/Form/FormNative.js +9 -1
  19. package/dist/scripts/src/components/FormItem/FormItem.js +113 -33
  20. package/dist/scripts/src/components/FormItem/FormItemNative.js +8 -2
  21. package/dist/scripts/src/components/FormItem/Validations.js +1 -1
  22. package/dist/scripts/src/components/Heading/Heading.js +23 -4
  23. package/dist/scripts/src/components/Heading/HeadingNative.js +9 -4
  24. package/dist/scripts/src/components/Icon/Icon.js +5 -2
  25. package/dist/scripts/src/components/Icon/IconNative.js +2 -2
  26. package/dist/scripts/src/components/Image/Image.js +5 -1
  27. package/dist/scripts/src/components/Items/Items.js +4 -2
  28. package/dist/scripts/src/components/Items/ItemsNative.js +1 -3
  29. package/dist/scripts/src/components/Link/Link.js +13 -4
  30. package/dist/scripts/src/components/List/List.js +22 -5
  31. package/dist/scripts/src/components/Markdown/Markdown.js +8 -4
  32. package/dist/scripts/src/components/ModalDialog/ModalDialog.js +12 -6
  33. package/dist/scripts/src/components/NavLink/NavLink.js +28 -10
  34. package/dist/scripts/src/components/NoResult/NoResult.js +6 -2
  35. package/dist/scripts/src/components/NumberBox/NumberBox.js +22 -6
  36. package/dist/scripts/src/components/Option/Option.js +1 -1
  37. package/dist/scripts/src/components/ProgressBar/ProgressBar.js +5 -1
  38. package/dist/scripts/src/components/Spinner/Spinner.js +10 -2
  39. package/dist/scripts/src/components/Splitter/Splitter.js +38 -13
  40. package/dist/scripts/src/components/Stack/Stack.js +39 -11
  41. package/dist/scripts/src/components/StickyBox/StickyBox.js +7 -2
  42. package/dist/scripts/src/components/Switch/Switch.js +0 -1
  43. package/dist/scripts/src/components/Table/Table.js +35 -18
  44. package/dist/scripts/src/components/TableOfContents/TableOfContents.js +13 -4
  45. package/dist/scripts/src/components/TableOfContents/TableOfContentsNative.js +15 -22
  46. package/dist/scripts/src/components/Tabs/Tabs.js +8 -3
  47. package/dist/scripts/src/components/Text/Text.js +20 -8
  48. package/dist/scripts/src/components/TextArea/TextArea.js +30 -13
  49. package/dist/scripts/src/components/Theme/Theme.js +6 -2
  50. package/dist/scripts/src/components/abstractions.js +14 -3
  51. package/dist/scripts/src/components-core/TableOfContentsContext.js +57 -17
  52. package/dist/scripts/src/components-core/utils/extractParam.js +3 -2
  53. package/dist/style.css +1 -1
  54. package/dist/xmlui-metadata.mjs +9307 -5528
  55. package/dist/xmlui-metadata.umd.js +17 -17
  56. package/dist/xmlui-standalone.umd.js +166 -166
  57. package/dist/xmlui.mjs +1 -1
  58. package/package.json +1 -1
@@ -7,6 +7,8 @@ const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  const react_1 = require("react");
8
8
  const hooks_1 = require("./utils/hooks");
9
9
  const react_2 = require("@remix-run/react");
10
+ const constants_1 = require("./constants");
11
+ const react_router_dom_1 = require("react-router-dom");
10
12
  /**
11
13
  * Several components work together to represent the hierarchy of a particular
12
14
  * app page as a TOC. This React component provides a context for storing this
@@ -18,9 +20,8 @@ exports.TableOfContentsContext = (0, react_1.createContext)(null);
18
20
  */
19
21
  function TableOfContentsProvider({ children }) {
20
22
  var _a, _b;
21
- const [headings, setHeadings] = (0, react_1.useState)({});
22
- const [observeIntersection, setObserveIntersection] = (0, react_1.useState)(false);
23
- const [activeId, setActiveId] = (0, react_1.useState)(null);
23
+ const [headings, setHeadings] = (0, react_1.useState)(constants_1.EMPTY_OBJECT);
24
+ const [callbacks, setCallbacks] = (0, react_1.useState)(constants_1.EMPTY_ARRAY);
24
25
  const observer = (0, react_1.useRef)(null);
25
26
  const initialHeading = (0, react_1.useRef)(null);
26
27
  const thisRef = (0, react_1.useRef)({
@@ -32,25 +33,33 @@ function TableOfContentsProvider({ children }) {
32
33
  thisRef.current.suspendPositionBasedSetActiveId = false;
33
34
  }, []),
34
35
  });
36
+ const notify = (0, react_1.useCallback)((id) => {
37
+ callbacks.forEach((cb) => cb(id));
38
+ }, [callbacks]);
35
39
  (0, react_1.useEffect)(() => {
36
- if (observeIntersection) {
40
+ if (callbacks.length) {
37
41
  const handleObserver = (entries) => {
38
42
  entries.forEach((entry) => {
39
43
  if (entry === null || entry === void 0 ? void 0 : entry.isIntersecting) {
40
44
  if (!thisRef.current.suspendPositionBasedSetActiveId) {
41
- setActiveId(entry.target.id);
45
+ notify(entry.target.id);
42
46
  }
43
47
  }
44
48
  });
45
49
  };
50
+ // stolen from nextra: https://github.com/shuding/nextra/blob/3729f67059f1fbdd3f98125bebabbe568c918694/packages/nextra-theme-docs/src/mdx-components/heading-anchor.client.tsx
51
+ // let headerHeight = getComputedStyle(scrollParent || document.body).getPropertyValue(
52
+ // '--header-abs-height'
53
+ // );
46
54
  observer.current = new IntersectionObserver(handleObserver, {
47
- rootMargin: "0px 0px -50%",
48
- threshold: [0, 1],
55
+ rootMargin: `0% 0% -80%`,
56
+ // root: scrollParent,
57
+ // threshold: [0, 1],
49
58
  });
50
59
  Object.values(headings).forEach((elem) => { var _a, _b; return (_b = (_a = observer === null || observer === void 0 ? void 0 : observer.current) === null || _a === void 0 ? void 0 : _a.observe) === null || _b === void 0 ? void 0 : _b.call(_a, elem.anchor); });
51
60
  return () => { var _a; return (_a = observer.current) === null || _a === void 0 ? void 0 : _a.disconnect(); };
52
61
  }
53
- }, [headings, observeIntersection]);
62
+ }, [callbacks.length, headings, notify, scrollParent]);
54
63
  const registerHeading = (0, react_1.useCallback)((headingItem) => {
55
64
  setHeadings((prevHeadings) => {
56
65
  return Object.assign(Object.assign({}, prevHeadings), { [headingItem.id]: headingItem });
@@ -63,12 +72,28 @@ function TableOfContentsProvider({ children }) {
63
72
  });
64
73
  };
65
74
  }, []);
66
- const setActiveAnchorId = (0, react_1.useCallback)((id) => {
67
- if (headings[id]) {
75
+ const navigate = (0, react_router_dom_1.useNavigate)();
76
+ const scrollToAnchor = (0, react_1.useCallback)((id, smoothScrolling) => {
77
+ const value = headings[id];
78
+ if (value) {
79
+ value.anchor.scrollIntoView({
80
+ block: "start",
81
+ inline: "start",
82
+ behavior: smoothScrolling ? "smooth" : "auto",
83
+ });
84
+ notify(id);
85
+ requestAnimationFrame(() => {
86
+ navigate({
87
+ hash: `#${value.id}`,
88
+ }, {
89
+ state: {
90
+ preventHashScroll: true,
91
+ },
92
+ });
93
+ });
68
94
  thisRef.current.suspendPositionBasedSetActiveId = true;
69
- setActiveId(id);
70
95
  }
71
- }, [headings]);
96
+ }, [headings, navigate, notify]);
72
97
  const sortedHeadings = (0, react_1.useMemo)(() => {
73
98
  return Object.values(headings).sort(function (a, b) {
74
99
  if (a.anchor === b.anchor)
@@ -100,16 +125,31 @@ function TableOfContentsProvider({ children }) {
100
125
  }
101
126
  }
102
127
  }, [location.hash, sortedHeadings]);
128
+ const subscribeToActiveAnchorChange = (0, react_1.useCallback)((cb) => {
129
+ setCallbacks((prev) => {
130
+ return [...prev, cb];
131
+ });
132
+ return () => {
133
+ setCallbacks((prev) => {
134
+ return prev.filter((item) => item !== cb);
135
+ });
136
+ };
137
+ }, []);
103
138
  const contextValue = (0, react_1.useMemo)(() => {
104
139
  return {
105
140
  registerHeading,
106
141
  headings: sortedHeadings,
107
- observeIntersection,
108
- setObserveIntersection,
109
- activeAnchorId: activeId,
110
- setActiveAnchorId,
142
+ scrollToAnchor,
143
+ subscribeToActiveAnchorChange,
144
+ hasTableOfContents: callbacks.length > 0,
111
145
  };
112
- }, [registerHeading, sortedHeadings, observeIntersection, activeId, setActiveAnchorId]);
146
+ }, [
147
+ registerHeading,
148
+ sortedHeadings,
149
+ scrollToAnchor,
150
+ subscribeToActiveAnchorChange,
151
+ callbacks.length,
152
+ ]);
113
153
  return ((0, jsx_runtime_1.jsx)(exports.TableOfContentsContext.Provider, { value: contextValue, children: children }));
114
154
  }
115
155
  function useTableOfContents() {
@@ -7,6 +7,7 @@ exports.extractParam = extractParam;
7
7
  exports.withStableObjectReference = withStableObjectReference;
8
8
  exports.shouldKeep = shouldKeep;
9
9
  exports.resolveAndCleanProps = resolveAndCleanProps;
10
+ exports.removeStylesFromProps = removeStylesFromProps;
10
11
  const react_1 = __importDefault(require("react"));
11
12
  const lodash_es_1 = require("lodash-es");
12
13
  const ParameterParser_1 = require("../script-runner/ParameterParser");
@@ -158,7 +159,7 @@ function shouldKeep(when, componentState, appContext) {
158
159
  */
159
160
  function resolveAndCleanProps(props, extractValue, layoutCss = {}, resourceExtraction) {
160
161
  const { extractResourceUrl, resourceProps } = resourceExtraction !== null && resourceExtraction !== void 0 ? resourceExtraction : {};
161
- const cleanedProps = cleanStyles(props, layoutCss);
162
+ const cleanedProps = removeStylesFromProps(props, layoutCss);
162
163
  const resultProps = {};
163
164
  const result = Object.keys(cleanedProps).reduce((acc, propName) => {
164
165
  if (resourceProps && extractResourceUrl && resourceProps.includes(propName)) {
@@ -177,7 +178,7 @@ function resolveAndCleanProps(props, extractValue, layoutCss = {}, resourceExtra
177
178
  * @param layoutCss which style properties to remove
178
179
  * @returns only component-specific properties
179
180
  */
180
- function cleanStyles(nodeProps, layoutCss = {}) {
181
+ function removeStylesFromProps(nodeProps, layoutCss = {}) {
181
182
  if (nodeProps.hasOwnProperty("style")) {
182
183
  delete nodeProps["style"];
183
184
  }