Просмотр исходного кода

WIP: move lsx components under @growi/app

Yuki Takei 3 лет назад
Родитель
Сommit
81f5ecef9f

+ 7 - 7
packages/plugin-lsx/src/client/js/components/Lsx.jsx → packages/app/src/components/ReactMarkdownComponents/Lsx/Lsx.jsx

@@ -1,20 +1,20 @@
-
 import React from 'react';
 
 import * as url from 'url';
 
 import { pathUtils } from '@growi/core';
-import axios from 'axios';
 import PropTypes from 'prop-types';
 
+import axios from '~/utils/axios';
+
 // eslint-disable-next-line no-unused-vars
-import { LsxContext } from '../util/LsxContext';
-import { TagCacheManagerFactory } from '../util/TagCacheManagerFactory';
 
 import { LsxListView } from './LsxPageList/LsxListView';
 import { PageNode } from './PageNode';
+import { LsxContext } from './lsx-context';
+import { getInstance as getTagCacheManager } from './tag-cache-manager';
 
-import styles from '../../css/index.css';
+import styles from './Lsx.module.scss';
 
 export class Lsx extends React.Component {
 
@@ -30,7 +30,7 @@ export class Lsx extends React.Component {
       errorMessage: '',
     };
 
-    this.tagCacheManager = TagCacheManagerFactory.getInstance();
+    this.tagCacheManager = getTagCacheManager();
   }
 
   async componentDidMount() {
@@ -234,7 +234,7 @@ export class Lsx extends React.Component {
   }
 
   render() {
-    return <div className="lsx">{this.renderContents()}</div>;
+    return <div className={`lsx ${styles.lsx}`}>{this.renderContents()}</div>;
   }
 
 }

+ 0 - 0
packages/plugin-lsx/src/client/css/index.css → packages/app/src/components/ReactMarkdownComponents/Lsx/Lsx.module.scss


+ 0 - 0
packages/plugin-lsx/src/client/js/util/Interceptor/LsxLogoutInterceptor.js → packages/app/src/components/ReactMarkdownComponents/Lsx/LsxLogoutInterceptor.js


+ 1 - 1
packages/plugin-lsx/src/client/js/components/LsxPageList/LsxListView.jsx → packages/app/src/components/ReactMarkdownComponents/Lsx/LsxPageList/LsxListView.jsx

@@ -2,8 +2,8 @@ import React from 'react';
 
 import PropTypes from 'prop-types';
 
-import { LsxContext } from '../../util/LsxContext';
 import { PageNode } from '../PageNode';
+import { LsxContext } from '../lsx-context';
 
 import { LsxPage } from './LsxPage';
 

+ 1 - 1
packages/plugin-lsx/src/client/js/components/LsxPageList/LsxPage.jsx → packages/app/src/components/ReactMarkdownComponents/Lsx/LsxPageList/LsxPage.jsx

@@ -4,8 +4,8 @@ import { pathUtils } from '@growi/core';
 import { PageListMeta } from '@growi/ui';
 import PropTypes from 'prop-types';
 
-import { LsxContext } from '../../util/LsxContext';
 import { PageNode } from '../PageNode';
+import { LsxContext } from '../lsx-context';
 
 import { PagePathWrapper } from './PagePathWrapper';
 

+ 0 - 0
packages/plugin-lsx/src/client/js/components/LsxPageList/PagePathWrapper.jsx → packages/app/src/components/ReactMarkdownComponents/Lsx/LsxPageList/PagePathWrapper.jsx


+ 0 - 0
packages/plugin-lsx/src/client/js/util/Interceptor/LsxPostRenderInterceptor.js → packages/app/src/components/ReactMarkdownComponents/Lsx/LsxPostRenderInterceptor.js


+ 0 - 0
packages/plugin-lsx/src/client/js/util/Interceptor/LsxPreRenderInterceptor.js → packages/app/src/components/ReactMarkdownComponents/Lsx/LsxPreRenderInterceptor.js


+ 0 - 0
packages/plugin-lsx/src/client/js/components/PageNode.js → packages/app/src/components/ReactMarkdownComponents/Lsx/PageNode.js


+ 10 - 15
packages/plugin-lsx/src/client/js/util/LsxContext.js → packages/app/src/components/ReactMarkdownComponents/Lsx/lsx-context.ts

@@ -6,19 +6,14 @@ const { TagContext, ArgsParser, OptionParser } = customTagUtils;
 
 export class LsxContext extends TagContext {
 
-  /**
-   * @param {object|TagContext|LsxContext} initArgs
-   */
-  constructor(initArgs) {
-    super(initArgs);
-
-    this.fromPagePath = null;
-
-    // initialized after parse()
-    this.isParsed = null;
-    this.pagePath = null;
-    this.options = {};
-  }
+  fromPagePath: string;
+
+  isParsed?: boolean;
+
+  pagePath?: string;
+
+  options?: any;
+
 
   parse() {
     if (this.isParsed) {
@@ -34,8 +29,8 @@ export class LsxContext extends TagContext {
     //   2: lsx(firstArgs, ...)
     //   3: fromPagePath
     const specifiedPath = this.options.prefix
-        || ((parsedResult.firstArgsValue === true) ? parsedResult.firstArgsKey : undefined)
-        || this.fromPagePath;
+        ?? ((parsedResult.firstArgsValue === true) ? parsedResult.firstArgsKey : undefined)
+        ?? this.fromPagePath;
 
     // resolve pagePath
     //   when `fromPagePath`=/hoge and `specifiedPath`=./fuga,

+ 0 - 0
packages/plugin-lsx/src/client/js/util/TagCacheManagerFactory.js → packages/app/src/components/ReactMarkdownComponents/Lsx/tag-cache-manager.ts


+ 2 - 0
packages/app/src/services/renderer/renderer.ts

@@ -16,6 +16,7 @@ import { PluggableList, Pluggable, PluginTuple } from 'unified';
 
 import { CodeBlock } from '~/components/ReactMarkdownComponents/CodeBlock';
 import { Header } from '~/components/ReactMarkdownComponents/Header';
+import { Lsx } from '~/components/ReactMarkdownComponents/Lsx/Lsx';
 import { NextLink } from '~/components/ReactMarkdownComponents/NextLink';
 import { RendererConfig } from '~/interfaces/services/renderer';
 import loggerFactory from '~/utils/logger';
@@ -282,6 +283,7 @@ const generateCommonOptions = (pagePath: string|undefined, config: RendererConfi
     components: {
       a: NextLink,
       code: CodeBlock,
+      lsx: Lsx,
     },
   };
 };

+ 1 - 1
packages/core/src/plugin/util/args-parser.js

@@ -6,7 +6,7 @@ class ArgsParser {
   /**
    * @typedef ParseArgsResult
    * @property {string} firstArgsKey - key of the first argument
-   * @property {string} firstArgsValue - value of the first argument
+   * @property {string|boolean} firstArgsValue - value of the first argument
    * @property {object} options - key of the first argument
    */