diff --git a/README.md b/README.md index 6093973..dfffc6a 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,19 @@ Template.foo.config = function () { }; ``` +CodeMirror is an peer NPM dependency: you must `meteor npm install codemirror`. +The advantage of this approach is that you can choose which version to include. +To include a CodeMirror [theme](https://codemirror.net/theme/) or +[addon](https://codemirror.net/doc/manual.html#addons), use an `import` +statement to include the module or CSS. For example: + +```js +import 'codemirror/theme/monokai.css'; // theme +import 'codemirror/addon/fold/foldcode'; // addon +import 'codemirror/addon/fold/foldgutter'; // addon needing CSS +import 'codemirror/addon/fold/foldgutter.css'; // addon's CSS +``` + ## Server Configuration See this [example config file](settings-example.json) for the various settings that you can use. diff --git a/demo/.meteor/packages b/demo/.meteor/packages index a04c95c..44341d9 100644 --- a/demo/.meteor/packages +++ b/demo/.meteor/packages @@ -3,14 +3,17 @@ # 'meteor add' and 'meteor remove' will edit this file for you, # but you can also edit it by hand. -autopublish -insecure +autopublish@1.0.7 +insecure@1.0.7 standard-app-packages -stylus +stylus@=2.513.8 mizzao:sharejs mizzao:sharejs-codemirror mizzao:sharejs-ace twbs:bootstrap -standard-minifiers -modules -ecmascript +modules@0.12.2 +ecmascript@0.11.1 +standard-minifier-css +standard-minifier-js +shell-server +dynamic-import diff --git a/demo/.meteor/release b/demo/.meteor/release index 61f6c67..f866f52 100644 --- a/demo/.meteor/release +++ b/demo/.meteor/release @@ -1 +1 @@ -METEOR@1.4.2.3 +METEOR@1.7.0.4 diff --git a/demo/.meteor/versions b/demo/.meteor/versions index 0d68bc3..cd494c1 100644 --- a/demo/.meteor/versions +++ b/demo/.meteor/versions @@ -1,78 +1,84 @@ -allow-deny@1.0.5 +allow-deny@1.1.0 autopublish@1.0.7 -autoupdate@1.3.12 -babel-compiler@6.13.0 -babel-runtime@1.0.1 -base64@1.0.10 +autoupdate@1.4.1 +babel-compiler@7.1.1 +babel-runtime@1.2.4 +base64@1.0.11 binary-heap@1.0.10 -blaze@2.3.0 +blaze@2.3.3 blaze-tools@1.0.10 -boilerplate-generator@1.0.11 -caching-compiler@1.1.9 -caching-html-compiler@1.1.0 -callback-hook@1.0.10 -check@1.2.4 -ddp@1.2.5 -ddp-client@1.3.2 -ddp-common@1.2.8 -ddp-server@1.3.12 +boilerplate-generator@1.5.0 +caching-compiler@1.1.12 +caching-html-compiler@1.1.3 +callback-hook@1.1.0 +check@1.3.1 +ddp@1.4.0 +ddp-client@2.3.3 +ddp-common@1.4.0 +ddp-server@2.2.0 deps@1.0.12 -diff-sequence@1.0.7 -ecmascript@0.6.1 -ecmascript-runtime@0.3.15 -ejson@1.0.13 +diff-sequence@1.1.0 +dynamic-import@0.4.1 +ecmascript@0.11.1 +ecmascript-runtime@0.7.0 +ecmascript-runtime-client@0.7.2 +ecmascript-runtime-server@0.7.1 +ejson@1.1.0 fastclick@1.0.13 geojson-utils@1.0.10 handlebars@1.0.7 html-tools@1.0.11 htmljs@1.0.11 -http@1.2.10 -id-map@1.0.9 +http@1.4.1 +id-map@1.1.0 insecure@1.0.7 -jquery@1.11.10 -launch-screen@1.1.0 +jquery@1.11.11 +launch-screen@1.1.1 livedata@1.0.18 -logging@1.1.16 -meteor@1.6.0 +logging@1.1.20 +meteor@1.9.2 meteor-platform@1.2.6 -minifier-css@1.2.15 -minifier-js@1.2.15 -minimongo@1.0.19 -mizzao:sharejs@0.9.1 +minifier-css@1.3.1 +minifier-js@2.3.5 +minimongo@1.4.4 +mizzao:sharejs@0.10.1 mizzao:sharejs-ace@1.4.1 -mizzao:sharejs-codemirror@5.22.2 -mobile-status-bar@1.0.13 -modules@0.7.7 -modules-runtime@0.7.8 -mongo@1.1.14 -mongo-id@1.0.6 +mizzao:sharejs-codemirror@5.39.2 +mobile-status-bar@1.0.14 +modern-browsers@0.1.2 +modules@0.12.2 +modules-runtime@0.10.2 +mongo@1.5.1 +mongo-dev-server@1.1.0 +mongo-id@1.0.7 mongo-livedata@1.0.12 -npm-mongo@2.2.16_1 -observe-sequence@1.0.14 -ordered-dict@1.0.9 -promise@0.8.8 -random@1.0.10 -reactive-dict@1.1.8 +npm-mongo@3.0.11 +observe-sequence@1.0.16 +ordered-dict@1.1.0 +promise@0.11.1 +random@1.1.0 +reactive-dict@1.2.1 reactive-var@1.0.11 -reload@1.1.11 -retry@1.0.9 -routepolicy@1.0.12 -session@1.1.7 -spacebars@1.0.13 -spacebars-compiler@1.1.0 +reload@1.2.0 +retry@1.1.0 +routepolicy@1.0.13 +session@1.1.8 +shell-server@0.3.1 +socket-stream-client@0.2.2 +spacebars@1.0.15 +spacebars-compiler@1.1.3 standard-app-packages@1.0.9 -standard-minifier-css@1.3.2 -standard-minifier-js@1.2.1 -standard-minifiers@1.0.6 +standard-minifier-css@1.4.1 +standard-minifier-js@2.3.4 stylus@2.513.8 -templating@1.3.0 -templating-compiler@1.3.0 -templating-runtime@1.3.0 -templating-tools@1.1.0 -tracker@1.1.1 +templating@1.3.2 +templating-compiler@1.3.3 +templating-runtime@1.3.2 +templating-tools@1.1.2 +tracker@1.2.0 twbs:bootstrap@3.3.6 -ui@1.0.12 +ui@1.0.13 underscore@1.0.10 -url@1.0.11 -webapp@1.3.12 +url@1.2.0 +webapp@1.6.2 webapp-hashing@1.0.9 diff --git a/demo/client/client.js b/demo/client/client.js index 4441ca6..6818640 100644 --- a/demo/client/client.js +++ b/demo/client/client.js @@ -1,4 +1,12 @@ +import 'codemirror/addon/fold/foldcode'; +import 'codemirror/addon/fold/foldgutter'; +import 'codemirror/addon/fold/indent-fold'; +import 'codemirror/addon/hint/show-hint'; +import 'codemirror/addon/display/placeholder'; +import 'codemirror/theme/monokai.css'; +import 'codemirror/addon/fold/foldgutter.css'; +import 'codemirror/addon/hint/show-hint.css'; Template.docList.helpers({ documents: function() { diff --git a/demo/package.json b/demo/package.json old mode 100644 new mode 100755 index d411658..ec22662 --- a/demo/package.json +++ b/demo/package.json @@ -4,7 +4,10 @@ "description": "meteor-documents-demo =====================", "main": "index.js", "dependencies": { - "babel-runtime": "^6.20.0" + "@babel/runtime": "^7.0.0-beta.55", + "ace-builds": "^1.4.1", + "babel-runtime": "^6.20.0", + "codemirror": "^5.39.2" }, "devDependencies": {}, "scripts": { diff --git a/sharejs-base/package.js b/sharejs-base/package.js index aaed2c1..8d98f0f 100644 --- a/sharejs-base/package.js +++ b/sharejs-base/package.js @@ -9,7 +9,7 @@ Npm.depends({ // Fork of 0.6.3 that doesn't require("mongodb"): // https://github.com/meteor/meteor/issues/532#issuecomment-82635979 // Includes "Failed to parse" bugfix - share: "https://github.com/qeek/sharejs-tmp-fork/tarball/94c059bd4da24de8e6e90fb83484dd9c7b0efd59", + share: "https://github.com/mizzao/ShareJS/tarball/05b625ea1e7f7f27bd13ba7ed05102b38dd175e5", browserchannel: '1.2.0' }); diff --git a/sharejs-base/sharejs-server.js b/sharejs-base/sharejs-server.js index b93e6cd..bb73564 100644 --- a/sharejs-base/sharejs-server.js +++ b/sharejs-base/sharejs-server.js @@ -5,7 +5,7 @@ import { Meteor } from 'meteor/meteor'; const Future = Npm.require('fibers/future'); -export const ShareJS = ShareJS || {}; +export const ShareJS = {}; // See docs for options. Uses mongo by default to enable persistence. // Using special options from https://github.com/share/ShareJS/blob/master/src/server/index.coffee diff --git a/sharejs-codemirror/client.js b/sharejs-codemirror/client.js index 3978abc..deededc 100644 --- a/sharejs-codemirror/client.js +++ b/sharejs-codemirror/client.js @@ -5,17 +5,18 @@ import { Template } from 'meteor/templating' import { Blaze } from 'meteor/blaze' import { ShareJSConnector } from 'meteor/mizzao:sharejs' -import CodeMirror from 'codemirror'; -import 'codemirror/addon/fold/foldcode'; -import 'codemirror/addon/fold/foldgutter'; -import 'codemirror/addon/fold/indent-fold'; -import 'codemirror/addon/hint/show-hint'; -import 'codemirror/addon/display/placeholder'; - -import 'codemirror/lib/codemirror.css'; -import 'codemirror/theme/monokai.css'; -import 'codemirror/addon/fold/foldgutter.css'; -import 'codemirror/addon/hint/show-hint.css'; +try { + CodeMirror = require('codemirror'); + import 'codemirror/lib/codemirror.css'; +} catch (e) { + if (e.toString().match("Cannot find module")) { + console.error("Could not load NPM module `codemirror`, which is a peer " + + "dependency. You need to `meteor npm install --save codemirror`."); + return; + } else { + throw e; + } +} import './cm' @@ -59,4 +60,4 @@ class ShareJSCMConnector extends ShareJSConnector { } Template.registerHelper("sharejsCM", new Template('sharejsCM',function(){ return new ShareJSCMConnector(this).create(); -})); \ No newline at end of file +})); diff --git a/sharejs-codemirror/cm.js b/sharejs-codemirror/cm.js index 4b04e36..0204508 100644 --- a/sharejs-codemirror/cm.js +++ b/sharejs-codemirror/cm.js @@ -49,7 +49,9 @@ console.error("Text does not match!"); console.error("editor: " + editorText); console.error("ot: " + otText); - return editor.setValue(sharedoc.getText()); + suppress = true; + editor.setValue(sharedoc.getText()); + suppress = false; } }, 0); }; diff --git a/sharejs-codemirror/package.js b/sharejs-codemirror/package.js index 86790a3..393a882 100644 --- a/sharejs-codemirror/package.js +++ b/sharejs-codemirror/package.js @@ -1,61 +1,10 @@ Package.describe({ name: "mizzao:sharejs-codemirror", summary: "ShareJS with the CodeMirror Editor", - version: "5.22.0", + version: "5.39.2", git: "https://github.com/mizzao/meteor-sharejs.git" }); -Npm.depends({ - codemirror: "5.22.0" -}); - - -// Ugly-ass function stolen from http://stackoverflow.com/a/20794116/586086 -// TODO make this less ugly in future -function getFilesFromFolder(packageName, folder){ - // local imports - var _ = Npm.require("underscore"); - var fs = Npm.require("fs"); - var path = Npm.require("path"); - // helper function, walks recursively inside nested folders and return absolute filenames - function walk(folder){ - var filenames = []; - // get relative filenames from folder - var folderContent = fs.readdirSync(folder); - // iterate over the folder content to handle nested folders - _.each(folderContent, function(filename) { - // build absolute filename - var absoluteFilename = path.join(folder, filename); - // get file stats - var stat = fs.statSync(absoluteFilename); - if(stat.isDirectory()){ - // directory case => add filenames fetched from recursive call - filenames = filenames.concat(walk(absoluteFilename)); - } - else{ - // file case => simply add it - filenames.push(absoluteFilename); - } - }); - return filenames; - } - // save current working directory (something like "/home/user/projects/my-project") - var cwd = process.cwd(); - - var isRunningFromApp = fs.existsSync(path.resolve("packages")); - var packagePath = isRunningFromApp ? path.resolve("packages", packageName) : ""; - console.log(packagePath); - - packagePath = path.resolve(packagePath); - // chdir to our package directory - process.chdir(path.join(packagePath)); - // launch initial walk - var result = walk(folder); - // restore previous cwd - process.chdir(cwd); - return result; -} - Package.onUse(function (api) { api.versionsFrom("1.3.2"); @@ -64,10 +13,6 @@ Package.onUse(function (api) { api.use("mizzao:sharejs@0.9.0"); api.imply("mizzao:sharejs"); - // Add Ace files as assets that can be loaded by the client later - var codemirrorData = getFilesFromFolder("mizzao:sharejs-codemirror", ".npm/package/node_modules/codemirror"); - api.addAssets(codemirrorData, 'client'); - api.mainModule('client.js', 'client'); api.addFiles([ 'templates.html'