dumi 2.1.19 → 2.2.0-alpha.1
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/features/html2sketch.d.ts +3 -0
- package/dist/features/html2sketch.js +111 -0
- package/dist/preset.js +2 -1
- package/package.json +3 -1
- package/theme-default/builtins/Previewer/index.js +12 -3
- package/theme-default/locales/en-US.json +5 -0
- package/theme-default/locales/zh-CN.json +5 -1
- package/theme-default/slots/PreviewerActions/index.d.ts +2 -1
- package/theme-default/slots/PreviewerActions/index.js +68 -6
- package/theme-default/slots/PreviewerActions/index.less +15 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/features/html2sketch.ts
|
|
20
|
+
var html2sketch_exports = {};
|
|
21
|
+
__export(html2sketch_exports, {
|
|
22
|
+
default: () => html2sketch_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(html2sketch_exports);
|
|
25
|
+
var SCRIPT_URL = "https://gw.alipayobjects.com/os/lib/html2sketch/1.0.1/dist/html2sketch.min.js";
|
|
26
|
+
var CONTAINER_ATTR = "data-html2sketch-container";
|
|
27
|
+
var RUNTIME_CONFIG = "toSketchJSON";
|
|
28
|
+
var html2sketch_default = (api) => {
|
|
29
|
+
api.describe({
|
|
30
|
+
key: "html2sketch",
|
|
31
|
+
config: {
|
|
32
|
+
schema: (Joi) => Joi.object({ scriptUrl: Joi.string().optional() })
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
api.onGenerateFiles(() => {
|
|
36
|
+
if (api.config.html2sketch) {
|
|
37
|
+
api.writeTmpFile({
|
|
38
|
+
path: "msgExecutor.ts",
|
|
39
|
+
content: `import { getSketchJSON } from '.';
|
|
40
|
+
|
|
41
|
+
window.addEventListener('message', (ev) => {
|
|
42
|
+
if (ev.data.type === 'dumi.html2sketch.exec') {
|
|
43
|
+
const { value: opts, token } = ev.data;
|
|
44
|
+
|
|
45
|
+
getSketchJSON(document, opts).then((value) => {
|
|
46
|
+
window.postMessage({ type: 'dumi.html2sketch.done', value, token }, '*');
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
`
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
api.writeTmpFile({
|
|
54
|
+
path: "index.ts",
|
|
55
|
+
content: `import type { nodeToGroup, nodeToSymbol, SketchFormat } from 'html2sketch';
|
|
56
|
+
import { ApplyPluginsType } from 'dumi';
|
|
57
|
+
import { getPluginManager } from '@@/core/plugin';
|
|
58
|
+
|
|
59
|
+
const html2sketch = typeof window !== 'undefined' ? window.html2sketch as {
|
|
60
|
+
nodeToGroup: typeof nodeToGroup;
|
|
61
|
+
nodeToSymbol: typeof nodeToSymbol;
|
|
62
|
+
} : null;
|
|
63
|
+
|
|
64
|
+
async function toSketchJSON(
|
|
65
|
+
node: HTMLElement,
|
|
66
|
+
opts: { type: 'group' | 'symbol' },
|
|
67
|
+
) {
|
|
68
|
+
return opts.type === 'group'
|
|
69
|
+
? (await html2sketch.nodeToGroup(node)).toSketchJSON()
|
|
70
|
+
: (await html2sketch.nodeToSymbol(node)).toSketchJSON();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function runtimeToSketchJSON(
|
|
74
|
+
target: HTMLElement | Document,
|
|
75
|
+
opts: Parameters<typeof toSketchJSON>[1],
|
|
76
|
+
): ReturnType<typeof toSketchJSON> | Promise<null> {
|
|
77
|
+
return getPluginManager().applyPlugins({
|
|
78
|
+
key: '${RUNTIME_CONFIG}',
|
|
79
|
+
type: ApplyPluginsType.modify,
|
|
80
|
+
initialValue: null,
|
|
81
|
+
args: { target, opts },
|
|
82
|
+
async: true,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const getSketchJSON = ${api.config.html2sketch ? `async (
|
|
87
|
+
target: HTMLElement | Document,
|
|
88
|
+
opts: Parameters<typeof toSketchJSON>[1],
|
|
89
|
+
): ReturnType<typeof toSketchJSON> => {
|
|
90
|
+
let node = target;
|
|
91
|
+
|
|
92
|
+
// handle iframe demo & post message executor
|
|
93
|
+
if (!(target instanceof HTMLElement) || target.tagName === 'IFRAME') {
|
|
94
|
+
const doc = target instanceof HTMLIFrameElement ? target.contentDocument! : target;
|
|
95
|
+
|
|
96
|
+
node = doc.querySelector('[${CONTAINER_ATTR}], #${api.config.mountElementId}');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return await runtimeToSketchJSON(node, opts) || await toSketchJSON(node, opts);
|
|
100
|
+
}` : "null"};
|
|
101
|
+
`
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
api.addEntryImports(() => api.config.html2sketch ? { source: "@@/plugin-html2sketch/msgExecutor" } : []);
|
|
105
|
+
api.addHTMLHeadScripts(() => {
|
|
106
|
+
return api.config.html2sketch ? [api.config.html2sketch.scriptUrl || SCRIPT_URL] : [];
|
|
107
|
+
});
|
|
108
|
+
api.addRuntimePluginKey(() => api.config.html2sketch ? [RUNTIME_CONFIG] : []);
|
|
109
|
+
};
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {});
|
package/dist/preset.js
CHANGED
|
@@ -44,7 +44,8 @@ var preset_default = (api) => {
|
|
|
44
44
|
require.resolve("./features/parser"),
|
|
45
45
|
require.resolve("./features/assets"),
|
|
46
46
|
require.resolve("./features/exportStatic"),
|
|
47
|
-
require.resolve("./features/sitemap")
|
|
47
|
+
require.resolve("./features/sitemap"),
|
|
48
|
+
require.resolve("./features/html2sketch")
|
|
48
49
|
]
|
|
49
50
|
};
|
|
50
51
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.0-alpha.1",
|
|
4
4
|
"description": "📖 Documentation Generator of React Component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"generator",
|
|
@@ -87,6 +87,7 @@
|
|
|
87
87
|
"animated-scroll-to": "^2.3.0",
|
|
88
88
|
"classnames": "2.3.2",
|
|
89
89
|
"codesandbox": "^2.2.3",
|
|
90
|
+
"copy-to-clipboard": "^3.3.3",
|
|
90
91
|
"deepmerge": "^4.2.2",
|
|
91
92
|
"dumi-afx-deps": "^1.0.0-alpha.12",
|
|
92
93
|
"dumi-assets-types": "2.0.0-alpha.0",
|
|
@@ -101,6 +102,7 @@
|
|
|
101
102
|
"hast-util-to-string": "^2.0.0",
|
|
102
103
|
"heti": "^0.9.2",
|
|
103
104
|
"html-to-text": "^8.2.1",
|
|
105
|
+
"html2sketch": "^1.0.1",
|
|
104
106
|
"js-yaml": "^4.1.0",
|
|
105
107
|
"lodash.throttle": "^4.1.1",
|
|
106
108
|
"mdast-util-to-string": "^3.1.0",
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
1
3
|
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); }
|
|
2
4
|
|
|
3
5
|
import classnames from 'classnames';
|
|
4
6
|
import { useLocation } from 'dumi';
|
|
5
7
|
import PreviewerActions from 'dumi/theme/slots/PreviewerActions';
|
|
6
|
-
import React from 'react';
|
|
8
|
+
import React, { useRef } from 'react';
|
|
7
9
|
import "./index.less";
|
|
8
10
|
|
|
9
11
|
var Previewer = function Previewer(props) {
|
|
12
|
+
var _demoContainer$curren;
|
|
13
|
+
|
|
14
|
+
var demoContainer = useRef(null);
|
|
15
|
+
|
|
10
16
|
var _useLocation = useLocation(),
|
|
11
17
|
hash = _useLocation.hash;
|
|
12
18
|
|
|
@@ -24,7 +30,8 @@ var Previewer = function Previewer(props) {
|
|
|
24
30
|
},
|
|
25
31
|
"data-compact": props.compact || undefined,
|
|
26
32
|
"data-transform": props.transform || undefined,
|
|
27
|
-
"data-iframe": props.iframe || undefined
|
|
33
|
+
"data-iframe": props.iframe || undefined,
|
|
34
|
+
ref: demoContainer
|
|
28
35
|
}, props.iframe ? /*#__PURE__*/React.createElement("iframe", {
|
|
29
36
|
style: ['string', 'number'].includes(_typeof(props.iframe)) ? {
|
|
30
37
|
height: Number(props.iframe)
|
|
@@ -41,7 +48,9 @@ var Previewer = function Previewer(props) {
|
|
|
41
48
|
dangerouslySetInnerHTML: {
|
|
42
49
|
__html: props.description
|
|
43
50
|
}
|
|
44
|
-
})), /*#__PURE__*/React.createElement(PreviewerActions, props
|
|
51
|
+
})), /*#__PURE__*/React.createElement(PreviewerActions, _extends({}, props, {
|
|
52
|
+
demoContainer: props.iframe ? (_demoContainer$curren = demoContainer.current) === null || _demoContainer$curren === void 0 ? void 0 : _demoContainer$curren.firstElementChild : demoContainer.current
|
|
53
|
+
}))));
|
|
45
54
|
};
|
|
46
55
|
|
|
47
56
|
export default Previewer;
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
"header.social.linkedin": "Linkedin",
|
|
14
14
|
"previewer.actions.code.expand": "Show Code",
|
|
15
15
|
"previewer.actions.code.shrink": "Hide Code",
|
|
16
|
+
"previewer.actions.sketch": "Copy to Sketch app",
|
|
17
|
+
"previewer.actions.sketch.group": "Copy as Sketch Group",
|
|
18
|
+
"previewer.actions.sketch.symbol": "Copy as Sketch Symbol",
|
|
19
|
+
"previewer.actions.sketch.divider": "------------------------",
|
|
20
|
+
"previewer.actions.sketch.guide": "How to paste to Sketch?",
|
|
16
21
|
"previewer.actions.codesandbox": "Open in CodeSandbox",
|
|
17
22
|
"previewer.actions.codepen": "Open in CodePen (Not implemented)",
|
|
18
23
|
"previewer.actions.stackblitz": "Open in StackBlitz",
|
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
"previewer.actions.code.expand": "展开代码",
|
|
15
15
|
"previewer.actions.code.shrink": "收起代码",
|
|
16
16
|
"previewer.actions.codesandbox": "在 CodeSandbox 中打开",
|
|
17
|
-
"previewer.actions.
|
|
17
|
+
"previewer.actions.sketch": "拷贝到 Sketch",
|
|
18
|
+
"previewer.actions.sketch.group": "拷贝为 Sketch Group",
|
|
19
|
+
"previewer.actions.sketch.symbol": "拷贝为 Sketch Symbol",
|
|
20
|
+
"previewer.actions.sketch.divider": "----------------------",
|
|
21
|
+
"previewer.actions.sketch.guide": "如何粘贴到 SKetch?",
|
|
18
22
|
"previewer.actions.stackblitz": "在 StackBlitz 中打开",
|
|
19
23
|
"previewer.actions.separate": "在独立页面中打开",
|
|
20
24
|
"404.title": "页面未找到",
|
|
@@ -5,8 +5,9 @@ export interface IPreviewerActionsProps extends IPreviewerProps {
|
|
|
5
5
|
/**
|
|
6
6
|
* disabled actions
|
|
7
7
|
*/
|
|
8
|
-
disabledActions?: ('CSB' | '
|
|
8
|
+
disabledActions?: ('CSB' | 'STACKBLITZ' | 'EXTERNAL' | 'HTML2SKETCH')[];
|
|
9
9
|
forceShowCode?: boolean;
|
|
10
|
+
demoContainer: HTMLDivElement | HTMLIFrameElement;
|
|
10
11
|
}
|
|
11
12
|
declare const PreviewerActions: FC<IPreviewerActionsProps>;
|
|
12
13
|
export default PreviewerActions;
|
|
@@ -10,14 +10,16 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
10
10
|
|
|
11
11
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
12
|
|
|
13
|
-
import { ReactComponent as
|
|
14
|
-
|
|
13
|
+
import { ReactComponent as IconCheck } from '@ant-design/icons-svg/inline-svg/outlined/check.svg';
|
|
14
|
+
import { ReactComponent as IconCodeSandbox } from '@ant-design/icons-svg/inline-svg/outlined/code-sandbox.svg';
|
|
15
|
+
import { ReactComponent as IconSketch } from '@ant-design/icons-svg/inline-svg/outlined/sketch.svg';
|
|
15
16
|
import { ReactComponent as IconStackBlitz } from '@ant-design/icons-svg/inline-svg/outlined/thunderbolt.svg';
|
|
16
|
-
import
|
|
17
|
+
import copy from 'copy-to-clipboard';
|
|
18
|
+
import { getSketchJSON, openCodeSandbox, openStackBlitz, useIntl } from 'dumi';
|
|
17
19
|
import SourceCode from 'dumi/theme/builtins/SourceCode';
|
|
18
20
|
import PreviewerActionsExtra from 'dumi/theme/slots/PreviewerActionsExtra';
|
|
19
21
|
import Tabs from 'rc-tabs';
|
|
20
|
-
import React, { useState } from 'react';
|
|
22
|
+
import React, { useRef, useState } from 'react';
|
|
21
23
|
import "./index.less";
|
|
22
24
|
|
|
23
25
|
var IconCode = function IconCode() {
|
|
@@ -47,7 +49,7 @@ var IconExternalLink = function IconExternalLink() {
|
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
var PreviewerActions = function PreviewerActions(props) {
|
|
50
|
-
var _files$activeKey$0$ma, _props$disabledAction, _props$disabledAction2, _props$disabledAction3;
|
|
52
|
+
var _files$activeKey$0$ma, _props$disabledAction, _props$disabledAction2, _props$disabledAction3, _props$disabledAction4;
|
|
51
53
|
|
|
52
54
|
var intl = useIntl();
|
|
53
55
|
var files = Object.entries(props.asset.dependencies).filter(function (_ref) {
|
|
@@ -67,6 +69,13 @@ var PreviewerActions = function PreviewerActions(props) {
|
|
|
67
69
|
showCode = _useState4[0],
|
|
68
70
|
setShowCode = _useState4[1];
|
|
69
71
|
|
|
72
|
+
var copyTimer = useRef();
|
|
73
|
+
|
|
74
|
+
var _useState5 = useState(false),
|
|
75
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
76
|
+
isCopied = _useState6[0],
|
|
77
|
+
setIsCopied = _useState6[1];
|
|
78
|
+
|
|
70
79
|
var isSingleFile = files.length === 1;
|
|
71
80
|
var lang = ((_files$activeKey$0$ma = files[activeKey][0].match(/\.([^.]+)$/)) === null || _files$activeKey$0$ma === void 0 ? void 0 : _files$activeKey$0$ma[1]) || 'text';
|
|
72
81
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
@@ -89,7 +98,60 @@ var PreviewerActions = function PreviewerActions(props) {
|
|
|
89
98
|
onClick: function onClick() {
|
|
90
99
|
return openStackBlitz(props);
|
|
91
100
|
}
|
|
92
|
-
}, /*#__PURE__*/React.createElement(IconStackBlitz, null)), !((_props$disabledAction3 = props.disabledActions) !== null && _props$disabledAction3 !== void 0 && _props$disabledAction3.includes('
|
|
101
|
+
}, /*#__PURE__*/React.createElement(IconStackBlitz, null)), !((_props$disabledAction3 = props.disabledActions) !== null && _props$disabledAction3 !== void 0 && _props$disabledAction3.includes('HTML2SKETCH')) && getSketchJSON && /*#__PURE__*/React.createElement("span", {
|
|
102
|
+
className: "dumi-default-previewer-action-btn dumi-default-previewer-action-sketch",
|
|
103
|
+
"data-dumi-tooltip": intl.formatMessage({
|
|
104
|
+
id: 'previewer.actions.sketch'
|
|
105
|
+
}),
|
|
106
|
+
"data-copied": isCopied || undefined
|
|
107
|
+
}, isCopied ? /*#__PURE__*/React.createElement(IconCheck, null) : /*#__PURE__*/React.createElement(IconSketch, null), /*#__PURE__*/React.createElement("select", {
|
|
108
|
+
value: "",
|
|
109
|
+
onChange: function onChange(ev) {
|
|
110
|
+
var type = ev.target.value;
|
|
111
|
+
|
|
112
|
+
switch (type) {
|
|
113
|
+
case 'group':
|
|
114
|
+
case 'symbol':
|
|
115
|
+
getSketchJSON(props.demoContainer, {
|
|
116
|
+
type: type
|
|
117
|
+
}).then(function (data) {
|
|
118
|
+
copy(JSON.stringify(data));
|
|
119
|
+
setIsCopied(true);
|
|
120
|
+
clearTimeout(copyTimer.current);
|
|
121
|
+
copyTimer.current = window.setTimeout(function () {
|
|
122
|
+
return setIsCopied(false);
|
|
123
|
+
}, 2000);
|
|
124
|
+
});
|
|
125
|
+
break;
|
|
126
|
+
|
|
127
|
+
case 'guide':
|
|
128
|
+
window.open('https://d.umijs.org/config#html2sketch');
|
|
129
|
+
break;
|
|
130
|
+
|
|
131
|
+
default:
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}, /*#__PURE__*/React.createElement("option", {
|
|
135
|
+
value: "",
|
|
136
|
+
hidden: true
|
|
137
|
+
}), /*#__PURE__*/React.createElement("option", {
|
|
138
|
+
value: "group"
|
|
139
|
+
}, intl.formatMessage({
|
|
140
|
+
id: 'previewer.actions.sketch.group'
|
|
141
|
+
})), /*#__PURE__*/React.createElement("option", {
|
|
142
|
+
value: "symbol"
|
|
143
|
+
}, intl.formatMessage({
|
|
144
|
+
id: 'previewer.actions.sketch.symbol'
|
|
145
|
+
})), /*#__PURE__*/React.createElement("option", {
|
|
146
|
+
value: "-",
|
|
147
|
+
disabled: true
|
|
148
|
+
}, intl.formatMessage({
|
|
149
|
+
id: 'previewer.actions.sketch.divider'
|
|
150
|
+
})), /*#__PURE__*/React.createElement("option", {
|
|
151
|
+
value: "guide"
|
|
152
|
+
}, intl.formatMessage({
|
|
153
|
+
id: 'previewer.actions.sketch.guide'
|
|
154
|
+
})))), !((_props$disabledAction4 = props.disabledActions) !== null && _props$disabledAction4 !== void 0 && _props$disabledAction4.includes('EXTERNAL')) && /*#__PURE__*/React.createElement("a", {
|
|
93
155
|
target: "_blank",
|
|
94
156
|
rel: "noreferrer",
|
|
95
157
|
href: props.demoUrl,
|
|
@@ -51,6 +51,21 @@
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
&-action-sketch {
|
|
55
|
+
> select {
|
|
56
|
+
position: absolute;
|
|
57
|
+
appearance: none;
|
|
58
|
+
width: 100%;
|
|
59
|
+
height: 100%;
|
|
60
|
+
opacity: 0;
|
|
61
|
+
cursor: pointer;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
&[data-copied] > svg {
|
|
65
|
+
fill: @c-success;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
54
69
|
&-tabs {
|
|
55
70
|
position: relative;
|
|
56
71
|
padding: 0 12px;
|