From c4bccc3619c60558dc78cd76e7dab9179645698a Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Tue, 7 Nov 2023 16:21:05 +0900 Subject: [PATCH 01/16] add short term and auto type --- src/components/Term/auto-type.js | 81 ++++++++++++++++++++++++ src/components/Term/index.jsx | 13 +++- src/components/Term/short-definitions.js | 79 +++++++++++++++++++++++ 3 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 src/components/Term/auto-type.js create mode 100644 src/components/Term/short-definitions.js diff --git a/src/components/Term/auto-type.js b/src/components/Term/auto-type.js new file mode 100644 index 000000000..c375c72eb --- /dev/null +++ b/src/components/Term/auto-type.js @@ -0,0 +1,81 @@ +/* +----- Memo ------- +> both shortened / full type is allowed +> only match literal terms, + therefore not for explanation terms +> doesn't need to be one text per tye, + but has to be one type per text +> data is stored as Map. use Map#get +*/ + +const autoType = new Map([ + ["拡張子", "fileExtension"], + ["フォーク", "fork"], + ["Git", "git"], + ["GitHub", "github"], + ["Gitpod", "gitpod"], + ["リポジトリ", "repository"], + ["HTML", "html"], + ["JavaScript", "javascript"], + ["開始タグ", "startTag"], + ["タグ", "tag"], + ["属性", "attribute"], + ["HTML 要素", "element"], + ["要素", "element"], + ["終了タグ", "endTag"], + ["CSS", "css"], + ["style属性", "styleAttribute"], + ["文", "statement"], + ["値", "value"], + ["文字列", "string"], + ["演算子", "operator"], + ["式", "expression"], + ["評価", "evaluation"], + ["変数", "variable"], + ["宣言", "declaration"] + ["代入", "assignment"], + ["キャメルケース", "camelCase"], + ["スネークケース", "snakeCase"], + ["パスカルケース", "pascalCase"], + ["真偽値", "bool"], + ["if 文", "ifStatement"], + ["if文", "ifStatement"], + ["制御構造", "controlFlow"], + ["関数", "function"], + ["引数", "parameter"], + ["渡す", "pass"], + ["戻り値", "returnValue"], + ["返り値", "returnValue"], + ["返す", "return"], + ["スコープ", "scope"], + ["モジュール化", "modularization"], + ["オブジェクト", "object"], + ["プリミティブ", "primitive"], + ["プロパティ", "property"], + ["DOM", "dom"], + ["イベント", "events"], + ["イベントハンドラ", "eventHandler"], + ["参照", "reference"], + ["副作用", "sideEffects"], + ["純粋関数", "pureFunction"], + ["参照透過性", "referenceTransparency"], + ["クラス", "class"], + ["インスタンス", "instance"], + ["コンストラクタ", "constructor"], + ["メソッド", "method"], + ["アロー関数", "arrowFunction"], + ["コールバック関数", "callBackFunction"], + ["モジュール", "module"], + ["ライブラリ", "library"], + ["JSON", "json"], + ["クエリ文字列", "queryString"], + ["npx コマンド", "npxCommand"], + ["npxコマンド", "npxCommand"], + ["非同期処理", "asyncProcess"], + ["API", "api"], + ["スレッド", "thread"], + ["トランスパイル", "transpile"] + ["モジュールバンドラ", "moduleBundler"], + ["JSX", "jsx"],]) + +export default autoType; diff --git a/src/components/Term/index.jsx b/src/components/Term/index.jsx index e042a14fd..b45d10e56 100644 --- a/src/components/Term/index.jsx +++ b/src/components/Term/index.jsx @@ -6,14 +6,23 @@ import "tippy.js/dist/tippy.css"; import "tippy.js/themes/material.css"; import styles from "./styles.module.css"; import definitions from "./definitions"; +import shortDefinitions from "./short-definitions.js"; +import autoType from "./auto-type.js"; /** * @param {Object} props * @param {keyof typeof definitions} props.type * @param {React.ReactNode} props.children */ -export default function Term({ type, children }) { - const term = definitions.terms[type]; +export default function Term({ type = null, children }) { + if (type === null) type = autoType.get(children.textContent); + if (!type) + throw new Error( + `Problem: Term ${children.textContent} is not defined. + Solution: explicitly specify term type, or add type definition to auto-type.js`, + ); + const term = + definitions.terms[type] || definitions.terms[shortDefinitions[type]]; if (!term) throw new Error(`Type ${type} is not defined.`); const referencePageTitle = definitions.referencePageTitles[term.referencePage]; diff --git a/src/components/Term/short-definitions.js b/src/components/Term/short-definitions.js new file mode 100644 index 000000000..4501b6081 --- /dev/null +++ b/src/components/Term/short-definitions.js @@ -0,0 +1,79 @@ +export default { + target: { + js: "javascript", + jsStatement: "javascriptStatement", + statement: "javascriptStatement", + jsValue: "javascriptValue", + value: "javascriptValue", + jsString: "javascriptString", + string: "javascriptString", + jsNumber: "javascriptNumber", + number: "javascriptNumber", + jsOperator: "javascriptOperator", + operator: "javascriptOperator", + jsExpression: "javascriptExpression", + expression: "javascriptExpression", + jsEvaluation: "javascriptEvaluation", + evaluation: "javascriptEvaluation", + jsVariable: "javascriptVariable", + variable: "javascriptVariable", + jsDeclaration: "javascriptDeclaration", + declaration: "javascriptDeclaration", + jsAssignment: "javascriptAssignment", + assignment: "javascriptAssignment", + jsBoolean: "javascriptBoolean", + jsBool: "javascriptBoolean", + boolean: "javascriptBoolean", + bool: "javascriptBoolean", + jsIfStatement: "javascriptIfStatement", + jsIf: "javascriptIfStatement", + ifStatement: "javascriptIfStatement", + if: "javascriptIfStatement", + jsFunction: "javascriptFunction", + function: "javascriptFunction", + jsParameter: "javascriptParameter", + parameter: "javascriptParameter", + jsPass: "javascriptPass", + pass: "javascriptPass", + jsReturnValue: "javascriptReturnValue", + returnValue: "javascriptReturnValue", + jsReturn: "javascriptReturn", + return: "javascriptReturn", + jsScope: "javascriptScope", + scope: "javascriptScope", + jsModularization: "javascriptModularization", + modularization: "javascriptModularization", + jsObject: "javascriptObject", + object: "javascriptObject", + jsPrimitive: "javascriptPrimitive", + primitive: "javascriptPrimitive", + jsProperty: "javascriptProperty", + property: "javascriptProperty", + jsReference: "javascriptReference", + reference: "javascriptReference", + jsSideEffects: "javascriptSideEffects", + jsSideEffect: "javascriptSideEffects", + sideEffects: "javascriptSideEffects", + sideEffect: "javascriptSideEffects", + jsPureFunction: "javascriptPureFunction", + pureFunction: "javascriptPureFunction", + jsReferenceTransparency: "javascriptReferenceTransparency", + referenceTransparency: "javascriptTransparency", + jsClass: "javascriptClass", + class: "javascriptClass", + jsInstance: "javascriptInstance", + instance: "javascriptInstance", + jsConstructor: "javascriptConstructor", + constructor: "javascriptConstructor", + jsMethod: "javascriptMethod", + method: "javascriptMethod", + jsModule: "javascriptModule", + module: "javascriptModule", + asyncProcess: "asynchronousProcess", + jsTruthyFalsy: "javascriptTruthyFalsy", + jsTruthy: "javascriptTruthyFalsy", + jsFalsy: "javascriptTruthyFalsy", + truthy: "javascriptTruthyFalsy", + falsy: "javascriptTruthyFalsy", + }, +}; \ No newline at end of file From ace426d702e171dbb5366027282b2c0ae371a489 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Tue, 7 Nov 2023 17:00:09 +0900 Subject: [PATCH 02/16] =?UTF-8?q?=E3=83=90=E3=82=B0=E4=BF=AE=E6=AD=A3=20"I?= =?UTF-8?q?terator=20value=20undefined=20is=20not=20an=20iterable=20object?= =?UTF-8?q?"=20build=E3=81=AF=E3=81=AA=E3=81=9C=E3=81=8B=E9=80=9A=E3=82=89?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=81=91=E3=81=A9=E8=87=AA=E5=88=86=E3=81=AE?= =?UTF-8?q?=E3=81=9B=E3=81=84=E3=81=98=E3=82=83=E3=81=AA=E3=81=84=E3=81=A7?= =?UTF-8?q?=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Term/auto-type.js | 6 +++--- src/components/Term/index.jsx | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/Term/auto-type.js b/src/components/Term/auto-type.js index c375c72eb..666dd580a 100644 --- a/src/components/Term/auto-type.js +++ b/src/components/Term/auto-type.js @@ -32,7 +32,7 @@ const autoType = new Map([ ["式", "expression"], ["評価", "evaluation"], ["変数", "variable"], - ["宣言", "declaration"] + ["宣言", "declaration"], ["代入", "assignment"], ["キャメルケース", "camelCase"], ["スネークケース", "snakeCase"], @@ -74,8 +74,8 @@ const autoType = new Map([ ["非同期処理", "asyncProcess"], ["API", "api"], ["スレッド", "thread"], - ["トランスパイル", "transpile"] + ["トランスパイル", "transpile"], ["モジュールバンドラ", "moduleBundler"], - ["JSX", "jsx"],]) + ["JSX", "jsx"]]) export default autoType; diff --git a/src/components/Term/index.jsx b/src/components/Term/index.jsx index b45d10e56..7cf5b736b 100644 --- a/src/components/Term/index.jsx +++ b/src/components/Term/index.jsx @@ -15,7 +15,12 @@ import autoType from "./auto-type.js"; * @param {React.ReactNode} props.children */ export default function Term({ type = null, children }) { - if (type === null) type = autoType.get(children.textContent); + function unwrap(mdx) { + if (typeof mdx === "string") return mdx; + else return unwrap(mdx.props.children); + } + if (type === null || type === undefined) + type = autoType.get(unwrap(children)); if (!type) throw new Error( `Problem: Term ${children.textContent} is not defined. From 32b8bd4fe9308026c1e4e90807f2d38746b5cdc5 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Tue, 7 Nov 2023 17:03:14 +0900 Subject: [PATCH 03/16] add "how to use" --- src/components/Term/auto-type.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/Term/auto-type.js b/src/components/Term/auto-type.js index 666dd580a..dec3cb452 100644 --- a/src/components/Term/auto-type.js +++ b/src/components/Term/auto-type.js @@ -1,10 +1,13 @@ /* ----- Memo ------- + # Adding auto terms > both shortened / full type is allowed > only match literal terms, therefore not for explanation terms > doesn't need to be one text per tye, but has to be one type per text + + # Usage > data is stored as Map. use Map#get */ From 8ed596c00420a198c0b75142d3add6dec724ce7d Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Tue, 7 Nov 2023 17:08:04 +0900 Subject: [PATCH 04/16] =?UTF-8?q?=E5=8B=95=E3=81=8B=E3=81=AA=E3=81=8B?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Term/index.jsx | 2 +- src/components/Term/short-definitions.js | 152 +++++++++++------------ 2 files changed, 76 insertions(+), 78 deletions(-) diff --git a/src/components/Term/index.jsx b/src/components/Term/index.jsx index 7cf5b736b..3f843f3db 100644 --- a/src/components/Term/index.jsx +++ b/src/components/Term/index.jsx @@ -23,7 +23,7 @@ export default function Term({ type = null, children }) { type = autoType.get(unwrap(children)); if (!type) throw new Error( - `Problem: Term ${children.textContent} is not defined. + `Problem: Term ${children.textContent} is not defined in AutoType. Solution: explicitly specify term type, or add type definition to auto-type.js`, ); const term = diff --git a/src/components/Term/short-definitions.js b/src/components/Term/short-definitions.js index 4501b6081..111d0ed89 100644 --- a/src/components/Term/short-definitions.js +++ b/src/components/Term/short-definitions.js @@ -1,79 +1,77 @@ export default { - target: { - js: "javascript", - jsStatement: "javascriptStatement", - statement: "javascriptStatement", - jsValue: "javascriptValue", - value: "javascriptValue", - jsString: "javascriptString", - string: "javascriptString", - jsNumber: "javascriptNumber", - number: "javascriptNumber", - jsOperator: "javascriptOperator", - operator: "javascriptOperator", - jsExpression: "javascriptExpression", - expression: "javascriptExpression", - jsEvaluation: "javascriptEvaluation", - evaluation: "javascriptEvaluation", - jsVariable: "javascriptVariable", - variable: "javascriptVariable", - jsDeclaration: "javascriptDeclaration", - declaration: "javascriptDeclaration", - jsAssignment: "javascriptAssignment", - assignment: "javascriptAssignment", - jsBoolean: "javascriptBoolean", - jsBool: "javascriptBoolean", - boolean: "javascriptBoolean", - bool: "javascriptBoolean", - jsIfStatement: "javascriptIfStatement", - jsIf: "javascriptIfStatement", - ifStatement: "javascriptIfStatement", - if: "javascriptIfStatement", - jsFunction: "javascriptFunction", - function: "javascriptFunction", - jsParameter: "javascriptParameter", - parameter: "javascriptParameter", - jsPass: "javascriptPass", - pass: "javascriptPass", - jsReturnValue: "javascriptReturnValue", - returnValue: "javascriptReturnValue", - jsReturn: "javascriptReturn", - return: "javascriptReturn", - jsScope: "javascriptScope", - scope: "javascriptScope", - jsModularization: "javascriptModularization", - modularization: "javascriptModularization", - jsObject: "javascriptObject", - object: "javascriptObject", - jsPrimitive: "javascriptPrimitive", - primitive: "javascriptPrimitive", - jsProperty: "javascriptProperty", - property: "javascriptProperty", - jsReference: "javascriptReference", - reference: "javascriptReference", - jsSideEffects: "javascriptSideEffects", - jsSideEffect: "javascriptSideEffects", - sideEffects: "javascriptSideEffects", - sideEffect: "javascriptSideEffects", - jsPureFunction: "javascriptPureFunction", - pureFunction: "javascriptPureFunction", - jsReferenceTransparency: "javascriptReferenceTransparency", - referenceTransparency: "javascriptTransparency", - jsClass: "javascriptClass", - class: "javascriptClass", - jsInstance: "javascriptInstance", - instance: "javascriptInstance", - jsConstructor: "javascriptConstructor", - constructor: "javascriptConstructor", - jsMethod: "javascriptMethod", - method: "javascriptMethod", - jsModule: "javascriptModule", - module: "javascriptModule", - asyncProcess: "asynchronousProcess", - jsTruthyFalsy: "javascriptTruthyFalsy", - jsTruthy: "javascriptTruthyFalsy", - jsFalsy: "javascriptTruthyFalsy", - truthy: "javascriptTruthyFalsy", - falsy: "javascriptTruthyFalsy", - }, + js: "javascript", + jsStatement: "javascriptStatement", + statement: "javascriptStatement", + jsValue: "javascriptValue", + value: "javascriptValue", + jsString: "javascriptString", + string: "javascriptString", + jsNumber: "javascriptNumber", + number: "javascriptNumber", + jsOperator: "javascriptOperator", + operator: "javascriptOperator", + jsExpression: "javascriptExpression", + expression: "javascriptExpression", + jsEvaluation: "javascriptEvaluation", + evaluation: "javascriptEvaluation", + jsVariable: "javascriptVariable", + variable: "javascriptVariable", + jsDeclaration: "javascriptDeclaration", + declaration: "javascriptDeclaration", + jsAssignment: "javascriptAssignment", + assignment: "javascriptAssignment", + jsBoolean: "javascriptBoolean", + jsBool: "javascriptBoolean", + boolean: "javascriptBoolean", + bool: "javascriptBoolean", + jsIfStatement: "javascriptIfStatement", + jsIf: "javascriptIfStatement", + ifStatement: "javascriptIfStatement", + if: "javascriptIfStatement", + jsFunction: "javascriptFunction", + function: "javascriptFunction", + jsParameter: "javascriptParameter", + parameter: "javascriptParameter", + jsPass: "javascriptPass", + pass: "javascriptPass", + jsReturnValue: "javascriptReturnValue", + returnValue: "javascriptReturnValue", + jsReturn: "javascriptReturn", + return: "javascriptReturn", + jsScope: "javascriptScope", + scope: "javascriptScope", + jsModularization: "javascriptModularization", + modularization: "javascriptModularization", + jsObject: "javascriptObject", + object: "javascriptObject", + jsPrimitive: "javascriptPrimitive", + primitive: "javascriptPrimitive", + jsProperty: "javascriptProperty", + property: "javascriptProperty", + jsReference: "javascriptReference", + reference: "javascriptReference", + jsSideEffects: "javascriptSideEffects", + jsSideEffect: "javascriptSideEffects", + sideEffects: "javascriptSideEffects", + sideEffect: "javascriptSideEffects", + jsPureFunction: "javascriptPureFunction", + pureFunction: "javascriptPureFunction", + jsReferenceTransparency: "javascriptReferenceTransparency", + referenceTransparency: "javascriptTransparency", + jsClass: "javascriptClass", + class: "javascriptClass", + jsInstance: "javascriptInstance", + instance: "javascriptInstance", + jsConstructor: "javascriptConstructor", + constructor: "javascriptConstructor", + jsMethod: "javascriptMethod", + method: "javascriptMethod", + jsModule: "javascriptModule", + module: "javascriptModule", + asyncProcess: "asynchronousProcess", + jsTruthyFalsy: "javascriptTruthyFalsy", + jsTruthy: "javascriptTruthyFalsy", + jsFalsy: "javascriptTruthyFalsy", + truthy: "javascriptTruthyFalsy", + falsy: "javascriptTruthyFalsy" }; \ No newline at end of file From fd933d39afa3effcc2a73b8d7b24830d1283724b Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Tue, 7 Nov 2023 22:18:36 +0900 Subject: [PATCH 05/16] prettier format --- src/components/Term/auto-type.js | 3 ++- src/components/Term/short-definitions.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/Term/auto-type.js b/src/components/Term/auto-type.js index dec3cb452..6448f0531 100644 --- a/src/components/Term/auto-type.js +++ b/src/components/Term/auto-type.js @@ -79,6 +79,7 @@ const autoType = new Map([ ["スレッド", "thread"], ["トランスパイル", "transpile"], ["モジュールバンドラ", "moduleBundler"], - ["JSX", "jsx"]]) + ["JSX", "jsx"], +]); export default autoType; diff --git a/src/components/Term/short-definitions.js b/src/components/Term/short-definitions.js index 111d0ed89..f5b58d604 100644 --- a/src/components/Term/short-definitions.js +++ b/src/components/Term/short-definitions.js @@ -73,5 +73,5 @@ export default { jsTruthy: "javascriptTruthyFalsy", jsFalsy: "javascriptTruthyFalsy", truthy: "javascriptTruthyFalsy", - falsy: "javascriptTruthyFalsy" -}; \ No newline at end of file + falsy: "javascriptTruthyFalsy", +}; From 3c01fe0334662f65bda1cce68bd5ad7fd7bc9e52 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Wed, 8 Nov 2023 00:14:02 +0900 Subject: [PATCH 06/16] remove unnecessary guard --- src/components/Term/index.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/Term/index.jsx b/src/components/Term/index.jsx index 3f843f3db..bf9c75d08 100644 --- a/src/components/Term/index.jsx +++ b/src/components/Term/index.jsx @@ -19,8 +19,7 @@ export default function Term({ type = null, children }) { if (typeof mdx === "string") return mdx; else return unwrap(mdx.props.children); } - if (type === null || type === undefined) - type = autoType.get(unwrap(children)); + if (type === null) type = autoType.get(unwrapNode(children)); if (!type) throw new Error( `Problem: Term ${children.textContent} is not defined in AutoType. From 16ba9c5802b09cae89b81b1a203ff7ebb87bee0a Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Wed, 8 Nov 2023 00:14:32 +0900 Subject: [PATCH 07/16] =?UTF-8?q?=E5=91=BD=E5=90=8D=E6=94=B9=E5=96=84=20(?= =?UTF-8?q?=E5=A4=9A=E5=88=86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Term/index.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Term/index.jsx b/src/components/Term/index.jsx index bf9c75d08..f7873cac4 100644 --- a/src/components/Term/index.jsx +++ b/src/components/Term/index.jsx @@ -15,9 +15,9 @@ import autoType from "./auto-type.js"; * @param {React.ReactNode} props.children */ export default function Term({ type = null, children }) { - function unwrap(mdx) { - if (typeof mdx === "string") return mdx; - else return unwrap(mdx.props.children); + function unwrapNode(node) { + if (typeof node === "string") return node; + else return unwrapNode(node.props.children); } if (type === null) type = autoType.get(unwrapNode(children)); if (!type) From 2162cb83a2918c903d3e80367d08e67b53261f02 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Wed, 8 Nov 2023 00:20:07 +0900 Subject: [PATCH 08/16] autoType -> typeMap --- src/components/Term/index.jsx | 6 +++--- src/components/Term/{auto-type.js => type-map.js} | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename src/components/Term/{auto-type.js => type-map.js} (97%) diff --git a/src/components/Term/index.jsx b/src/components/Term/index.jsx index f7873cac4..db99d9076 100644 --- a/src/components/Term/index.jsx +++ b/src/components/Term/index.jsx @@ -7,7 +7,7 @@ import "tippy.js/themes/material.css"; import styles from "./styles.module.css"; import definitions from "./definitions"; import shortDefinitions from "./short-definitions.js"; -import autoType from "./auto-type.js"; +import typeMap from "./type-map.js"; /** * @param {Object} props @@ -19,10 +19,10 @@ export default function Term({ type = null, children }) { if (typeof node === "string") return node; else return unwrapNode(node.props.children); } - if (type === null) type = autoType.get(unwrapNode(children)); + if (type === null) type = typeMap.get(unwrapNode(children)); if (!type) throw new Error( - `Problem: Term ${children.textContent} is not defined in AutoType. + `Problem: Term ${children.textContent} is not defined in type-map.js . Solution: explicitly specify term type, or add type definition to auto-type.js`, ); const term = diff --git a/src/components/Term/auto-type.js b/src/components/Term/type-map.js similarity index 97% rename from src/components/Term/auto-type.js rename to src/components/Term/type-map.js index 6448f0531..63456d9cb 100644 --- a/src/components/Term/auto-type.js +++ b/src/components/Term/type-map.js @@ -11,7 +11,7 @@ > data is stored as Map. use Map#get */ -const autoType = new Map([ +const typeMap = new Map([ ["拡張子", "fileExtension"], ["フォーク", "fork"], ["Git", "git"], @@ -82,4 +82,4 @@ const autoType = new Map([ ["JSX", "jsx"], ]); -export default autoType; +export default typeMap; From fb1f2413849a006352c6c4b97281ad5cc4e4f3ca Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Wed, 8 Nov 2023 00:32:40 +0900 Subject: [PATCH 09/16] =?UTF-8?q?=E5=89=8D=E3=81=AE=E5=90=8D=E5=89=8D?= =?UTF-8?q?=E3=81=8C=E6=AE=8B=E3=81=A3=E3=81=A6=E3=81=9F=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Term/index.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Term/index.jsx b/src/components/Term/index.jsx index db99d9076..07ad5d7eb 100644 --- a/src/components/Term/index.jsx +++ b/src/components/Term/index.jsx @@ -23,8 +23,9 @@ export default function Term({ type = null, children }) { if (!type) throw new Error( `Problem: Term ${children.textContent} is not defined in type-map.js . - Solution: explicitly specify term type, or add type definition to auto-type.js`, + Solution: explicitly specify term type, or add type definition to type-map.js`, ); + const term = definitions.terms[type] || definitions.terms[shortDefinitions[type]]; if (!term) throw new Error(`Type ${type} is not defined.`); From 817732c1b5f19d752dd5ceeb9fe7a4ba24777f3d Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Wed, 8 Nov 2023 12:10:16 +0900 Subject: [PATCH 10/16] =?UTF-8?q?onlyText=E5=B0=8E=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Term/index.jsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/components/Term/index.jsx b/src/components/Term/index.jsx index 07ad5d7eb..493938763 100644 --- a/src/components/Term/index.jsx +++ b/src/components/Term/index.jsx @@ -4,6 +4,7 @@ import Tippy from "@tippyjs/react"; import { MdArrowForward } from "react-icons/md"; import "tippy.js/dist/tippy.css"; import "tippy.js/themes/material.css"; +import { onlyText } from "react-children-utilities"; import styles from "./styles.module.css"; import definitions from "./definitions"; import shortDefinitions from "./short-definitions.js"; @@ -15,14 +16,10 @@ import typeMap from "./type-map.js"; * @param {React.ReactNode} props.children */ export default function Term({ type = null, children }) { - function unwrapNode(node) { - if (typeof node === "string") return node; - else return unwrapNode(node.props.children); - } - if (type === null) type = typeMap.get(unwrapNode(children)); + if (type === null) type = typeMap.get(onlyText(children)); if (!type) throw new Error( - `Problem: Term ${children.textContent} is not defined in type-map.js . + `Problem: Term ${onlyText(children)} is not defined in type-map.js . Solution: explicitly specify term type, or add type definition to type-map.js`, ); From 09733bc9526d0f07106ef04cb063a87586de2bb4 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Wed, 8 Nov 2023 12:15:34 +0900 Subject: [PATCH 11/16] =?UTF-8?q?=E8=AA=AC=E6=98=8E=E3=81=AE=E6=97=A5?= =?UTF-8?q?=E6=9C=AC=E8=AA=9E=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Term/type-map.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/components/Term/type-map.js b/src/components/Term/type-map.js index 63456d9cb..9cfff52cb 100644 --- a/src/components/Term/type-map.js +++ b/src/components/Term/type-map.js @@ -1,14 +1,15 @@ /* ----- Memo ------- - # Adding auto terms -> both shortened / full type is allowed -> only match literal terms, - therefore not for explanation terms -> doesn't need to be one text per tye, - but has to be one type per text + # term の追加 +> 文字列そのままの Term しか match しないので、 + 説明的な Term (Truthy と Falsy など)は対応していません。 +> 名前の同じ Term は、使用頻度の高そうな方を優先してください。 - # Usage -> data is stored as Map. use Map#get + # 使い方 +> Mapとして保存されています。 Map#get を使ってください +> 説明的な Term (Truthy と Falsy など) や + 名前の同じ Term (CSS のプロパティ -> JS のプロパティとして解釈する) + などは対応していないので、term を明示してください。 */ const typeMap = new Map([ From d027a48638e5ac28708122b5ae9c1659e5e6051d Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Wed, 8 Nov 2023 12:24:29 +0900 Subject: [PATCH 12/16] =?UTF-8?q?MEMO=20=E3=81=AE=E4=BE=8B=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=80=81=E5=8D=8A=E8=A7=92=E3=82=B9=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B9=E3=81=AE=E5=BC=B7=E8=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Term/type-map.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/Term/type-map.js b/src/components/Term/type-map.js index 9cfff52cb..ce6963fb3 100644 --- a/src/components/Term/type-map.js +++ b/src/components/Term/type-map.js @@ -2,14 +2,25 @@ ----- Memo ------- # term の追加 > 文字列そのままの Term しか match しないので、 - 説明的な Term (Truthy と Falsy など)は対応していません。 + 説明的な Term は対応していません。 + 例: "演算子の優先順位"、"Truthy と Falsy" + > 名前の同じ Term は、使用頻度の高そうな方を優先してください。 + 例: "プロパティ" -> "jsProperty" + +> 英数字と日本語の間は半角を入れることになっているので、 + 半角が入っているもののみを記述してください。 + 例: 〇 "HTML 要素" × "HTML要素" + # 使い方 > Mapとして保存されています。 Map#get を使ってください + 例: const type = typeMap.get(termAsJapaneseString); // ./index.jsx + > 説明的な Term (Truthy と Falsy など) や 名前の同じ Term (CSS のプロパティ -> JS のプロパティとして解釈する) などは対応していないので、term を明示してください。 + 例: CSS のプロパティ // /docs/ */ const typeMap = new Map([ @@ -28,7 +39,7 @@ const typeMap = new Map([ ["要素", "element"], ["終了タグ", "endTag"], ["CSS", "css"], - ["style属性", "styleAttribute"], + ["style 属性", "styleAttribute"], ["文", "statement"], ["値", "value"], ["文字列", "string"], @@ -43,13 +54,11 @@ const typeMap = new Map([ ["パスカルケース", "pascalCase"], ["真偽値", "bool"], ["if 文", "ifStatement"], - ["if文", "ifStatement"], ["制御構造", "controlFlow"], ["関数", "function"], ["引数", "parameter"], ["渡す", "pass"], ["戻り値", "returnValue"], - ["返り値", "returnValue"], ["返す", "return"], ["スコープ", "scope"], ["モジュール化", "modularization"], @@ -74,7 +83,6 @@ const typeMap = new Map([ ["JSON", "json"], ["クエリ文字列", "queryString"], ["npx コマンド", "npxCommand"], - ["npxコマンド", "npxCommand"], ["非同期処理", "asyncProcess"], ["API", "api"], ["スレッド", "thread"], From 32d7c4130115f2d288c9d77913eb74ff59444678 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Wed, 8 Nov 2023 12:35:13 +0900 Subject: [PATCH 13/16] =?UTF-8?q?react-children-utilities=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 11 ++++++++++- package.json | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index d7196ae35..35890f0c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "outdent": "^0.8.0", "prism-react-renderer": "^2.1.0", "react": "^18.2.0", + "react-children-utilities": "^2.9.0", "react-dom": "^18.2.0", "react-icons": "^4.11.0", "rehype-katex": "^7.0.0", @@ -27,7 +28,7 @@ "prettier": "^3.0.3" }, "engines": { - "node": ">=16.0.0" + "node": ">=18.0" } }, "node_modules/@algolia/autocomplete-core": { @@ -13209,6 +13210,14 @@ "pure-color": "^1.2.0" } }, + "node_modules/react-children-utilities": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/react-children-utilities/-/react-children-utilities-2.9.0.tgz", + "integrity": "sha512-B3enhwcibIziobkMVccLd+6uIRoiCC9OZ1nR2B5sFCTnUYoGOCqgPOWUL+IC4S8IYaaN5AeF+SS0X1wernPdZA==", + "peerDependencies": { + "react": "18 || 17 || 16 || 15" + } + }, "node_modules/react-dev-utils": { "version": "12.0.1", "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-12.0.1.tgz", diff --git a/package.json b/package.json index 089f0e4d9..efd7da513 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "react-dom": "^18.2.0", "react-icons": "^4.11.0", "rehype-katex": "^7.0.0", - "remark-math": "^6.0.0" + "remark-math": "^6.0.0", + "react-children-utilities": "^2.9.0" }, "browserslist": { "production": [ From 9f76a3340c71b23e64249f5ea756bda426af743a Mon Sep 17 00:00:00 2001 From: frgd <137767097+Fridge0@users.noreply.github.com> Date: Wed, 8 Nov 2023 13:51:58 +0900 Subject: [PATCH 14/16] update JSDoc --- src/components/Term/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Term/index.jsx b/src/components/Term/index.jsx index 493938763..2a16be85b 100644 --- a/src/components/Term/index.jsx +++ b/src/components/Term/index.jsx @@ -12,7 +12,7 @@ import typeMap from "./type-map.js"; /** * @param {Object} props - * @param {keyof typeof definitions} props.type + * @param {keyof typeof definitions | null} props.type * @param {React.ReactNode} props.children */ export default function Term({ type = null, children }) { From c02c04caffb80bc9f226e189239250e42434fb32 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Wed, 8 Nov 2023 15:13:08 +0900 Subject: [PATCH 15/16] get rid of short-definition.js (for later PR) --- src/components/Term/index.jsx | 4 +- src/components/Term/short-definitions.js | 77 ------------------------ src/components/Term/type-map.js | 74 ++++++++++++++++++++++- 3 files changed, 73 insertions(+), 82 deletions(-) delete mode 100644 src/components/Term/short-definitions.js diff --git a/src/components/Term/index.jsx b/src/components/Term/index.jsx index 493938763..f1d7c1a4b 100644 --- a/src/components/Term/index.jsx +++ b/src/components/Term/index.jsx @@ -7,7 +7,6 @@ import "tippy.js/themes/material.css"; import { onlyText } from "react-children-utilities"; import styles from "./styles.module.css"; import definitions from "./definitions"; -import shortDefinitions from "./short-definitions.js"; import typeMap from "./type-map.js"; /** @@ -23,8 +22,7 @@ export default function Term({ type = null, children }) { Solution: explicitly specify term type, or add type definition to type-map.js`, ); - const term = - definitions.terms[type] || definitions.terms[shortDefinitions[type]]; + const term = definitions.terms[type]; if (!term) throw new Error(`Type ${type} is not defined.`); const referencePageTitle = definitions.referencePageTitles[term.referencePage]; diff --git a/src/components/Term/short-definitions.js b/src/components/Term/short-definitions.js deleted file mode 100644 index f5b58d604..000000000 --- a/src/components/Term/short-definitions.js +++ /dev/null @@ -1,77 +0,0 @@ -export default { - js: "javascript", - jsStatement: "javascriptStatement", - statement: "javascriptStatement", - jsValue: "javascriptValue", - value: "javascriptValue", - jsString: "javascriptString", - string: "javascriptString", - jsNumber: "javascriptNumber", - number: "javascriptNumber", - jsOperator: "javascriptOperator", - operator: "javascriptOperator", - jsExpression: "javascriptExpression", - expression: "javascriptExpression", - jsEvaluation: "javascriptEvaluation", - evaluation: "javascriptEvaluation", - jsVariable: "javascriptVariable", - variable: "javascriptVariable", - jsDeclaration: "javascriptDeclaration", - declaration: "javascriptDeclaration", - jsAssignment: "javascriptAssignment", - assignment: "javascriptAssignment", - jsBoolean: "javascriptBoolean", - jsBool: "javascriptBoolean", - boolean: "javascriptBoolean", - bool: "javascriptBoolean", - jsIfStatement: "javascriptIfStatement", - jsIf: "javascriptIfStatement", - ifStatement: "javascriptIfStatement", - if: "javascriptIfStatement", - jsFunction: "javascriptFunction", - function: "javascriptFunction", - jsParameter: "javascriptParameter", - parameter: "javascriptParameter", - jsPass: "javascriptPass", - pass: "javascriptPass", - jsReturnValue: "javascriptReturnValue", - returnValue: "javascriptReturnValue", - jsReturn: "javascriptReturn", - return: "javascriptReturn", - jsScope: "javascriptScope", - scope: "javascriptScope", - jsModularization: "javascriptModularization", - modularization: "javascriptModularization", - jsObject: "javascriptObject", - object: "javascriptObject", - jsPrimitive: "javascriptPrimitive", - primitive: "javascriptPrimitive", - jsProperty: "javascriptProperty", - property: "javascriptProperty", - jsReference: "javascriptReference", - reference: "javascriptReference", - jsSideEffects: "javascriptSideEffects", - jsSideEffect: "javascriptSideEffects", - sideEffects: "javascriptSideEffects", - sideEffect: "javascriptSideEffects", - jsPureFunction: "javascriptPureFunction", - pureFunction: "javascriptPureFunction", - jsReferenceTransparency: "javascriptReferenceTransparency", - referenceTransparency: "javascriptTransparency", - jsClass: "javascriptClass", - class: "javascriptClass", - jsInstance: "javascriptInstance", - instance: "javascriptInstance", - jsConstructor: "javascriptConstructor", - constructor: "javascriptConstructor", - jsMethod: "javascriptMethod", - method: "javascriptMethod", - jsModule: "javascriptModule", - module: "javascriptModule", - asyncProcess: "asynchronousProcess", - jsTruthyFalsy: "javascriptTruthyFalsy", - jsTruthy: "javascriptTruthyFalsy", - jsFalsy: "javascriptTruthyFalsy", - truthy: "javascriptTruthyFalsy", - falsy: "javascriptTruthyFalsy", -}; diff --git a/src/components/Term/type-map.js b/src/components/Term/type-map.js index ce6963fb3..6ef9b8243 100644 --- a/src/components/Term/type-map.js +++ b/src/components/Term/type-map.js @@ -23,6 +23,77 @@ 例: CSS のプロパティ // /docs/ */ +const typeMap = new Map([ + ["拡張子", "fileExtension"], + ["フォーク", "fork"], + ["Git", "git"], + ["GitHub", "github"], + ["Gitpod", "gitpod"], + ["リポジトリ", "repository"], + ["HTML", "html"], + ["JavaScript", "javascript"], + ["開始タグ", "startTag"], + ["タグ", "tag"], + ["属性", "attribute"], + ["HTML 要素", "element"], + ["要素", "element"], + ["終了タグ", "endTag"], + ["CSS", "css"], + ["style 属性", "styleAttribute"], + ["文", "javascriptStatement"], + ["値", "javascriptValue"], + ["文字列", "javascriptString"], + ["演算子", "javascriptOperator"], + ["式", "javascriptExpression"], + ["評価", "javascriptEvaluation"], + ["変数", "javascriptVariable"], + ["宣言", "javascriptDeclaration"], + ["代入", "javascriptAssignment"], + ["キャメルケース", "camelCase"], + ["スネークケース", "snakeCase"], + ["パスカルケース", "pascalCase"], + ["真偽値", "javascriptBoolean"], + ["if 文", "javascriptIfStatement"], + ["制御構造", "javascriptControlFlow"], + ["関数", "javascriptFunction"], + ["引数", "javascriptParameter"], + ["渡す", "javascriptPass"], + ["戻り値", "javascriptReturnValue"], + ["返す", "javascriptReturn"], + ["スコープ", "javascriptScope"], + ["モジュール化", "javascriptModularization"], + ["オブジェクト", "javascriptObject"], + ["プリミティブ", "javascriptPrimitive"], + ["プロパティ", "javascriptProperty"], + ["DOM", "dom"], + ["イベント", "events"], + ["イベントハンドラ", "eventHandler"], + ["参照", "javascriptReference"], + ["副作用", "javascriptSideEffects"], + ["純粋関数", "javascriptPureFunction"], + ["参照透過性", "javascriptReferenceTransparency"], + ["クラス", "javascriptClass"], + ["インスタンス", "javascriptInstance"], + ["コンストラクタ", "javascriptConstructor"], + ["メソッド", "javascriptMethod"], + ["アロー関数", "arrowFunction"], + ["コールバック関数", "callBackFunction"], + ["モジュール", "javascriptModule"], + ["ライブラリ", "library"], + ["JSON", "json"], + ["クエリ文字列", "queryString"], + ["npx コマンド", "npxCommand"], + ["非同期処理", "asynchronousProcess"], + ["API", "api"], + ["スレッド", "thread"], + ["トランスパイル", "transpile"], + ["モジュールバンドラ", "moduleBundler"], + ["JSX", "jsx"], +]); + +export default typeMap; + +/* for later use // no-more-meaningless-javascript const typeMap = new Map([ ["拡張子", "fileExtension"], ["フォーク", "fork"], @@ -90,5 +161,4 @@ const typeMap = new Map([ ["モジュールバンドラ", "moduleBundler"], ["JSX", "jsx"], ]); - -export default typeMap; +*/ From 69257908898b04ef13ead9f22a0e1e769ec14112 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Wed, 8 Nov 2023 16:14:03 +0900 Subject: [PATCH 16/16] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Term/type-map.js | 44 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/components/Term/type-map.js b/src/components/Term/type-map.js index 6ef9b8243..6f88378ab 100644 --- a/src/components/Term/type-map.js +++ b/src/components/Term/type-map.js @@ -1,27 +1,23 @@ -/* ------ Memo ------- - # term の追加 -> 文字列そのままの Term しか match しないので、 - 説明的な Term は対応していません。 - 例: "演算子の優先順位"、"Truthy と Falsy" - -> 名前の同じ Term は、使用頻度の高そうな方を優先してください。 - 例: "プロパティ" -> "jsProperty" - -> 英数字と日本語の間は半角を入れることになっているので、 - 半角が入っているもののみを記述してください。 - 例: 〇 "HTML 要素" × "HTML要素" - - - # 使い方 -> Mapとして保存されています。 Map#get を使ってください - 例: const type = typeMap.get(termAsJapaneseString); // ./index.jsx - -> 説明的な Term (Truthy と Falsy など) や - 名前の同じ Term (CSS のプロパティ -> JS のプロパティとして解釈する) - などは対応していないので、term を明示してください。 - 例: CSS のプロパティ // /docs/ -*/ +/* + * # term の追加 + * > 文字列そのままの Term しか match しないので、 + * 説明的な Term は対応していません。 + * 例: "演算子の優先順位"、"Truthy と Falsy" + * + * > 名前の同じ Term は、使用頻度の高そうな方を優先してください。 + * 例: "プロパティ" -> "javascriptProperty" + * + * > 英数字と日本語の間は半角スペースを入れることになっているので、 + * 半角が入っているもののみを記述してください。 + * 例: 〇 "HTML 要素" × "HTML要素" + * + * + * # 使い方 + * > 説明的な Term (Truthy と Falsy など) や、 + * 名前の同じ Term (CSS のプロパティ -> JS のプロパティとして解釈する) + * などは対応していないので、term を明示してください。 + * 例: CSS のプロパティ // /docs/ + */ const typeMap = new Map([ ["拡張子", "fileExtension"],