@antv/dumi-theme-antv 0.3.0-beta.1 → 0.3.0-beta.3

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/pages/404.js CHANGED
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  import { Header } from "../slots/Header";
2
3
  import { NotFound as NotFoundPage } from "../slots/404";
3
4
  import { Footer } from "../slots/Footer";
@@ -4,4 +4,9 @@
4
4
  * @returns {ExamplesPage.ExampleTopic[]} 案例主题列表
5
5
  * @author YuZhanglong <loveyzl1123@gmail.com>
6
6
  */
7
- export declare const getExamplesPageTopics: () => ExamplesPage.ExampleTopic[];
7
+ export declare const getExamplesPageTopics: (exampleTopics: ExamplesPage.ExampleTopic[]) => {
8
+ id: string;
9
+ title: ExamplesPage.ExampleTopic;
10
+ icon: ExamplesPage.ExampleTopic;
11
+ examples: ExamplesPage.Example[];
12
+ }[];
@@ -35,7 +35,7 @@ var getExampleDemos = (exampleDir) => {
35
35
  const demoMeta = JSON.parse(demoMetaJSON).demos;
36
36
  const demos = demoMeta.map((item) => {
37
37
  const { title, screenshot, filename, new: isNew } = item;
38
- const id = filename.replace(/\.tsx?$/, "");
38
+ const id = filename.replace(/\.tsx?$/, "").replace(/\.ts?$/, "").replace(/\.jsx?$/, "").replace(/\.js?$/, "");
39
39
  return {
40
40
  id,
41
41
  screenshot,
@@ -68,13 +68,21 @@ var getTopicExamples = (topicPath) => {
68
68
  return example;
69
69
  });
70
70
  };
71
- var getExamplesPageTopics = () => {
72
- const exampleTopicPaths = glob.sync(`${examplesBaseDir}/*`);
73
- return exampleTopicPaths.map((topicPath) => {
74
- const topicMetaPath = path.resolve(topicPath, "meta.js");
75
- const topicMeta = require(topicMetaPath);
76
- topicMeta.examples = getTopicExamples(topicPath);
77
- return topicMeta;
71
+ var getExamplesPageTopics = (exampleTopics) => {
72
+ return exampleTopics.map(({ id, slug, title, icon }) => {
73
+ const nid = id || slug;
74
+ let examples = [];
75
+ try {
76
+ examples = getTopicExamples(path.join(examplesBaseDir, nid));
77
+ } catch (e) {
78
+ console.warn(e);
79
+ }
80
+ return {
81
+ id: nid,
82
+ title,
83
+ icon,
84
+ examples
85
+ };
78
86
  });
79
87
  };
80
88
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,7 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
18
 
22
19
  // src/plugin/index.ts
@@ -26,52 +23,52 @@ __export(plugin_exports, {
26
23
  });
27
24
  module.exports = __toCommonJS(plugin_exports);
28
25
  var import_examples = require("./examples");
29
- function generateMetaJSON() {
30
- const res = (0, import_examples.getExamplesPageTopics)();
31
- return {
32
- exampleTopics: res
33
- };
34
- }
26
+ var import_utils = require("./utils");
35
27
  var plugin_default = (api) => {
36
28
  api.describe({ key: `dumi-theme:${require("../../package.json").name}` });
37
29
  const pages = [
38
30
  {
39
31
  id: "dumi-theme-antv-example-list-zh",
40
32
  path: "/examples/",
41
- file: require.resolve("../pages/Examples/index.tsx")
33
+ file: (0, import_utils.myResolve)("../pages/Examples/index.tsx")
42
34
  },
43
35
  {
44
36
  id: "dumi-theme-antv-example-list-lang",
45
37
  path: "/:language/examples/",
46
- file: require.resolve("../pages/Examples/index.tsx")
38
+ file: (0, import_utils.myResolve)("../pages/Examples/index.tsx")
47
39
  },
48
40
  {
49
41
  id: "dumi-theme-antv-single-example-zh",
50
42
  path: "/examples/:topic/:example",
51
- file: require.resolve("../pages/Example/index.tsx")
43
+ file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
52
44
  },
53
45
  {
54
46
  id: "dumi-theme-antv-single-example-lang",
55
47
  path: "/:language/examples/:topic/:example",
56
- file: require.resolve("../pages/Example/index.tsx")
48
+ file: (0, import_utils.myResolve)("../pages/Example/index.tsx")
57
49
  }
58
50
  ];
59
- const contextFilePath = require.resolve("../context.ts");
51
+ const contextFilePath = (0, import_utils.myResolve)("../context.ts");
60
52
  api.onGenerateFiles(() => {
61
53
  api.writeTmpFile({
62
54
  noPluginDir: true,
63
55
  path: "theme-antv/ContextWrapper.tsx",
64
56
  content: `
65
- import { useOutlet } from 'dumi';
57
+ import React from 'react';
58
+ import { useOutlet, useSiteData } from 'dumi';
66
59
  import { ThemeAntVContext } from '${contextFilePath}';
67
60
 
68
61
  export default function ThemeAntVContextWrapper() {
69
62
  const outlet = useOutlet();
63
+ // const { themeConfig } = useSiteData();
64
+ // const exampleTopics = themeConfig?.examples || [];
70
65
 
71
66
  return (
72
67
  <ThemeAntVContext.Provider
73
68
  value={{
74
- meta: ${JSON.stringify(generateMetaJSON())}
69
+ meta: ${JSON.stringify({
70
+ exampleTopics: (0, import_examples.getExamplesPageTopics)(api.config.themeConfig.examples || [])
71
+ })}
75
72
  }}
76
73
  >
77
74
  {outlet}
@@ -95,7 +92,7 @@ export default function ThemeAntVContextWrapper() {
95
92
  parentId: "DocLayout"
96
93
  };
97
94
  });
98
- routes["404"].file = require.resolve("../pages/404.tsx");
95
+ routes["404"].file = (0, import_utils.myResolve)("../pages/404.tsx");
99
96
  return routes;
100
97
  });
101
98
  };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 自定义的 resolve 函数,优先找 tsx,如果找不到则找对应的 js 文件。
3
+ * 因为 dumi-theme-antv 编译之后,全部变成 js 文件
4
+ */
5
+ export declare function myResolve(p: string, alternateExts?: string[]): string;
@@ -0,0 +1,46 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/plugin/utils.ts
23
+ var utils_exports = {};
24
+ __export(utils_exports, {
25
+ myResolve: () => myResolve
26
+ });
27
+ module.exports = __toCommonJS(utils_exports);
28
+ var path = __toESM(require("path"));
29
+ function myResolve(p, alternateExts = [".js"]) {
30
+ const extname2 = path.extname(p);
31
+ const pathname = p.slice(0, p.length - extname2.length);
32
+ const exts = [extname2, ...alternateExts];
33
+ for (let i = 0; i < exts.length; i++) {
34
+ const ext = exts[i];
35
+ const fullpath = `${pathname}${ext}`;
36
+ try {
37
+ return require.resolve(fullpath);
38
+ } catch (e) {
39
+ }
40
+ }
41
+ return "";
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ myResolve
46
+ });
@@ -18,9 +18,12 @@
18
18
  height: 100%;
19
19
  position: relative;
20
20
 
21
- .playgroundScriptContainer {
21
+ :global(#playgroundScriptContainer) {
22
22
  flex: 1;
23
23
  position: relative;
24
+ width: 100%;
25
+ height: 100%;
26
+
24
27
  :global(#container) {
25
28
  width: 100%;
26
29
  height: 100%;
@@ -24,8 +24,8 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
24
24
 
25
25
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
26
26
 
27
- import { Input, Menu, Tooltip } from 'antd';
28
27
  import React, { useEffect, useRef, useState } from 'react';
28
+ import { Input, Menu, Tooltip } from 'antd';
29
29
  import { useLocale } from 'dumi';
30
30
  import { createFromIconfontCN, SearchOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
31
31
  import classNames from 'classnames';
package/dist/typings.d.ts CHANGED
@@ -104,10 +104,13 @@ declare namespace ExamplesPage {
104
104
  /** 案例主题 */
105
105
  export interface ExampleTopic {
106
106
  /**
107
- * id
107
+ * id 和文件夹目录名保持一致
108
108
  */
109
109
  id: string;
110
-
110
+ /**
111
+ * slug 和 id 一样,兼容旧配置
112
+ */
113
+ slug?: string;
111
114
  /**
112
115
  * 标题
113
116
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.3.0-beta.1",
3
+ "version": "0.3.0-beta.3",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "types": "dist/types.d.ts",
6
6
  "scripts": {