@podlite/editor-react 0.0.11 → 0.0.12
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/CHANGELOG.md +7 -1
- package/esm/index.css +1 -332
- package/esm/index.js +31 -13250
- package/esm/index.js.map +7 -0
- package/jest.config copy.js +2 -0
- package/jest.tsconfig.json +1 -0
- package/lib/index.css +1 -332
- package/lib/index.js +31 -13253
- package/lib/index.js.map +7 -0
- package/package.json +18 -19
- package/scripts/build.ts +17 -0
- package/scripts/build_esm.ts +17 -0
- package/src/Editor.css +14 -1
- package/src/dict.ts +46 -19
- package/src/index.tsx +15 -6
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1309
- package/yarn-error.log +8903 -0
package/lib/index.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../node_modules/react-is/cjs/react-is.production.min.js", "../../../node_modules/react-is/index.js", "../src/index.tsx", "../src/dict.ts"],
|
|
4
|
+
"sourcesContent": ["/** @license React v17.0.2\n * react-is.production.min.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict';var b=60103,c=60106,d=60107,e=60108,f=60114,g=60109,h=60110,k=60112,l=60113,m=60120,n=60115,p=60116,q=60121,r=60122,u=60117,v=60129,w=60131;\nif(\"function\"===typeof Symbol&&Symbol.for){var x=Symbol.for;b=x(\"react.element\");c=x(\"react.portal\");d=x(\"react.fragment\");e=x(\"react.strict_mode\");f=x(\"react.profiler\");g=x(\"react.provider\");h=x(\"react.context\");k=x(\"react.forward_ref\");l=x(\"react.suspense\");m=x(\"react.suspense_list\");n=x(\"react.memo\");p=x(\"react.lazy\");q=x(\"react.block\");r=x(\"react.server.block\");u=x(\"react.fundamental\");v=x(\"react.debug_trace_mode\");w=x(\"react.legacy_hidden\")}\nfunction y(a){if(\"object\"===typeof a&&null!==a){var t=a.$$typeof;switch(t){case b:switch(a=a.type,a){case d:case f:case e:case l:case m:return a;default:switch(a=a&&a.$$typeof,a){case h:case k:case p:case n:case g:return a;default:return t}}case c:return t}}}var z=g,A=b,B=k,C=d,D=p,E=n,F=c,G=f,H=e,I=l;exports.ContextConsumer=h;exports.ContextProvider=z;exports.Element=A;exports.ForwardRef=B;exports.Fragment=C;exports.Lazy=D;exports.Memo=E;exports.Portal=F;exports.Profiler=G;exports.StrictMode=H;\nexports.Suspense=I;exports.isAsyncMode=function(){return!1};exports.isConcurrentMode=function(){return!1};exports.isContextConsumer=function(a){return y(a)===h};exports.isContextProvider=function(a){return y(a)===g};exports.isElement=function(a){return\"object\"===typeof a&&null!==a&&a.$$typeof===b};exports.isForwardRef=function(a){return y(a)===k};exports.isFragment=function(a){return y(a)===d};exports.isLazy=function(a){return y(a)===p};exports.isMemo=function(a){return y(a)===n};\nexports.isPortal=function(a){return y(a)===c};exports.isProfiler=function(a){return y(a)===f};exports.isStrictMode=function(a){return y(a)===e};exports.isSuspense=function(a){return y(a)===l};exports.isValidElementType=function(a){return\"string\"===typeof a||\"function\"===typeof a||a===d||a===f||a===v||a===e||a===l||a===m||a===w||\"object\"===typeof a&&null!==a&&(a.$$typeof===p||a.$$typeof===n||a.$$typeof===g||a.$$typeof===h||a.$$typeof===k||a.$$typeof===u||a.$$typeof===q||a[0]===r)?!0:!1};\nexports.typeOf=y;\n", "'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/react-is.production.min.js');\n} else {\n module.exports = require('./cjs/react-is.development.js');\n}\n", "import * as React from 'react'\nimport { Controlled as CodeMirrorControlled, UnControlled as CodeMirror} from 'react-codemirror2'\nimport CMirror from 'codemirror'\nimport dictionary from './dict'\nimport { useState, useEffect, useRef, useMemo } from 'react'\nimport {isValidElementType, isElement} from 'react-is'\n\n// TODO: use bundler to add into package\n// import '../../../node_modules/codemirror/lib/codemirror.css';\nimport 'codemirror/mode/gfm/gfm';\nimport \"codemirror/addon/hint/show-hint\";\nimport 'codemirror/addon/hint/show-hint.css';\nimport './Editor.css';\n\n\n//@ts-ignore\nfunction useDebouncedEffect(fn, deps, time) {\n const dependencies = [...deps, time] \n useEffect(() => {\n const timeout = setTimeout(fn, time);\n return () => {\n clearTimeout(timeout);\n }\n }, dependencies);\n}\n\n/* set window title */ \n// @ts-ignore\n// const setWindowTitle = (title: string) => { vmd.setWindowTitle(title) }\nexport interface ConverterResult {\n errors?:any,\n result:any\n}\n\nlet instanceCM = null\ntype Props={\n content: string,\n onChangeSource:Function,\n sourceType?: 'pod6' | 'md',\n onConvertSource: (source:string)=>ConverterResult,\n onSavePressed?: Function,\n isDarkTheme? : boolean,\n isLineNumbers?: boolean,\n isAutoComplete?: boolean,\n isPreviewModeEnabled? :boolean\n isControlled?:boolean\n}\n\nexport default ({ \n onChangeSource = ()=>{}, \n content, \n isDarkTheme = false, \n isLineNumbers = false, \n isPreviewModeEnabled = false, \n onConvertSource, \n onSavePressed = () => { },\n sourceType = 'pod6',\n isControlled=false,\n isAutoComplete = true,\n }: Props) => {\n const [text, updateText] = useState(content)\n\n const [marks, updateMarks] = useState([])\n const [, updateScrollMap] = useState([])\n \n const [isPreviewMode, setPreviewMode] = useState(isPreviewModeEnabled)\n\n const [isPreviewScroll, setPreviewScrolling] = useState(false);\n const refValue = useRef(isPreviewScroll);\n const [showTree, setShowTree] = useState(false)\n\n const [filePath, setFilePath] = useState('')\n const [fileName, setFileName] = useState('')\n const [fileExt, setFileExt] = useState('')\n const [isChanged, setChanged] = useState(false)\n\n const [fileLoading, setFileLoading] = useState(true)\n\nuseEffect(()=>{\nupdateText(content)\n},[content])\n\n const [result, updateResult] = useState<ConverterResult>() \n useDebouncedEffect(() => {\n updateResult(onConvertSource(text))\n }, [text], 50)\n \n const inputEl = useRef(null)\n\n// hot keys\n useEffect( () => {\n const saveFileAction = () => {\n if (isChanged) {\n console.warn(\"Save File\")\n onSavePressed(text)\n\n }\n }\n})\n\n\nuseEffect(() => {\n refValue.current = isPreviewScroll;\n});\nvar options: CMirror.EditorConfiguration = {\n lineNumbers: isLineNumbers,\n inputStyle: \"contenteditable\",\n //@ts-ignore\n spellcheck: true,\n autofocus:true,\n lineWrapping:true,\n viewportMargin:Infinity,\n mode: sourceType !== 'md' ? null : \n {\n name: \"gfm\",\n tokenTypeOverrides: {\n emoji: \"emoji\"\n }\n },\n theme: isDarkTheme ? \"duotone-dark\" : \"default\"\n};\n\n\nconst previewEl = useRef(null)\n\nuseEffect(() => {\n //@ts-ignore\n const newScrollMap = [...document.querySelectorAll('.line-src')]\n .map(n => {\n const line = parseInt(n.getAttribute('data-line'),10 )\n //@ts-ignore\n const offsetTop = n.offsetTop\n return { line, offsetTop}\n })\n //@ts-ignore \n updateScrollMap(newScrollMap)\n //@ts-ignore\n const listener = (e) => { \n if (!isPreviewScroll ) {return}\n let element = e.target\n //@ts-ignore\n const getLine = (offset) => {\n const c = newScrollMap.filter( i => i.offsetTop > offset )\n const lineElement = c.shift() || newScrollMap[ newScrollMap.length - 1 ]\n if (!lineElement) {\n console.warn(`[podlite-editor] can't get line for offset. Forget add .line-src ?`)\n }\n return lineElement.line\n }\n const line = getLine(element.scrollTop)\n if (instanceCM) {\n const t = element.scrollTop === 0 ? 0 : instanceCM.charCoords({line: line, ch: 0}, \"local\").top;\n instanceCM.scrollTo(null, t);\n }\n return true\n }\n if (previewEl && previewEl.current) {\n //@ts-ignore\n previewEl.current.addEventListener(\"scroll\", listener);\n }\n return () => {\n // @ts-ignore\n previewEl && previewEl.current && previewEl && previewEl.current.removeEventListener(\"scroll\", listener);\n };\n},[text,isPreviewScroll])\n\nuseEffect(() => {\n //@ts-ignore\n let cm = instanceCM\n if (!cm) {return}\n //@ts-ignore\n marks.forEach(marker => marker.clear())\n //@ts-ignore\n let cmMrks:Array<never> = []\n //@ts-ignore\n if (result && result.errors ) {\n\n //@ts-ignore\n result.errors.map((loc:any)=>{\n // @ts-ignore\n let from = {line: loc.start.line-1, ch: loc.start.column-1 - (loc.start.offset === loc.end.offset)};\n let to = {line: loc.end.line-1, ch: loc.end.column-1};\n\n cmMrks.push(\n //@ts-ignore\n cm.markText(\n from,\n to, \n {\n className: 'syntax-error',\n title: ';data.error.message',\n css: \"color : red\"\n }\n )\n \n )\n })\n }\n updateMarks(cmMrks)\n\n},[text,result])\n\nconst previewHtml = <div className={ \"Editorright \" + (isDarkTheme ? 'dark' : '' )}\n onMouseEnter={()=>setPreviewScrolling(true)} \n onMouseMove={()=>setPreviewScrolling(true)} \n ref={previewEl} \n >\n {\n result ? \n isElement(result.result) ? <div className=\"content\">{result.result}</div> : <div \n dangerouslySetInnerHTML={{__html: result.result}} \n className=\"content\" \n ></div>\n : ''\n \n }\n </div>\n//@ts-ignore\nconst scrollEditorHandler = (editor) => {\n if (refValue.current) { return }\n let scrollInfo = editor.getScrollInfo();\n // get line number of the top line in the page\n let lineNumber = editor.lineAtHeight(scrollInfo.top, 'local') + 1;\n if (previewEl) {\n const el = previewEl.current\n const elementId = `#line-${lineNumber}`\n const scrollToElement = document.querySelector(elementId)\n if (scrollToElement) {\n //@ts-ignore\n const scrollTo = scrollToElement.offsetTop\n //@ts-ignore\n el.scrollTo({\n top: scrollTo,\n left: 0,\n behavior: 'smooth'\n })\n }\n }\n}\nconst [instanceCMLocal, updateInstanceCM] = useState<any>()\n\nuseEffect(()=>{\n if (!instanceCMLocal) return\n if (!isAutoComplete) return\n var onChange = function(instance, object)\n {\n // Check if the last inserted character is `=`.\n if (object.text[0] === '=' &&\n // start directive\n instance.getRange({ch:0,line: object.to.line}, object.to).match(/^\\s*$/))\n {\n CMirror.showHint(instanceCMLocal, CMirror.hint.dictionaryHint);\n }\n }\n instanceCMLocal.on('change', onChange);\n\n CMirror.registerHelper('hint', 'dictionaryHint', function(editor) {\n var cur = editor.getCursor();\n var curLine = editor.getLine(cur.line);\n var start = cur.ch;\n var end = start;\n while (end < curLine.length && /[\\w$]/.test(curLine.charAt(end))) ++end;\n while (start && /[^=]/.test(curLine.charAt(start - 1))) --start;\n var curWord = start !== end && curLine.slice(start, end);\n var regex = new RegExp('' + curWord, 'i');\n // filter dict by regex and sort by mostly nearness\n const filterDictByRegex = (arr, regex)=>{\n const dict = arr.reduce((acc, item)=>{\n if (item === null) { return acc; }\n const result = (typeof item === 'object' && !Array.isArray(item)) ? item.displayText.match(regex): item.match(regex);\n if ( result ) {\n acc.push({item, index:result.index})\n }\n return acc;\n }, []);\n return dict.sort((a, b) => a.index - b.index).map(i=>i.item)\n }\n return {\n list: (!curWord ? dictionary : filterDictByRegex(dictionary,regex )),\n from: CMirror.Pos(cur.line, start-1),\n to: CMirror.Pos(cur.line, end)\n }\n });\n instanceCMLocal.refresh()\n return () => {\n //@ts-ignore\n instanceCMLocal.off('change', onChange)\n }\n},[instanceCMLocal, isAutoComplete])\n\nreturn (\n <div className=\"EditorApp\">\n <div className={ isPreviewModeEnabled ? \"layoutPreview\": \"layout\"}>\n <div className=\"Editorleft\" onMouseEnter={()=>setPreviewScrolling(false)}\n onMouseMove={()=>setPreviewScrolling(false)}\n >\n {isControlled ? \n <CodeMirrorControlled\n value={content}\n editorDidMount={ editor => { instanceCM = editor; updateInstanceCM(editor) } }\n onBeforeChange={(editor, data, value) => {\n setChanged(true); \n // updateText(value);\n onChangeSource(value)\n }}\n onScroll={scrollEditorHandler}\n options={options} \n className=\"editorApp\"\n />\n :\n <CodeMirror \n value={content}\n editorDidMount={ editor => { instanceCM = editor; updateInstanceCM(editor) } }\n onChange = { (editor, data, value) => { \n setChanged(true); \n updateText(value);\n onChangeSource(value)\n } }\n onScroll={scrollEditorHandler}\n options={options} \n className=\"editorApp\"\n />\n }\n </div>\n {previewHtml}\n </div>\n </div>\n);\n}\n", "// this file contains the dictionary ot the messages used in the podlite editor\n\nconst dict = [\n {\n \"displayText\": \"head1\",\n \"text\": `=head1 `\n },\n {\n \"displayText\": \"head2\",\n \"text\": `=head2 `\n },\n \n {\n \"displayText\": \"head3\",\n \"text\": `=head3 `\n },\n {\n \"displayText\": \"item1 *\",\n \"text\": `=item1 `\n }, \n {\n \"displayText\": \"item1 1.)\",\n \"text\": `=item1 # `\n},\n{\n \"displayText\": \"item (1., 2.) \uD83C\uDFF7\",\n \"text\": `=item1 # item \n =item2 # item level 2\n =item2 # item level 2\n=item1 # item\n =item2 # item\n =item2 # item level 2\n`},\n{\n \"displayText\": \"item (*, *) \uD83C\uDFF7\",\n \"text\": `=item1 item \n =item2 item level 2\n =item2 item level 2\n=item1 item\n =item2 item\n =item3 item level 2\n`},\n{\n \"displayText\": \"Image \uD83C\uDFF7\",\n \"text\": `=Image https://github.com/zag/podlite-desktop/blob/master/dist-assets/linux-icon/256x256.png?raw=true\n`,\n},\n{\n \"displayText\": \"table simple \uD83C\uDFF7\",\n \"text\":`=for table\n mouse | mice\n horse | horses\n elephant | elephants\n`\n},\n{\n \"displayText\": \"table 2x \uD83C\uDFF7\",\n \"text\": `=begin table :caption('Caption of table')\nConstants 1\nVariables 10\nSubroutines 33\nEverything else 57\n=end table\n`},\n{\n \"displayText\": \"table 3x \uD83C\uDFF7\",\n \"text\": `=for table :caption('Caption of table')\n Animal | Legs | Eats\n =======================\n Zebra + 4 + Cookies\n Human + 2 + Pizza\n Shark + 0 + Fish\n`\n},\n{\n \"displayText\": \"Diagram simple \uD83C\uDFF7\",\n \"text\": `=begin Diagram :caption('Caption of diagram')\n graph LR\n A-->B\n B-->C\n C-->A\n D-->C\n=end Diagram\n`\n},\n{\n \"displayText\": \"Diagram Sequence \uD83C\uDFF7\",\n \"text\": `=for Diagram :caption('Caption of diagram')\n sequenceDiagram\n autonumber\n Student->>Admin: Can I enrol this semester?\n loop enrolmentCheck\n Admin->>Admin: Check previous results\n end\n Note right of Admin: Exam results may <br> be delayed\n Admin-->>Student: Enrolment success\n Admin->>Professor: Assign student to tutor\n Professor-->>Admin: Student is assigned\n\n`\n},\n{\n \"displayText\": \"Diagram flowchart \uD83C\uDFF7\",\n \"text\": `=for Diagram :caption('Caption of diagram')\n graph LR\n A[Square Rect] -- Link text --> B((Circle))\n A --> C(Round Rect)\n B --> D{Rhombus}\n C --> D\n\n`\n},\n{\n \"displayText\": \"Diagram class \uD83C\uDFF7\",\n \"text\": `=for Diagram :caption('Caption of diagram')\n classDiagram\n Person <|-- Student\n Person <|-- Professor\n Person : +String name\n Person : +String phoneNumber\n Person : +String emailAddress\n Person: +purchaseParkingPass()\n Address \"1\" <-- \"0..1\" Person:lives at\n class Student{\n +int studentNumber\n +int averageMark\n +isEligibleToEnrol()\n +getSeminarsTaken()\n }\n class Professor{\n +int salary\n }\n class Address{\n +String street\n +String city\n +String state\n +int postalCode\n +String country\n -validate()\n +outputAsLabel() \n }\n\n`\n},\n{\n \"displayText\": \"code block with formatting \uD83C\uDFF7\",\n \"text\": `=begin code :allow<I B Z> \n\n=end code\n`\n},\n{\n \"displayText\": \"Toc head1, head2, head3\",\n \"text\": `=Toc head1, head2, head3\n`},\n{\n \"displayText\": \"Toc (with :title) \uD83C\uDFF7\",\n \"text\": `=for Toc :title('Table of content')\nhead1, head2, head2 \n\n`\n},\n{\n \"displayText\": \"Toc ( Images, Diagrams ) + tables \uD83C\uDFF7\",\n \"text\": `=for Toc :title('List of media')\nImage, Diagram\n=for Toc :title('List of tables')\ntable\n\n`\n},\n\n]\nexport default dict;\n"],
|
|
5
|
+
"mappings": "opBAAA,cAQA,aAAa,GAAI,GAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAE,MAAM,GAAE,MAAM,GAAE,MAAM,GAAE,MACnJ,AAAG,AAAa,MAAO,SAApB,YAA4B,OAAO,KAAS,GAAE,OAAO,IAAI,EAAE,EAAE,iBAAiB,EAAE,EAAE,gBAAgB,EAAE,EAAE,kBAAkB,EAAE,EAAE,qBAAqB,EAAE,EAAE,kBA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gB,UACT,IAAM,CAET,EAAgB,IAAI,SAAU,MAEpC,CAAC,EAAiB,IAGlB,gBAAC,MAAD,CAAK,UAAU,aACb,gBAAC,MAAD,CAAK,UAAY,EAAuB,gBAAiB,UACrD,gBAAC,MAAD,CAAK,UAAU,aAAa,aAAc,IAAI,EAAoB,IAC3C,YAAa,IAAI,EAAoB,KAE3D,GACG,gBAAC,aAAD,CACA,MAAO,EACP,eAAiB,GAAU,CAAE,EAAa,EAAQ,EAAiB,IACnE,eAAgB,CAAC,EAAQ,EAAM,IAAU,CACrC,EAAW,IAEX,EAAe,IAEnB,SAAU,EACV,QAAS,EACT,UAAU,cAGV,gBAAC,eAAD,CACI,MAAO,EACP,eAAiB,GAAU,CAAE,EAAa,EAAS,EAAiB,IACpE,SAAa,CAAC,EAAQ,EAAM,IAAU,CAClC,EAAW,IACX,EAAW,GACX,EAAe,IAEnB,SAAU,EACV,QAAS,EACT,UAAU,eAIhB",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podlite/editor-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Podlite React component",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -17,30 +17,29 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"clean": "rm -rf dist lib tsconfig.tsbuildinfo",
|
|
20
|
-
"build": "
|
|
21
|
-
"build:cjs": "
|
|
22
|
-
"build:esm": "
|
|
23
|
-
"test": "jest --
|
|
20
|
+
"build": "run-p build:cjs build:esm",
|
|
21
|
+
"build:cjs": "ts-node ./scripts/build.ts && tsc --declaration --emitDeclarationOnly",
|
|
22
|
+
"build:esm": "ts-node ./scripts/build_esm.ts && tsc --declaration --emitDeclarationOnly --outDir esm",
|
|
23
|
+
"test": "yarn g:jest --passWithNoTests"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"react-
|
|
26
|
+
"codemirror": "5.x",
|
|
27
|
+
"react-codemirror2": "^7.2.1",
|
|
28
|
+
"react-is": "^17.0.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/
|
|
32
|
-
"
|
|
31
|
+
"@types/node": "^17.0.7",
|
|
32
|
+
"@types/react": "^16.x",
|
|
33
|
+
"@yarnpkg/esbuild-plugin-pnp": "^2.0.0",
|
|
33
34
|
"esbuild": "^0.11.12",
|
|
34
|
-
"jest-serializer-html": "^7.0.0",
|
|
35
35
|
"prettier": "^2.2.1",
|
|
36
36
|
"react": "^16.12.0",
|
|
37
|
-
"react-dom": "^
|
|
38
|
-
"ts-
|
|
39
|
-
"typescript": "4.
|
|
37
|
+
"react-dom": "^16.12.0",
|
|
38
|
+
"ts-node": "^9.1.1",
|
|
39
|
+
"typescript": "4.5.4"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"react": "
|
|
43
|
-
"react-dom": "
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}
|
|
42
|
+
"react": "*",
|
|
43
|
+
"react-dom": "*"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/scripts/build.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { build } from 'esbuild';
|
|
2
|
+
import { pnpPlugin } from '@yarnpkg/esbuild-plugin-pnp';
|
|
3
|
+
|
|
4
|
+
build({
|
|
5
|
+
plugins: [pnpPlugin()],
|
|
6
|
+
bundle: true,
|
|
7
|
+
entryPoints: ['src/index.tsx'],
|
|
8
|
+
external: ['react', 'react-dom', 'codemirror', 'react-codemirror2'],
|
|
9
|
+
minify: true,
|
|
10
|
+
format: 'cjs',
|
|
11
|
+
target: 'node12.0',
|
|
12
|
+
sourcemap: true,
|
|
13
|
+
outfile: 'lib/index.js',
|
|
14
|
+
}).catch((e) => {
|
|
15
|
+
console.log('Build not successful', e.message);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { build } from 'esbuild';
|
|
2
|
+
import { pnpPlugin } from '@yarnpkg/esbuild-plugin-pnp';
|
|
3
|
+
|
|
4
|
+
build({
|
|
5
|
+
plugins: [pnpPlugin()],
|
|
6
|
+
bundle: true,
|
|
7
|
+
entryPoints: ['src/index.tsx'],
|
|
8
|
+
external: ['react', 'react-dom', 'codemirror', 'react-codemirror2'],
|
|
9
|
+
minify: true,
|
|
10
|
+
format: 'esm',
|
|
11
|
+
target: 'node12.0',
|
|
12
|
+
sourcemap: true,
|
|
13
|
+
outfile: 'esm/index.js',
|
|
14
|
+
}).catch((e) => {
|
|
15
|
+
console.log('Build not successful', e.message);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
package/src/Editor.css
CHANGED
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
word-break: normal;
|
|
134
134
|
min-width: 70%;
|
|
135
135
|
max-width: 100%;
|
|
136
|
-
margin:
|
|
136
|
+
margin: 1em auto;
|
|
137
137
|
border-spacing: 0;
|
|
138
138
|
border-collapse: collapse;
|
|
139
139
|
text-align: center;
|
|
@@ -210,7 +210,20 @@
|
|
|
210
210
|
display: block;
|
|
211
211
|
margin: auto;
|
|
212
212
|
}
|
|
213
|
+
|
|
214
|
+
.toc {
|
|
215
|
+
padding: 1rem;
|
|
216
|
+
}
|
|
213
217
|
|
|
218
|
+
.toc-list {
|
|
219
|
+
list-style: none;
|
|
220
|
+
font-size: .8rem;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.caption {
|
|
224
|
+
text-align: center;
|
|
225
|
+
font-size: 0.9rem;
|
|
226
|
+
}
|
|
214
227
|
/* End of pod6 */
|
|
215
228
|
|
|
216
229
|
|
package/src/dict.ts
CHANGED
|
@@ -14,14 +14,14 @@ const dict = [
|
|
|
14
14
|
"displayText": "head3",
|
|
15
15
|
"text": `=head3 `
|
|
16
16
|
},
|
|
17
|
+
{
|
|
18
|
+
"displayText": "item1 *",
|
|
19
|
+
"text": `=item1 `
|
|
20
|
+
},
|
|
17
21
|
{
|
|
18
22
|
"displayText": "item1 1.)",
|
|
19
23
|
"text": `=item1 # `
|
|
20
24
|
},
|
|
21
|
-
{
|
|
22
|
-
"displayText": "item1 *",
|
|
23
|
-
"text": `=item1 `
|
|
24
|
-
},
|
|
25
25
|
{
|
|
26
26
|
"displayText": "item (1., 2.) 🏷",
|
|
27
27
|
"text": `=item1 # item
|
|
@@ -42,7 +42,7 @@ const dict = [
|
|
|
42
42
|
`},
|
|
43
43
|
{
|
|
44
44
|
"displayText": "Image 🏷",
|
|
45
|
-
"text": `=Image
|
|
45
|
+
"text": `=Image https://github.com/zag/podlite-desktop/blob/master/dist-assets/linux-icon/256x256.png?raw=true
|
|
46
46
|
`,
|
|
47
47
|
},
|
|
48
48
|
{
|
|
@@ -72,9 +72,20 @@ Everything else 57
|
|
|
72
72
|
Shark + 0 + Fish
|
|
73
73
|
`
|
|
74
74
|
},
|
|
75
|
+
{
|
|
76
|
+
"displayText": "Diagram simple 🏷",
|
|
77
|
+
"text": `=begin Diagram :caption('Caption of diagram')
|
|
78
|
+
graph LR
|
|
79
|
+
A-->B
|
|
80
|
+
B-->C
|
|
81
|
+
C-->A
|
|
82
|
+
D-->C
|
|
83
|
+
=end Diagram
|
|
84
|
+
`
|
|
85
|
+
},
|
|
75
86
|
{
|
|
76
87
|
"displayText": "Diagram Sequence 🏷",
|
|
77
|
-
"text": `=Diagram
|
|
88
|
+
"text": `=for Diagram :caption('Caption of diagram')
|
|
78
89
|
sequenceDiagram
|
|
79
90
|
autonumber
|
|
80
91
|
Student->>Admin: Can I enrol this semester?
|
|
@@ -86,22 +97,11 @@ Everything else 57
|
|
|
86
97
|
Admin->>Professor: Assign student to tutor
|
|
87
98
|
Professor-->>Admin: Student is assigned
|
|
88
99
|
|
|
89
|
-
`
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
"displayText": "Diagram simple 🏷",
|
|
93
|
-
"text": `=begin Diagram
|
|
94
|
-
graph LR
|
|
95
|
-
A-->B
|
|
96
|
-
B-->C
|
|
97
|
-
C-->A
|
|
98
|
-
D-->C
|
|
99
|
-
=end Diagram
|
|
100
100
|
`
|
|
101
101
|
},
|
|
102
102
|
{
|
|
103
103
|
"displayText": "Diagram flowchart 🏷",
|
|
104
|
-
"text": `=Diagram
|
|
104
|
+
"text": `=for Diagram :caption('Caption of diagram')
|
|
105
105
|
graph LR
|
|
106
106
|
A[Square Rect] -- Link text --> B((Circle))
|
|
107
107
|
A --> C(Round Rect)
|
|
@@ -112,7 +112,7 @@ Everything else 57
|
|
|
112
112
|
},
|
|
113
113
|
{
|
|
114
114
|
"displayText": "Diagram class 🏷",
|
|
115
|
-
"text": `=Diagram
|
|
115
|
+
"text": `=for Diagram :caption('Caption of diagram')
|
|
116
116
|
classDiagram
|
|
117
117
|
Person <|-- Student
|
|
118
118
|
Person <|-- Professor
|
|
@@ -140,6 +140,33 @@ Everything else 57
|
|
|
140
140
|
+outputAsLabel()
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
`
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"displayText": "code block with formatting 🏷",
|
|
147
|
+
"text": `=begin code :allow<I B Z>
|
|
148
|
+
|
|
149
|
+
=end code
|
|
150
|
+
`
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"displayText": "Toc head1, head2, head3",
|
|
154
|
+
"text": `=Toc head1, head2, head3
|
|
155
|
+
`},
|
|
156
|
+
{
|
|
157
|
+
"displayText": "Toc (with :title) 🏷",
|
|
158
|
+
"text": `=for Toc :title('Table of content')
|
|
159
|
+
head1, head2, head2
|
|
160
|
+
|
|
161
|
+
`
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"displayText": "Toc ( Images, Diagrams ) + tables 🏷",
|
|
165
|
+
"text": `=for Toc :title('List of media')
|
|
166
|
+
Image, Diagram
|
|
167
|
+
=for Toc :title('List of tables')
|
|
168
|
+
table
|
|
169
|
+
|
|
143
170
|
`
|
|
144
171
|
},
|
|
145
172
|
|
package/src/index.tsx
CHANGED
|
@@ -260,14 +260,23 @@ useEffect(()=>{
|
|
|
260
260
|
var start = cur.ch;
|
|
261
261
|
var end = start;
|
|
262
262
|
while (end < curLine.length && /[\w$]/.test(curLine.charAt(end))) ++end;
|
|
263
|
-
while (start && /[
|
|
263
|
+
while (start && /[^=]/.test(curLine.charAt(start - 1))) --start;
|
|
264
264
|
var curWord = start !== end && curLine.slice(start, end);
|
|
265
|
-
var regex = new RegExp('
|
|
265
|
+
var regex = new RegExp('' + curWord, 'i');
|
|
266
|
+
// filter dict by regex and sort by mostly nearness
|
|
267
|
+
const filterDictByRegex = (arr, regex)=>{
|
|
268
|
+
const dict = arr.reduce((acc, item)=>{
|
|
269
|
+
if (item === null) { return acc; }
|
|
270
|
+
const result = (typeof item === 'object' && !Array.isArray(item)) ? item.displayText.match(regex): item.match(regex);
|
|
271
|
+
if ( result ) {
|
|
272
|
+
acc.push({item, index:result.index})
|
|
273
|
+
}
|
|
274
|
+
return acc;
|
|
275
|
+
}, []);
|
|
276
|
+
return dict.sort((a, b) => a.index - b.index).map(i=>i.item)
|
|
277
|
+
}
|
|
266
278
|
return {
|
|
267
|
-
list: (!curWord ? dictionary : dictionary
|
|
268
|
-
//@ts-ignore
|
|
269
|
-
return (typeof item === 'object' && !Array.isArray(item) && item !== null ) ? item.displayText.match(regex): item.match(regex);
|
|
270
|
-
})).sort(),
|
|
279
|
+
list: (!curWord ? dictionary : filterDictByRegex(dictionary,regex )),
|
|
271
280
|
from: CMirror.Pos(cur.line, start-1),
|
|
272
281
|
to: CMirror.Pos(cur.line, end)
|
|
273
282
|
}
|