dumi 2.0.4 → 2.0.5
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/dist/client/theme-api/AtomRenderer.d.ts +8 -0
- package/dist/client/theme-api/AtomRenderer.js +99 -0
- package/dist/client/theme-api/context.d.ts +1 -0
- package/dist/client/theme-api/context.js +1 -0
- package/dist/client/theme-api/index.d.ts +1 -0
- package/dist/client/theme-api/index.js +1 -0
- package/dist/features/tabs.js +3 -3
- package/dist/features/theme/index.js +26 -6
- package/dist/loaders/markdown/index.js +1 -0
- package/dist/loaders/markdown/transformer/remarkContainer.d.ts +1 -1
- package/dist/loaders/markdown/transformer/remarkContainer.js +4 -0
- package/package.json +1 -1
- package/theme-default/slots/RtlSwitch/index.less +6 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AtomAsset, ExamplePresetAsset } from 'dumi-assets-types';
|
|
2
|
+
import { type FC } from 'react';
|
|
3
|
+
interface IAtomRendererProps {
|
|
4
|
+
type: AtomAsset['type'];
|
|
5
|
+
value: ExamplePresetAsset['value'];
|
|
6
|
+
}
|
|
7
|
+
export declare const AtomRenderer: FC<IAtomRendererProps>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
|
|
9
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
|
|
11
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
+
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
14
|
+
|
|
15
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
16
|
+
|
|
17
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
+
|
|
19
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
20
|
+
|
|
21
|
+
import { useSiteData } from 'dumi';
|
|
22
|
+
import React from 'react';
|
|
23
|
+
|
|
24
|
+
function builtInProcessor(entity, entryExports) {
|
|
25
|
+
var mod;
|
|
26
|
+
|
|
27
|
+
switch (entity.$$__type) {
|
|
28
|
+
case 'function':
|
|
29
|
+
// eslint-disable-next-line no-eval
|
|
30
|
+
return eval(entity.$$__body.sourceCode);
|
|
31
|
+
|
|
32
|
+
case 'element':
|
|
33
|
+
// find child component from entry exports
|
|
34
|
+
mod = entity.$$__body.componentName.split('.').reduce(function (col, cur) {
|
|
35
|
+
return col[cur];
|
|
36
|
+
}, entryExports); // fallback to HTML tag
|
|
37
|
+
|
|
38
|
+
if (mod === undefined) return entity.$$__body.componentName; // support pure render for antd components
|
|
39
|
+
|
|
40
|
+
return '_InternalPanelDoNotUseOrYouWillBeFired' in mod ? mod._InternalPanelDoNotUseOrYouWillBeFired : mod;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function deepReplace(value, entityProcessor) {
|
|
45
|
+
// transform array props
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
return value.map(function (e) {
|
|
48
|
+
return deepReplace(e, entityProcessor);
|
|
49
|
+
});
|
|
50
|
+
} // transform element props
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if (_typeof(value) === 'object' && (value === null || value === void 0 ? void 0 : value.$$__type) === 'element') {
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
55
|
+
return translatePresetToReact(value.$$__body, entityProcessor);
|
|
56
|
+
} // transform pure object props
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if (_typeof(value) === 'object' && Object.prototype.toString.call(value) === '[object Object]') {
|
|
60
|
+
return Object.entries(value).reduce(function (col, _ref) {
|
|
61
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
62
|
+
key = _ref2[0],
|
|
63
|
+
value = _ref2[1];
|
|
64
|
+
|
|
65
|
+
return _objectSpread(_objectSpread({}, col), {}, _defineProperty({}, key, deepReplace(value, entityProcessor)));
|
|
66
|
+
}, {});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function translatePresetToReact(value, processor) {
|
|
73
|
+
var props = value.props,
|
|
74
|
+
size = value.size;
|
|
75
|
+
var Component = processor({
|
|
76
|
+
$$__type: 'element',
|
|
77
|
+
$$__body: value
|
|
78
|
+
});
|
|
79
|
+
return /*#__PURE__*/React.createElement(Component, deepReplace(_objectSpread(_objectSpread({}, props), {}, {
|
|
80
|
+
style: _objectSpread(_objectSpread({}, props.style), size)
|
|
81
|
+
}), processor));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export var AtomRenderer = function AtomRenderer(props) {
|
|
85
|
+
var _useSiteData = useSiteData(),
|
|
86
|
+
entryExports = _useSiteData.entryExports;
|
|
87
|
+
|
|
88
|
+
switch (props.type) {
|
|
89
|
+
case 'COMPONENT':
|
|
90
|
+
return translatePresetToReact(props.value, function (entity) {
|
|
91
|
+
// TODO: support custom processor
|
|
92
|
+
return builtInProcessor(entity, entryExports);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
default:
|
|
96
|
+
// TODO: handle FUNCTION type
|
|
97
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, props.type, " atom is not supported.");
|
|
98
|
+
}
|
|
99
|
+
};
|
|
@@ -4,6 +4,7 @@ import { type ComponentType } from 'react';
|
|
|
4
4
|
import type { ILocalesConfig, IPreviewerProps, IThemeConfig } from './types';
|
|
5
5
|
interface ISiteContext {
|
|
6
6
|
pkg: Partial<Record<keyof typeof PICKED_PKG_FIELDS, any>>;
|
|
7
|
+
entryExports: Record<string, any>;
|
|
7
8
|
demos: Record<string, {
|
|
8
9
|
component: ComponentType;
|
|
9
10
|
asset: IPreviewerProps['asset'];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createIntlCache, defineMessages, FormattedDate, FormattedDateParts, FormattedDisplayName, FormattedList, FormattedMessage, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, injectIntl, IntlContext, IntlProvider, RawIntlProvider, useIntl, } from 'react-intl';
|
|
2
|
+
export { AtomRenderer } from './AtomRenderer';
|
|
2
3
|
export { useSiteData } from './context';
|
|
3
4
|
export { DumiDemo } from './DumiDemo';
|
|
4
5
|
export { DumiDemoGrid } from './DumiDemoGrid';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createIntlCache, defineMessages, FormattedDate, FormattedDateParts, FormattedDisplayName, FormattedList, FormattedMessage, FormattedNumber, FormattedNumberParts, FormattedPlural, FormattedRelativeTime, FormattedTime, FormattedTimeParts, injectIntl, IntlContext, IntlProvider, RawIntlProvider, useIntl } from 'react-intl';
|
|
2
|
+
export { AtomRenderer } from "./AtomRenderer";
|
|
2
3
|
export { useSiteData } from "./context";
|
|
3
4
|
export { DumiDemo } from "./DumiDemo";
|
|
4
5
|
export { DumiDemoGrid } from "./DumiDemoGrid";
|
package/dist/features/tabs.js
CHANGED
|
@@ -47,7 +47,7 @@ var tabs_default = (api) => {
|
|
|
47
47
|
key: "addContentTab"
|
|
48
48
|
});
|
|
49
49
|
tabsFromPlugins.forEach((tab) => {
|
|
50
|
-
tab.id ?? (tab.id = `plugin-tab
|
|
50
|
+
tab.id ?? (tab.id = `plugin-tab-${tab.key}`);
|
|
51
51
|
tab.component = (0, import_plugin_utils.winPath)(tab.component);
|
|
52
52
|
});
|
|
53
53
|
return memo;
|
|
@@ -82,8 +82,8 @@ var tabs_default = (api) => {
|
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
|
-
tabs.push(...tabsFromPlugins.map((tab) => ({
|
|
86
|
-
index: tabs.length,
|
|
85
|
+
tabs.push(...tabsFromPlugins.map((tab, index) => ({
|
|
86
|
+
index: tabs.length + index,
|
|
87
87
|
key: tab.key,
|
|
88
88
|
id: tab.id,
|
|
89
89
|
file: tab.component
|
|
@@ -42,6 +42,12 @@ function getPkgThemePath(api) {
|
|
|
42
42
|
const pkgThemeName = getPkgThemeName(api);
|
|
43
43
|
return pkgThemeName && import_path.default.dirname(require.resolve(`${pkgThemeName}/package.json`, { paths: [api.cwd] }));
|
|
44
44
|
}
|
|
45
|
+
function getModuleExports(modulePath) {
|
|
46
|
+
return (0, import_bundler_utils.parseModuleSync)({
|
|
47
|
+
path: modulePath,
|
|
48
|
+
content: import_fs.default.readFileSync(modulePath, "utf-8")
|
|
49
|
+
})[1];
|
|
50
|
+
}
|
|
45
51
|
var theme_default = (api) => {
|
|
46
52
|
const defaultThemeData = (0, import_loader.default)(DEFAULT_THEME_PATH);
|
|
47
53
|
const pkgThemePath = getPkgThemePath(api);
|
|
@@ -60,7 +66,12 @@ var theme_default = (api) => {
|
|
|
60
66
|
api.registerPlugins([plugin]);
|
|
61
67
|
}
|
|
62
68
|
});
|
|
63
|
-
(0, import_derivative.safeExcludeInMFSU)(api, [
|
|
69
|
+
(0, import_derivative.safeExcludeInMFSU)(api, [
|
|
70
|
+
"dumi/theme-default",
|
|
71
|
+
"@ant-design/icons-svg",
|
|
72
|
+
"highlight-words-core",
|
|
73
|
+
getPkgThemeName(api)
|
|
74
|
+
].filter(Boolean).map((pkg) => new RegExp(pkg)));
|
|
64
75
|
api.register({
|
|
65
76
|
key: "modifyAppData",
|
|
66
77
|
before: "appData",
|
|
@@ -113,10 +124,7 @@ var theme_default = (api) => {
|
|
|
113
124
|
if (item.source === "dumi")
|
|
114
125
|
return;
|
|
115
126
|
let contents = [];
|
|
116
|
-
const
|
|
117
|
-
path: item.source,
|
|
118
|
-
content: import_fs.default.readFileSync(item.source, "utf-8")
|
|
119
|
-
});
|
|
127
|
+
const exports = getModuleExports(item.source);
|
|
120
128
|
if (exports.includes("default")) {
|
|
121
129
|
contents.push(`export { default } from '${item.source}';`);
|
|
122
130
|
}
|
|
@@ -130,6 +138,10 @@ var theme_default = (api) => {
|
|
|
130
138
|
});
|
|
131
139
|
});
|
|
132
140
|
});
|
|
141
|
+
const entryFile = api.config.resolve.entryFile && [import_path.default.resolve(api.cwd, api.config.resolve.entryFile)].find(import_fs.default.existsSync);
|
|
142
|
+
const entryExports = entryFile ? getModuleExports(entryFile) : [];
|
|
143
|
+
const hasDefaultExport = entryExports.includes("default");
|
|
144
|
+
const hasNamedExport = entryExports.some((exp) => exp !== "default");
|
|
133
145
|
api.writeTmpFile({
|
|
134
146
|
noPluginDir: true,
|
|
135
147
|
path: "dumi/theme/ContextWrapper.tsx",
|
|
@@ -137,7 +149,14 @@ var theme_default = (api) => {
|
|
|
137
149
|
import { useOutlet, history } from 'dumi';
|
|
138
150
|
import { SiteContext } from '${(0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/context"))}';
|
|
139
151
|
import { demos, components } from '../meta';
|
|
140
|
-
import { locales } from '../locales/config'
|
|
152
|
+
import { locales } from '../locales/config';${hasDefaultExport ? `
|
|
153
|
+
import entryDefaultExport from '${(0, import_plugin_utils.winPath)(entryFile)}';` : ""}${hasNamedExport ? `
|
|
154
|
+
import * as entryMemberExports from '${(0, import_plugin_utils.winPath)(entryFile)}';` : ""}
|
|
155
|
+
|
|
156
|
+
const entryExports = {
|
|
157
|
+
${hasDefaultExport ? "default: entryDefaultExport," : ""}
|
|
158
|
+
${hasNamedExport ? "...entryMemberExports," : ""}
|
|
159
|
+
};
|
|
141
160
|
|
|
142
161
|
export default function DumiContextWrapper() {
|
|
143
162
|
const outlet = useOutlet();
|
|
@@ -160,6 +179,7 @@ export default function DumiContextWrapper() {
|
|
|
160
179
|
return (
|
|
161
180
|
<SiteContext.Provider value={{
|
|
162
181
|
pkg: ${JSON.stringify(import_plugin_utils.lodash.pick(api.pkg, ...Object.keys(import_constants.PICKED_PKG_FIELDS)))},
|
|
182
|
+
entryExports,
|
|
163
183
|
demos,
|
|
164
184
|
components,
|
|
165
185
|
locales,
|
|
@@ -32,6 +32,10 @@ var VALID_CONTAINER_TYPES = ["info", "warning", "success", "error"];
|
|
|
32
32
|
({ visit, SKIP } = await import("unist-util-visit"));
|
|
33
33
|
})();
|
|
34
34
|
function remarkContainer() {
|
|
35
|
+
const data = this.data();
|
|
36
|
+
const micromarkExtensions = data.micromarkExtensions.find(({ flow, text }) => flow && "58" in flow && text && "58" in text);
|
|
37
|
+
delete micromarkExtensions.text;
|
|
38
|
+
micromarkExtensions.flow["58"].splice(1, 1);
|
|
35
39
|
return (tree) => {
|
|
36
40
|
visit(tree, (node, i, parent) => {
|
|
37
41
|
if (node.type === "containerDirective" && VALID_CONTAINER_TYPES.includes(node.name)) {
|
package/package.json
CHANGED