UNPKG

4.75 kBMarkdownView Raw
1# we-edit
2
3## install
4```sh
5npm install we-edit
6```
7
8## design : Loader load input file by Stream, convert it to redux store, create representation document based on state in the store to view/edit in browser, or emit to a file format
9* Loader (Input) -> we-edit models
10* Viewer/Editor/Emitter -> we-edit document
11* Represenation(pagination/html/text) -> view document
12* Emitter.Format -> output document
13* Stream(load,write) -> file/url/object/...
14
15## concept
16* state document as store to support multiple view/edit/emit tasks for same state
17* utilize React to evolve documents for different purpose, and to improve performance
18* installable plugin to extend system, including Input, Loader, Stream, Emitter Format, Representation
19
20
21###example
22```js
23 //to convert docx to pdf, svg, and html on console
24 import {Loader, Emitter, Stream, render} from "we-edit"
25 import iDocx from "we-edit/input-docx"
26 import lsFile from "we-edit/loader-stream-file"
27 import * from "we-edit/representation-pagination"
28 import * from "we-edit/representation-html"
29
30 iDocx.install()
31 lsFile.install()
32
33 render(
34 <Loader type="file" path="./test.docx">
35 <Emitter>
36 <Stream type="file" path="./test" name={({format})=>`test.${format}`}>
37 <Emitter.Format type="pdf"/>
38 <Emitter.Format type="svg"/>
39 <Emitter.Format type="html"/>
40 </Stream>
41 </Emitter>
42 </Loader>
43 )
44 .then(a=>console.log(a))
45 .catch(e=>console.error(e))
46
47 //to view test.docx in browser in pages
48 import {Loader, Viewer, Representation} from "we-edit"
49 import iDocx from "we-edit/input-docx"
50 import lsBrowser from "we-edit/loader-stream-browser"
51 import * from "we-edit/representation-pagination"
52 import ReactDOM from "react-dom"
53
54 iDocx.install()
55 lsBrowser.install()
56 ReactDOM.render(
57 <Loader type="browser">
58 <Viewer representation={<Representation type="pagination"/>}>
59 </Loader>,
60 document.body
61 )
62
63 //to edit test.docx in browser in pages
64 import {Loader, Editor, Representation} from "we-edit"
65 import iDocx from "we-edit/input-docx"
66 import lsBrowser from "we-edit/loader-stream-browser"
67 import * from "we-edit/representation-pagination"
68 import ReactDOM from "react-dom"
69
70 iDocx.install()
71 lsBrowser.install()
72 ReactDOM.render(
73 <Loader type="browser">
74 <Editor representation="pagination"/>
75 </Loader>,
76 document.body
77 )
78
79 //or without loader to use load of Input Type
80 iDocx.load(file)
81 .then(doc=>{
82 return ReactDOM.render(
83 <doc.Store>
84 <Editor representation="pagination"/>
85 </doc.Store>,
86 document.body
87 )
88 })
89
90 //to edit test.docx in browser in pages, and view in html
91 import {Loader, Editor, Representation} from "we-edit"
92 import iDocx from "we-edit/input-docx"
93 import lsBrowser from "we-edit/loader-stream-browser"
94 import * from "we-edit/representation-pagination"
95 import * from "we-edit/representation-html"
96 import ReactDOM from "react-dom"
97 iDocx.install()
98 lsBrowser.install()
99 ReactDOM.render(
100 <Loader type="browser">
101 <div style={{position:"absolute",left:0,width:500}}>
102 <Editor representation="pagination"/>
103 </div>
104
105 <div style={{position:"absolute",right:0,width:500}}>
106 <Viewer representation="html"/>
107 </div>
108 </Loader>,
109 document.body
110 )
111
112 //for more featur office, check we-edit-office
113```
114
115
116## API
117
118### top level
119
120#### Input: API to extend supported files
121* Viewable: base class to extend view only file
122* Editable: base class to extend editable file
123* get(type:string): get Viewable/EditableDocument type
124* resolveFileType({data,ext,name,type,mimeType, ...extendedProps}): try to find supported document type according to props
125* parse(file:Blob|Object|Buffer|...): parse input file to a we-edit models
126 * return object with following important fields
127 * Store: redux store reprensenting the input file
128 * doc: [Input Type].parse() return
129 * name, id,
130 * buildReducer: to extend reducer of Store
131
132#### React components
133* WeEdit: auto manage multiple document state stores
134* WeEditUI, Office, Workspace,
135 * Ribbon,
136 * StatusBar, TitleBar, Canvas, Dashboard,
137 * reducer,
138 * create
139
140* Loader[type]: input
141* Stream[type]: output
142* Stream.Collection
143
144* Editor
145* Viewer
146* Emitter
147* Emitter.Format[type]
148
149* document models
150
151* Represenation[type]
152* Representation.[html|text|pagination|...].Output
153
154
155* Cursor: wrapper of cursor shape
156* Selection: wrapper of selection shape
157
158* DocumentTree: tree structure of document
159
160#### state
161* ACTION
162* DOMAIN="we-edit"
163* reducer
164* getActive
165* getContent
166* getSelection
167* getFile
168* getUndos
169* getRedos
170
171#### tools
172* getClientRect
173* shallowEqual
174* uuid
175
176### document models
177* Unknown,
178* Ignore,
179* Container,
180* Document,
181* Section,
182* Paragraph,
183* Text,
184* Image,
185* Table,
186* Row,
187* Cell,
188* Frame,
189* Shape,
190* Anchor,
191* Page,