vapid 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.gitmodules +6 -0
- data/.rspec +2 -0
- data/.rubocop.yml +133 -0
- data/.travis.yml +5 -0
- data/Gemfile +10 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/vapid +7 -0
- data/lib/vapid.rb +24 -0
- data/lib/vapid/assets/javascripts/vapid/admin.coffee +2 -0
- data/lib/vapid/assets/stylesheets/vapid/admin.scss +72 -0
- data/lib/vapid/builder.rb +70 -0
- data/lib/vapid/cli.rb +96 -0
- data/lib/vapid/controllers/admin_controller.rb +282 -0
- data/lib/vapid/controllers/project_controller.rb +41 -0
- data/lib/vapid/db/migrate/20170202182310_create_groups.rb +12 -0
- data/lib/vapid/db/migrate/20170202183017_create_records.rb +11 -0
- data/lib/vapid/db/migrate/20170202185150_create_users.rb +11 -0
- data/lib/vapid/directive.rb +168 -0
- data/lib/vapid/directives.rb +30 -0
- data/lib/vapid/directives/audio.rb +27 -0
- data/lib/vapid/directives/group.rb +71 -0
- data/lib/vapid/directives/hide.rb +11 -0
- data/lib/vapid/directives/href.rb +11 -0
- data/lib/vapid/directives/image.rb +14 -0
- data/lib/vapid/directives/richtext.rb +15 -0
- data/lib/vapid/directives/show.rb +11 -0
- data/lib/vapid/directives/text.rb +24 -0
- data/lib/vapid/directives/video.rb +28 -0
- data/lib/vapid/generator_template/.gitignore +21 -0
- data/lib/vapid/generator_template/Gemfile.tt +13 -0
- data/lib/vapid/generator_template/README.md +0 -0
- data/lib/vapid/generator_template/assets/favicon.ico +0 -0
- data/lib/vapid/generator_template/assets/images/.keep +0 -0
- data/lib/vapid/generator_template/assets/javascripts/.keep +0 -0
- data/lib/vapid/generator_template/assets/stylesheets/.keep +0 -0
- data/lib/vapid/generator_template/assets/stylesheets/application.css +120 -0
- data/lib/vapid/generator_template/config.ru +3 -0
- data/lib/vapid/generator_template/config/database.yml +12 -0
- data/lib/vapid/generator_template/config/settings.yml.tt +11 -0
- data/lib/vapid/generator_template/templates/index.html.erb +25 -0
- data/lib/vapid/generator_template/templates/layouts/default.html.erb +22 -0
- data/lib/vapid/models.rb +18 -0
- data/lib/vapid/models/group.rb +36 -0
- data/lib/vapid/models/record.rb +30 -0
- data/lib/vapid/models/user.rb +16 -0
- data/lib/vapid/server.rb +93 -0
- data/lib/vapid/settings.rb +13 -0
- data/lib/vapid/template.rb +79 -0
- data/lib/vapid/template/node.rb +91 -0
- data/lib/vapid/template/parser.rb +50 -0
- data/lib/vapid/vendor/semantic-ui/.versions +4 -0
- data/lib/vapid/vendor/semantic-ui/LICENSE +22 -0
- data/lib/vapid/vendor/semantic-ui/README.md +7 -0
- data/lib/vapid/vendor/semantic-ui/components/accordion.css +252 -0
- data/lib/vapid/vendor/semantic-ui/components/accordion.js +610 -0
- data/lib/vapid/vendor/semantic-ui/components/accordion.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/accordion.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/ad.css +275 -0
- data/lib/vapid/vendor/semantic-ui/components/ad.min.css +10 -0
- data/lib/vapid/vendor/semantic-ui/components/api.js +1167 -0
- data/lib/vapid/vendor/semantic-ui/components/api.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/breadcrumb.css +124 -0
- data/lib/vapid/vendor/semantic-ui/components/breadcrumb.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/button.css +3450 -0
- data/lib/vapid/vendor/semantic-ui/components/button.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/card.css +964 -0
- data/lib/vapid/vendor/semantic-ui/components/card.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/checkbox.css +625 -0
- data/lib/vapid/vendor/semantic-ui/components/checkbox.js +831 -0
- data/lib/vapid/vendor/semantic-ui/components/checkbox.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/checkbox.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/colorize.js +274 -0
- data/lib/vapid/vendor/semantic-ui/components/colorize.min.js +11 -0
- data/lib/vapid/vendor/semantic-ui/components/comment.css +270 -0
- data/lib/vapid/vendor/semantic-ui/components/comment.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/container.css +147 -0
- data/lib/vapid/vendor/semantic-ui/components/container.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/dimmer.css +200 -0
- data/lib/vapid/vendor/semantic-ui/components/dimmer.js +708 -0
- data/lib/vapid/vendor/semantic-ui/components/dimmer.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/dimmer.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/divider.css +260 -0
- data/lib/vapid/vendor/semantic-ui/components/divider.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/dropdown.css +1442 -0
- data/lib/vapid/vendor/semantic-ui/components/dropdown.js +3767 -0
- data/lib/vapid/vendor/semantic-ui/components/dropdown.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/dropdown.min.js +11 -0
- data/lib/vapid/vendor/semantic-ui/components/embed.css +166 -0
- data/lib/vapid/vendor/semantic-ui/components/embed.js +696 -0
- data/lib/vapid/vendor/semantic-ui/components/embed.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/embed.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/feed.css +296 -0
- data/lib/vapid/vendor/semantic-ui/components/feed.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/flag.css +1031 -0
- data/lib/vapid/vendor/semantic-ui/components/flag.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/form.css +1067 -0
- data/lib/vapid/vendor/semantic-ui/components/form.js +1603 -0
- data/lib/vapid/vendor/semantic-ui/components/form.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/form.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/grid.css +2002 -0
- data/lib/vapid/vendor/semantic-ui/components/grid.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/header.css +721 -0
- data/lib/vapid/vendor/semantic-ui/components/header.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/icon.css +3292 -0
- data/lib/vapid/vendor/semantic-ui/components/icon.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/image.css +306 -0
- data/lib/vapid/vendor/semantic-ui/components/image.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/input.css +510 -0
- data/lib/vapid/vendor/semantic-ui/components/input.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/item.css +486 -0
- data/lib/vapid/vendor/semantic-ui/components/item.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/label.css +1307 -0
- data/lib/vapid/vendor/semantic-ui/components/label.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/list.css +951 -0
- data/lib/vapid/vendor/semantic-ui/components/list.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/loader.css +347 -0
- data/lib/vapid/vendor/semantic-ui/components/loader.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/menu.css +2002 -0
- data/lib/vapid/vendor/semantic-ui/components/menu.min.css +1 -0
- data/lib/vapid/vendor/semantic-ui/components/message.css +477 -0
- data/lib/vapid/vendor/semantic-ui/components/message.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/modal.css +502 -0
- data/lib/vapid/vendor/semantic-ui/components/modal.js +913 -0
- data/lib/vapid/vendor/semantic-ui/components/modal.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/modal.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/nag.css +147 -0
- data/lib/vapid/vendor/semantic-ui/components/nag.js +507 -0
- data/lib/vapid/vendor/semantic-ui/components/nag.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/nag.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/popup.css +733 -0
- data/lib/vapid/vendor/semantic-ui/components/popup.js +1475 -0
- data/lib/vapid/vendor/semantic-ui/components/popup.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/popup.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/progress.css +516 -0
- data/lib/vapid/vendor/semantic-ui/components/progress.js +931 -0
- data/lib/vapid/vendor/semantic-ui/components/progress.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/progress.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/rail.css +152 -0
- data/lib/vapid/vendor/semantic-ui/components/rail.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/rating.css +263 -0
- data/lib/vapid/vendor/semantic-ui/components/rating.js +508 -0
- data/lib/vapid/vendor/semantic-ui/components/rating.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/rating.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/reset.css +424 -0
- data/lib/vapid/vendor/semantic-ui/components/reset.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/reveal.css +284 -0
- data/lib/vapid/vendor/semantic-ui/components/reveal.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/search.css +408 -0
- data/lib/vapid/vendor/semantic-ui/components/search.js +1442 -0
- data/lib/vapid/vendor/semantic-ui/components/search.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/search.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/segment.css +798 -0
- data/lib/vapid/vendor/semantic-ui/components/segment.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/shape.css +157 -0
- data/lib/vapid/vendor/semantic-ui/components/shape.js +921 -0
- data/lib/vapid/vendor/semantic-ui/components/shape.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/shape.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/sidebar.css +634 -0
- data/lib/vapid/vendor/semantic-ui/components/sidebar.js +1036 -0
- data/lib/vapid/vendor/semantic-ui/components/sidebar.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/sidebar.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/site.css +160 -0
- data/lib/vapid/vendor/semantic-ui/components/site.js +487 -0
- data/lib/vapid/vendor/semantic-ui/components/site.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/site.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/state.js +708 -0
- data/lib/vapid/vendor/semantic-ui/components/state.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/statistic.css +569 -0
- data/lib/vapid/vendor/semantic-ui/components/statistic.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/step.css +623 -0
- data/lib/vapid/vendor/semantic-ui/components/step.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/sticky.css +78 -0
- data/lib/vapid/vendor/semantic-ui/components/sticky.js +942 -0
- data/lib/vapid/vendor/semantic-ui/components/sticky.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/sticky.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/tab.css +91 -0
- data/lib/vapid/vendor/semantic-ui/components/tab.js +952 -0
- data/lib/vapid/vendor/semantic-ui/components/tab.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/tab.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/table.css +1108 -0
- data/lib/vapid/vendor/semantic-ui/components/table.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/transition.css +1964 -0
- data/lib/vapid/vendor/semantic-ui/components/transition.js +1095 -0
- data/lib/vapid/vendor/semantic-ui/components/transition.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/transition.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/video.css +125 -0
- data/lib/vapid/vendor/semantic-ui/components/video.js +532 -0
- data/lib/vapid/vendor/semantic-ui/components/video.min.css +10 -0
- data/lib/vapid/vendor/semantic-ui/components/video.min.js +11 -0
- data/lib/vapid/vendor/semantic-ui/components/visibility.js +1288 -0
- data/lib/vapid/vendor/semantic-ui/components/visibility.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/visit.js +517 -0
- data/lib/vapid/vendor/semantic-ui/components/visit.min.js +11 -0
- data/lib/vapid/vendor/semantic-ui/package.js +34 -0
- data/lib/vapid/vendor/semantic-ui/package.json +20 -0
- data/lib/vapid/vendor/semantic-ui/semantic.css +36844 -0
- data/lib/vapid/vendor/semantic-ui/semantic.js +22617 -0
- data/lib/vapid/vendor/semantic-ui/semantic.min.css +364 -0
- data/lib/vapid/vendor/semantic-ui/semantic.min.js +19 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.eot +0 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.otf +0 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.svg +2671 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.ttf +0 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.woff +0 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.woff2 +0 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/images/flags.png +0 -0
- data/lib/vapid/vendor/trix/.blade.yml +45 -0
- data/lib/vapid/vendor/trix/.github/ISSUE_TEMPLATE.md +13 -0
- data/lib/vapid/vendor/trix/.gitignore +3 -0
- data/lib/vapid/vendor/trix/.ruby-version +1 -0
- data/lib/vapid/vendor/trix/.travis.yml +6 -0
- data/lib/vapid/vendor/trix/CONDUCT.md +79 -0
- data/lib/vapid/vendor/trix/Gemfile +17 -0
- data/lib/vapid/vendor/trix/Gemfile.lock +152 -0
- data/lib/vapid/vendor/trix/LICENSE +20 -0
- data/lib/vapid/vendor/trix/README.md +382 -0
- data/lib/vapid/vendor/trix/assets/index.html +55 -0
- data/lib/vapid/vendor/trix/assets/trix-core.coffee +2 -0
- data/lib/vapid/vendor/trix/assets/trix.coffee +3 -0
- data/lib/vapid/vendor/trix/assets/trix.scss +5 -0
- data/lib/vapid/vendor/trix/assets/trix/banner/index.coffee.erb +3 -0
- data/lib/vapid/vendor/trix/assets/trix/banner/index.scss.erb +3 -0
- data/lib/vapid/vendor/trix/assets/trix/banner/index.txt.erb +3 -0
- data/lib/vapid/vendor/trix/assets/trix/images/README.md +6 -0
- data/lib/vapid/vendor/trix/assets/trix/images/attach.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/bold.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/bullets.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/code.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/heading_1.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/italic.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/link.svg +6 -0
- data/lib/vapid/vendor/trix/assets/trix/images/nesting_level_decrease.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/nesting_level_increase.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/numbers.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/quote.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/redo.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/remove.svg +4 -0
- data/lib/vapid/vendor/trix/assets/trix/images/strike.svg +6 -0
- data/lib/vapid/vendor/trix/assets/trix/images/trash.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/undo.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/attachments.scss +112 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/content.scss +88 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/editor.scss +8 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/icons.scss +14 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/media-queries.scss +7 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/toolbar.scss +194 -0
- data/lib/vapid/vendor/trix/bin/blade +16 -0
- data/lib/vapid/vendor/trix/bin/ci +21 -0
- data/lib/vapid/vendor/trix/bin/rackup +16 -0
- data/lib/vapid/vendor/trix/bin/rake +16 -0
- data/lib/vapid/vendor/trix/bin/release +139 -0
- data/lib/vapid/vendor/trix/bin/setup +69 -0
- data/lib/vapid/vendor/trix/bin/update-status-image +100 -0
- data/lib/vapid/vendor/trix/bower.json +34 -0
- data/lib/vapid/vendor/trix/config.ru +32 -0
- data/lib/vapid/vendor/trix/dist/trix-core.js +11 -0
- data/lib/vapid/vendor/trix/dist/trix.css +286 -0
- data/lib/vapid/vendor/trix/dist/trix.js +20 -0
- data/lib/vapid/vendor/trix/package.json +29 -0
- data/lib/vapid/vendor/trix/polyfills/polyfills.coffee +3 -0
- data/lib/vapid/vendor/trix/polyfills/set.coffee +24 -0
- data/lib/vapid/vendor/trix/polyfills/vendor/CustomElements.js +1029 -0
- data/lib/vapid/vendor/trix/polyfills/vendor/README.md +2 -0
- data/lib/vapid/vendor/trix/polyfills/vendor/promise.js +228 -0
- data/lib/vapid/vendor/trix/src/trix/VERSION +1 -0
- data/lib/vapid/vendor/trix/src/trix/config/block_attributes.coffee +37 -0
- data/lib/vapid/vendor/trix/src/trix/config/css.coffee +12 -0
- data/lib/vapid/vendor/trix/src/trix/config/file_size_formatting.coffee +22 -0
- data/lib/vapid/vendor/trix/src/trix/config/index.coffee +9 -0
- data/lib/vapid/vendor/trix/src/trix/config/lang.coffee +26 -0
- data/lib/vapid/vendor/trix/src/trix/config/selection_elements.coffee +26 -0
- data/lib/vapid/vendor/trix/src/trix/config/serialization.coffee +63 -0
- data/lib/vapid/vendor/trix/src/trix/config/text_attributes.coffee +25 -0
- data/lib/vapid/vendor/trix/src/trix/config/toolbar.coffee +41 -0
- data/lib/vapid/vendor/trix/src/trix/config/undo_interval.coffee +7 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/attachment_editor_controller.coffee +104 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/composition_controller.coffee +117 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/controller.coffee +3 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/editor_controller.coffee +369 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/input/composition_input.coffee +57 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/input_controller.coffee +473 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/toolbar_controller.coffee +173 -0
- data/lib/vapid/vendor/trix/src/trix/core/basic_object.coffee +44 -0
- data/lib/vapid/vendor/trix/src/trix/core/collections/element_store.coffee +21 -0
- data/lib/vapid/vendor/trix/src/trix/core/collections/hash.coffee +98 -0
- data/lib/vapid/vendor/trix/src/trix/core/collections/index.coffee +4 -0
- data/lib/vapid/vendor/trix/src/trix/core/collections/object_group.coffee +37 -0
- data/lib/vapid/vendor/trix/src/trix/core/collections/object_map.coffee +10 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/arrays.coffee +34 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/config.coffee +23 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/custom_elements.coffee +45 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/dom.coffee +185 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/extend.coffee +4 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/functions.coffee +3 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/global.coffee +23 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/index.coffee +10 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/objects.coffee +11 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/ranges.coffee +33 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/selection.coffee +25 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/strings.coffee +46 -0
- data/lib/vapid/vendor/trix/src/trix/core/index.coffee +4 -0
- data/lib/vapid/vendor/trix/src/trix/core/object.coffee +33 -0
- data/lib/vapid/vendor/trix/src/trix/core/utilities/index.coffee +2 -0
- data/lib/vapid/vendor/trix/src/trix/core/utilities/operation.coffee +37 -0
- data/lib/vapid/vendor/trix/src/trix/core/utilities/utf16_string.coffee +93 -0
- data/lib/vapid/vendor/trix/src/trix/elements/trix_editor_element.coffee +166 -0
- data/lib/vapid/vendor/trix/src/trix/elements/trix_toolbar_element.coffee +28 -0
- data/lib/vapid/vendor/trix/src/trix/index.coffee.erb +14 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/control_element.coffee +60 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/debugger.coffee +104 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/element.coffee +86 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/index.coffee +17 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/polyfills/vendor/details-element-polyfill.js +5 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/debug.jst.eco +17 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/document.jst.eco +33 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/performance.jst.eco +10 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/render.jst.eco +1 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/selection.jst.eco +5 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/undo.jst.eco +13 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/view.coffee +58 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/debug_view.coffee +33 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/document_view.coffee +12 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/performance_view.coffee +51 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/render_view.coffee +21 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/selection_view.coffee +33 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/undo_view.coffee +12 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/deserializer.coffee +55 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/index.coffee +5 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player.coffee +60 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player_controller.coffee +43 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player_element.coffee +32 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player_view.coffee +133 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/recorder.coffee +82 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/recording.coffee +54 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/serializer.coffee +61 -0
- data/lib/vapid/vendor/trix/src/trix/models/attachment.coffee +157 -0
- data/lib/vapid/vendor/trix/src/trix/models/attachment_manager.coffee +24 -0
- data/lib/vapid/vendor/trix/src/trix/models/attachment_piece.coffee +47 -0
- data/lib/vapid/vendor/trix/src/trix/models/block.coffee +230 -0
- data/lib/vapid/vendor/trix/src/trix/models/composition.coffee +521 -0
- data/lib/vapid/vendor/trix/src/trix/models/document.coffee +538 -0
- data/lib/vapid/vendor/trix/src/trix/models/editor.coffee +141 -0
- data/lib/vapid/vendor/trix/src/trix/models/html_parser.coffee +335 -0
- data/lib/vapid/vendor/trix/src/trix/models/line_break_insertion.coffee +31 -0
- data/lib/vapid/vendor/trix/src/trix/models/location_mapper.coffee +156 -0
- data/lib/vapid/vendor/trix/src/trix/models/managed_attachment.coffee +28 -0
- data/lib/vapid/vendor/trix/src/trix/models/piece.coffee +95 -0
- data/lib/vapid/vendor/trix/src/trix/models/point_mapper.coffee +28 -0
- data/lib/vapid/vendor/trix/src/trix/models/selection_manager.coffee +129 -0
- data/lib/vapid/vendor/trix/src/trix/models/splittable_list.coffee +168 -0
- data/lib/vapid/vendor/trix/src/trix/models/string_piece.coffee +49 -0
- data/lib/vapid/vendor/trix/src/trix/models/text.coffee +168 -0
- data/lib/vapid/vendor/trix/src/trix/models/undo_manager.coffee +40 -0
- data/lib/vapid/vendor/trix/src/trix/observers/mutation_observer.coffee +131 -0
- data/lib/vapid/vendor/trix/src/trix/observers/selection_change_observer.coffee +56 -0
- data/lib/vapid/vendor/trix/src/trix/operations/file_verification_operation.coffee +15 -0
- data/lib/vapid/vendor/trix/src/trix/operations/image_preload_operation.coffee +15 -0
- data/lib/vapid/vendor/trix/src/trix/views/attachment_view.coffee +99 -0
- data/lib/vapid/vendor/trix/src/trix/views/block_view.coffee +37 -0
- data/lib/vapid/vendor/trix/src/trix/views/document_view.coffee +68 -0
- data/lib/vapid/vendor/trix/src/trix/views/object_group_view.coffee +23 -0
- data/lib/vapid/vendor/trix/src/trix/views/object_view.coffee +86 -0
- data/lib/vapid/vendor/trix/src/trix/views/piece_view.coffee +97 -0
- data/lib/vapid/vendor/trix/src/trix/views/previewable_attachment_view.coffee +49 -0
- data/lib/vapid/vendor/trix/src/trix/views/text_view.coffee +30 -0
- data/lib/vapid/vendor/trix/test/.gitignore +1 -0
- data/lib/vapid/vendor/trix/test/src/system/attachment_test.coffee +70 -0
- data/lib/vapid/vendor/trix/test/src/system/basic_input_test.coffee +68 -0
- data/lib/vapid/vendor/trix/test/src/system/block_formatting_test.coffee +602 -0
- data/lib/vapid/vendor/trix/test/src/system/caching_test.coffee +21 -0
- data/lib/vapid/vendor/trix/test/src/system/composition_input_test.coffee +138 -0
- data/lib/vapid/vendor/trix/test/src/system/cursor_movement_test.coffee +54 -0
- data/lib/vapid/vendor/trix/test/src/system/custom_element_test.coffee +314 -0
- data/lib/vapid/vendor/trix/test/src/system/html_loading_test.coffee +62 -0
- data/lib/vapid/vendor/trix/test/src/system/html_replacement_test.coffee +101 -0
- data/lib/vapid/vendor/trix/test/src/system/installation_process_test.coffee +59 -0
- data/lib/vapid/vendor/trix/test/src/system/list_formatting_test.coffee +70 -0
- data/lib/vapid/vendor/trix/test/src/system/mutation_input_test.coffee +73 -0
- data/lib/vapid/vendor/trix/test/src/system/pasting_test.coffee +215 -0
- data/lib/vapid/vendor/trix/test/src/system/text_formatting_test.coffee +151 -0
- data/lib/vapid/vendor/trix/test/src/system/undo_test.coffee +48 -0
- data/lib/vapid/vendor/trix/test/src/test.coffee +16 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/assertions.coffee +38 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/editor_helpers.coffee +37 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_empty.jst.eco +1 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_html.jst.eco +2 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_in_table.jst.eco +7 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_block_styles.jst.eco +6 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_bold_styles.jst.eco +7 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_image.jst.eco +2 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_styled_content.jst.eco +7 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_toolbar_and_input.jst.eco +5 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/fixtures.coffee +536 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/logo.png +0 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/index.coffee +18 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/input_helpers.coffee +183 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/selection_helpers.coffee +91 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/test_helpers.coffee +72 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/test_stubs.coffee +31 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/toolbar_helpers.coffee +45 -0
- data/lib/vapid/vendor/trix/test/src/unit/attachment_test.coffee +23 -0
- data/lib/vapid/vendor/trix/test/src/unit/block_test.coffee +22 -0
- data/lib/vapid/vendor/trix/test/src/unit/composition_test.coffee +13 -0
- data/lib/vapid/vendor/trix/test/src/unit/document_test.coffee +11 -0
- data/lib/vapid/vendor/trix/test/src/unit/document_view_test.coffee +6 -0
- data/lib/vapid/vendor/trix/test/src/unit/html_parser_test.coffee +162 -0
- data/lib/vapid/vendor/trix/test/src/unit/location_mapper_test.coffee +185 -0
- data/lib/vapid/vendor/trix/test/src/unit/mutation_observer_test.coffee +84 -0
- data/lib/vapid/vendor/trix/test/src/unit/serialization_test.coffee +7 -0
- data/lib/vapid/vendor/trix/test/src/unit/string_change_summary_test.coffee +57 -0
- data/lib/vapid/vendor/trix/test/src/unit/text_test.coffee +19 -0
- data/lib/vapid/vendor/trix/test/vendor/rangy-core.js +3845 -0
- data/lib/vapid/vendor/trix/test/vendor/rangy-textrange.js +1930 -0
- data/lib/vapid/version.rb +4 -0
- data/lib/vapid/views/admin/install.html.erb +19 -0
- data/lib/vapid/views/admin/login.html.erb +11 -0
- data/lib/vapid/views/admin/overview/index.html.erb +1 -0
- data/lib/vapid/views/admin/records/_form.erb +9 -0
- data/lib/vapid/views/admin/records/edit.html.erb +5 -0
- data/lib/vapid/views/admin/records/index.html.erb +38 -0
- data/lib/vapid/views/admin/records/new.html.erb +3 -0
- data/lib/vapid/views/errors/404.html.erb +1 -0
- data/lib/vapid/views/errors/500.html.erb +1 -0
- data/lib/vapid/views/layouts/admin.html.erb +41 -0
- data/lib/vapid/views/layouts/admin_form.html.erb +22 -0
- data/lib/vapid/views/layouts/error.html.erb +11 -0
- data/vapid.gemspec +48 -0
- metadata +811 -0
@@ -0,0 +1,538 @@
|
|
1
|
+
#= require trix/models/block
|
2
|
+
#= require trix/models/splittable_list
|
3
|
+
#= require trix/models/html_parser
|
4
|
+
|
5
|
+
{arraysAreEqual, normalizeRange, rangeIsCollapsed, getBlockConfig} = Trix
|
6
|
+
|
7
|
+
class Trix.Document extends Trix.Object
|
8
|
+
@fromJSON: (documentJSON) ->
|
9
|
+
blocks = for blockJSON in documentJSON
|
10
|
+
Trix.Block.fromJSON blockJSON
|
11
|
+
new this blocks
|
12
|
+
|
13
|
+
@fromHTML: (html, options) ->
|
14
|
+
Trix.HTMLParser.parse(html, options).getDocument()
|
15
|
+
|
16
|
+
@fromString: (string, textAttributes) ->
|
17
|
+
text = Trix.Text.textForStringWithAttributes(string, textAttributes)
|
18
|
+
new this [new Trix.Block text]
|
19
|
+
|
20
|
+
|
21
|
+
constructor: (blocks = []) ->
|
22
|
+
super
|
23
|
+
blocks = [new Trix.Block] if blocks.length is 0
|
24
|
+
@blockList = Trix.SplittableList.box(blocks)
|
25
|
+
|
26
|
+
isEmpty: ->
|
27
|
+
@blockList.length is 1 and (
|
28
|
+
block = @getBlockAtIndex(0)
|
29
|
+
block.isEmpty() and not block.hasAttributes()
|
30
|
+
)
|
31
|
+
|
32
|
+
copy: (options = {})->
|
33
|
+
blocks = if options.consolidateBlocks
|
34
|
+
@blockList.consolidate().toArray()
|
35
|
+
else
|
36
|
+
@blockList.toArray()
|
37
|
+
|
38
|
+
new @constructor blocks
|
39
|
+
|
40
|
+
copyUsingObjectsFromDocument: (sourceDocument) ->
|
41
|
+
objectMap = new Trix.ObjectMap sourceDocument.getObjects()
|
42
|
+
@copyUsingObjectMap(objectMap)
|
43
|
+
|
44
|
+
copyUsingObjectMap: (objectMap) ->
|
45
|
+
blocks = for block in @getBlocks()
|
46
|
+
if mappedBlock = objectMap.find(block)
|
47
|
+
mappedBlock
|
48
|
+
else
|
49
|
+
block.copyUsingObjectMap(objectMap)
|
50
|
+
new @constructor blocks
|
51
|
+
|
52
|
+
copyWithBaseBlockAttributes: (blockAttributes = []) ->
|
53
|
+
blocks = for block in @getBlocks()
|
54
|
+
attributes = blockAttributes.concat(block.getAttributes())
|
55
|
+
block.copyWithAttributes(attributes)
|
56
|
+
new @constructor blocks
|
57
|
+
|
58
|
+
replaceBlock: (oldBlock, newBlock) ->
|
59
|
+
index = @blockList.indexOf(oldBlock)
|
60
|
+
return this if index is -1
|
61
|
+
new @constructor @blockList.replaceObjectAtIndex(newBlock, index)
|
62
|
+
|
63
|
+
insertDocumentAtRange: (document, range) ->
|
64
|
+
{blockList} = document
|
65
|
+
[position] = range = normalizeRange(range)
|
66
|
+
{index, offset} = @locationFromPosition(position)
|
67
|
+
|
68
|
+
result = this
|
69
|
+
block = @getBlockAtPosition(position)
|
70
|
+
|
71
|
+
if rangeIsCollapsed(range) and block.isEmpty() and not block.hasAttributes()
|
72
|
+
result = new @constructor result.blockList.removeObjectAtIndex(index)
|
73
|
+
else if block.getBlockBreakPosition() is offset
|
74
|
+
position++
|
75
|
+
|
76
|
+
result = result.removeTextAtRange(range)
|
77
|
+
new @constructor result.blockList.insertSplittableListAtPosition(blockList, position)
|
78
|
+
|
79
|
+
mergeDocumentAtRange: (document, range) ->
|
80
|
+
[startPosition] = range = normalizeRange(range)
|
81
|
+
startLocation = @locationFromPosition(startPosition)
|
82
|
+
blockAttributes = @getBlockAtIndex(startLocation.index).getAttributes()
|
83
|
+
baseBlockAttributes = document.getBaseBlockAttributes()
|
84
|
+
trailingBlockAttributes = blockAttributes.slice(-baseBlockAttributes.length)
|
85
|
+
|
86
|
+
if arraysAreEqual(baseBlockAttributes, trailingBlockAttributes)
|
87
|
+
leadingBlockAttributes = blockAttributes.slice(0, -baseBlockAttributes.length)
|
88
|
+
formattedDocument = document.copyWithBaseBlockAttributes(leadingBlockAttributes)
|
89
|
+
else
|
90
|
+
formattedDocument = document.copy(consolidateBlocks: true).copyWithBaseBlockAttributes(blockAttributes)
|
91
|
+
|
92
|
+
blockCount = formattedDocument.getBlockCount()
|
93
|
+
firstBlock = formattedDocument.getBlockAtIndex(0)
|
94
|
+
|
95
|
+
if arraysAreEqual(blockAttributes, firstBlock.getAttributes())
|
96
|
+
firstText = firstBlock.getTextWithoutBlockBreak()
|
97
|
+
result = @insertTextAtRange(firstText, range)
|
98
|
+
|
99
|
+
if blockCount > 1
|
100
|
+
formattedDocument = new @constructor formattedDocument.getBlocks().slice(1)
|
101
|
+
position = startPosition + firstText.getLength()
|
102
|
+
result = result.insertDocumentAtRange(formattedDocument, position)
|
103
|
+
else
|
104
|
+
result = @insertDocumentAtRange(formattedDocument, range)
|
105
|
+
|
106
|
+
result
|
107
|
+
|
108
|
+
insertTextAtRange: (text, range) ->
|
109
|
+
[startPosition] = range = normalizeRange(range)
|
110
|
+
{index, offset} = @locationFromPosition(startPosition)
|
111
|
+
|
112
|
+
document = @removeTextAtRange(range)
|
113
|
+
new @constructor document.blockList.editObjectAtIndex index, (block) ->
|
114
|
+
block.copyWithText(block.text.insertTextAtPosition(text, offset))
|
115
|
+
|
116
|
+
removeTextAtRange: (range) ->
|
117
|
+
[leftPosition, rightPosition] = range = normalizeRange(range)
|
118
|
+
return this if rangeIsCollapsed(range)
|
119
|
+
[leftLocation, rightLocation] = @locationRangeFromRange(range)
|
120
|
+
|
121
|
+
leftIndex = leftLocation.index
|
122
|
+
leftOffset = leftLocation.offset
|
123
|
+
leftBlock = @getBlockAtIndex(leftIndex)
|
124
|
+
|
125
|
+
rightIndex = rightLocation.index
|
126
|
+
rightOffset = rightLocation.offset
|
127
|
+
rightBlock = @getBlockAtIndex(rightIndex)
|
128
|
+
|
129
|
+
removeRightNewline = rightPosition - leftPosition is 1 and
|
130
|
+
leftBlock.getBlockBreakPosition() is leftOffset and
|
131
|
+
rightBlock.getBlockBreakPosition() isnt rightOffset and
|
132
|
+
rightBlock.text.getStringAtPosition(rightOffset) is "\n"
|
133
|
+
|
134
|
+
if removeRightNewline
|
135
|
+
blocks = @blockList.editObjectAtIndex rightIndex, (block) ->
|
136
|
+
block.copyWithText(block.text.removeTextAtRange([rightOffset, rightOffset + 1]))
|
137
|
+
else
|
138
|
+
leftText = leftBlock.text.getTextAtRange([0, leftOffset])
|
139
|
+
rightText = rightBlock.text.getTextAtRange([rightOffset, rightBlock.getLength()])
|
140
|
+
text = leftText.appendText(rightText)
|
141
|
+
|
142
|
+
removingLeftBlock = leftIndex isnt rightIndex and leftOffset is 0
|
143
|
+
useRightBlock = removingLeftBlock and leftBlock.getAttributeLevel() >= rightBlock.getAttributeLevel()
|
144
|
+
|
145
|
+
if useRightBlock
|
146
|
+
block = rightBlock.copyWithText(text)
|
147
|
+
else
|
148
|
+
block = leftBlock.copyWithText(text)
|
149
|
+
|
150
|
+
affectedBlockCount = rightIndex + 1 - leftIndex
|
151
|
+
blocks = @blockList.splice(leftIndex, affectedBlockCount, block)
|
152
|
+
|
153
|
+
new @constructor blocks
|
154
|
+
|
155
|
+
moveTextFromRangeToPosition: (range, position) ->
|
156
|
+
[startPosition, endPosition] = range = normalizeRange(range)
|
157
|
+
return this if startPosition <= position <= endPosition
|
158
|
+
|
159
|
+
document = @getDocumentAtRange(range)
|
160
|
+
result = @removeTextAtRange(range)
|
161
|
+
|
162
|
+
movingRightward = startPosition < position
|
163
|
+
position -= document.getLength() if movingRightward
|
164
|
+
|
165
|
+
unless result.firstBlockInRangeIsEntirelySelected(range)
|
166
|
+
[firstBlock, blocks...] = document.getBlocks()
|
167
|
+
if blocks.length is 0
|
168
|
+
text = firstBlock.getTextWithoutBlockBreak()
|
169
|
+
position += 1 if movingRightward
|
170
|
+
else
|
171
|
+
text = firstBlock.text
|
172
|
+
|
173
|
+
result = result.insertTextAtRange(text, position)
|
174
|
+
return result if blocks.length is 0
|
175
|
+
|
176
|
+
document = new @constructor blocks
|
177
|
+
position += text.getLength()
|
178
|
+
|
179
|
+
result.insertDocumentAtRange(document, position)
|
180
|
+
|
181
|
+
addAttributeAtRange: (attribute, value, range) ->
|
182
|
+
blockList = @blockList
|
183
|
+
@eachBlockAtRange range, (block, textRange, index) ->
|
184
|
+
blockList = blockList.editObjectAtIndex index, ->
|
185
|
+
if getBlockConfig(attribute)
|
186
|
+
block.addAttribute(attribute, value)
|
187
|
+
else
|
188
|
+
if textRange[0] is textRange[1]
|
189
|
+
block
|
190
|
+
else
|
191
|
+
block.copyWithText(block.text.addAttributeAtRange(attribute, value, textRange))
|
192
|
+
new @constructor blockList
|
193
|
+
|
194
|
+
addAttribute: (attribute, value) ->
|
195
|
+
blockList = @blockList
|
196
|
+
@eachBlock (block, index) ->
|
197
|
+
blockList = blockList.editObjectAtIndex (index), ->
|
198
|
+
block.addAttribute(attribute, value)
|
199
|
+
new @constructor blockList
|
200
|
+
|
201
|
+
removeAttributeAtRange: (attribute, range) ->
|
202
|
+
blockList = @blockList
|
203
|
+
@eachBlockAtRange range, (block, textRange, index) ->
|
204
|
+
if getBlockConfig(attribute)
|
205
|
+
blockList = blockList.editObjectAtIndex index, ->
|
206
|
+
block.removeAttribute(attribute)
|
207
|
+
else if textRange[0] isnt textRange[1]
|
208
|
+
blockList = blockList.editObjectAtIndex index, ->
|
209
|
+
block.copyWithText(block.text.removeAttributeAtRange(attribute, textRange))
|
210
|
+
new @constructor blockList
|
211
|
+
|
212
|
+
updateAttributesForAttachment: (attributes, attachment) ->
|
213
|
+
[startPosition] = range = @getRangeOfAttachment(attachment)
|
214
|
+
{index} = @locationFromPosition(startPosition)
|
215
|
+
text = @getTextAtIndex(index)
|
216
|
+
|
217
|
+
new @constructor @blockList.editObjectAtIndex index, (block) ->
|
218
|
+
block.copyWithText(text.updateAttributesForAttachment(attributes, attachment))
|
219
|
+
|
220
|
+
removeAttributeForAttachment: (attribute, attachment) ->
|
221
|
+
range = @getRangeOfAttachment(attachment)
|
222
|
+
@removeAttributeAtRange(attribute, range)
|
223
|
+
|
224
|
+
insertBlockBreakAtRange: (range) ->
|
225
|
+
[startPosition] = range = normalizeRange(range)
|
226
|
+
{offset} = @locationFromPosition(startPosition)
|
227
|
+
|
228
|
+
document = @removeTextAtRange(range)
|
229
|
+
blocks = [new Trix.Block] if offset is 0
|
230
|
+
new @constructor document.blockList.insertSplittableListAtPosition(new Trix.SplittableList(blocks), startPosition)
|
231
|
+
|
232
|
+
applyBlockAttributeAtRange: (attributeName, value, range) ->
|
233
|
+
{document, range} = @expandRangeToLineBreaksAndSplitBlocks(range)
|
234
|
+
config = getBlockConfig(attributeName)
|
235
|
+
|
236
|
+
if config.listAttribute
|
237
|
+
document = document.removeLastListAttributeAtRange(range, exceptAttributeName: attributeName)
|
238
|
+
{document, range} = document.convertLineBreaksToBlockBreaksInRange(range)
|
239
|
+
else if config.terminal
|
240
|
+
document = document.removeLastTerminalAttributeAtRange(range)
|
241
|
+
else
|
242
|
+
document = document.consolidateBlocksAtRange(range)
|
243
|
+
|
244
|
+
document.addAttributeAtRange(attributeName, value, range)
|
245
|
+
|
246
|
+
removeLastListAttributeAtRange: (range, options = {}) ->
|
247
|
+
blockList = @blockList
|
248
|
+
@eachBlockAtRange range, (block, textRange, index) ->
|
249
|
+
return unless lastAttributeName = block.getLastAttribute()
|
250
|
+
return unless getBlockConfig(lastAttributeName).listAttribute
|
251
|
+
return if lastAttributeName is options.exceptAttributeName
|
252
|
+
blockList = blockList.editObjectAtIndex index, ->
|
253
|
+
block.removeAttribute(lastAttributeName)
|
254
|
+
new @constructor blockList
|
255
|
+
|
256
|
+
removeLastTerminalAttributeAtRange: (range) ->
|
257
|
+
blockList = @blockList
|
258
|
+
@eachBlockAtRange range, (block, textRange, index) ->
|
259
|
+
return unless lastAttributeName = block.getLastAttribute()
|
260
|
+
return unless getBlockConfig(lastAttributeName).terminal
|
261
|
+
blockList = blockList.editObjectAtIndex index, ->
|
262
|
+
block.removeAttribute(lastAttributeName)
|
263
|
+
new @constructor blockList
|
264
|
+
|
265
|
+
firstBlockInRangeIsEntirelySelected: (range) ->
|
266
|
+
[startPosition, endPosition] = range = normalizeRange(range)
|
267
|
+
leftLocation = @locationFromPosition(startPosition)
|
268
|
+
rightLocation = @locationFromPosition(endPosition)
|
269
|
+
|
270
|
+
if leftLocation.offset is 0 and leftLocation.index < rightLocation.index
|
271
|
+
true
|
272
|
+
else if leftLocation.index is rightLocation.index
|
273
|
+
length = @getBlockAtIndex(leftLocation.index).getLength()
|
274
|
+
leftLocation.offset is 0 and rightLocation.offset is length
|
275
|
+
else
|
276
|
+
false
|
277
|
+
|
278
|
+
expandRangeToLineBreaksAndSplitBlocks: (range) ->
|
279
|
+
[startPosition, endPosition] = range = normalizeRange(range)
|
280
|
+
startLocation = @locationFromPosition(startPosition)
|
281
|
+
endLocation = @locationFromPosition(endPosition)
|
282
|
+
document = this
|
283
|
+
|
284
|
+
startBlock = document.getBlockAtIndex(startLocation.index)
|
285
|
+
if (startLocation.offset = startBlock.findLineBreakInDirectionFromPosition("backward", startLocation.offset))?
|
286
|
+
position = document.positionFromLocation(startLocation)
|
287
|
+
document = document.insertBlockBreakAtRange([position, position + 1])
|
288
|
+
endLocation.index += 1
|
289
|
+
endLocation.offset -= document.getBlockAtIndex(startLocation.index).getLength()
|
290
|
+
startLocation.index += 1
|
291
|
+
startLocation.offset = 0
|
292
|
+
|
293
|
+
if endLocation.offset is 0 and endLocation.index > startLocation.index
|
294
|
+
endLocation.index -= 1
|
295
|
+
endLocation.offset = document.getBlockAtIndex(endLocation.index).getBlockBreakPosition()
|
296
|
+
else
|
297
|
+
endBlock = document.getBlockAtIndex(endLocation.index)
|
298
|
+
if endBlock.text.getStringAtRange([endLocation.offset - 1, endLocation.offset]) is "\n"
|
299
|
+
endLocation.offset -= 1
|
300
|
+
else
|
301
|
+
endLocation.offset = endBlock.findLineBreakInDirectionFromPosition("forward", endLocation.offset)
|
302
|
+
unless endLocation.offset is endBlock.getBlockBreakPosition()
|
303
|
+
position = document.positionFromLocation(endLocation)
|
304
|
+
document = document.insertBlockBreakAtRange([position, position + 1])
|
305
|
+
|
306
|
+
startPosition = document.positionFromLocation(startLocation)
|
307
|
+
endPosition = document.positionFromLocation(endLocation)
|
308
|
+
range = normalizeRange([startPosition, endPosition])
|
309
|
+
|
310
|
+
{document, range}
|
311
|
+
|
312
|
+
convertLineBreaksToBlockBreaksInRange: (range) ->
|
313
|
+
[position] = range = normalizeRange(range)
|
314
|
+
string = @getStringAtRange(range).slice(0, -1)
|
315
|
+
document = this
|
316
|
+
|
317
|
+
string.replace /.*?\n/g, (match) ->
|
318
|
+
position += match.length
|
319
|
+
document = document.insertBlockBreakAtRange([position - 1, position])
|
320
|
+
|
321
|
+
{document, range}
|
322
|
+
|
323
|
+
consolidateBlocksAtRange: (range) ->
|
324
|
+
[startPosition, endPosition] = range = normalizeRange(range)
|
325
|
+
startIndex = @locationFromPosition(startPosition).index
|
326
|
+
endIndex = @locationFromPosition(endPosition).index
|
327
|
+
new @constructor @blockList.consolidateFromIndexToIndex(startIndex, endIndex)
|
328
|
+
|
329
|
+
getDocumentAtRange: (range) ->
|
330
|
+
range = normalizeRange(range)
|
331
|
+
blocks = @blockList.getSplittableListInRange(range).toArray()
|
332
|
+
new @constructor blocks
|
333
|
+
|
334
|
+
getStringAtRange: (range) ->
|
335
|
+
@getDocumentAtRange(range).toString()
|
336
|
+
|
337
|
+
getBlockAtIndex: (index) ->
|
338
|
+
@blockList.getObjectAtIndex(index)
|
339
|
+
|
340
|
+
getBlockAtPosition: (position) ->
|
341
|
+
{index} = @locationFromPosition(position)
|
342
|
+
@getBlockAtIndex(index)
|
343
|
+
|
344
|
+
getTextAtIndex: (index) ->
|
345
|
+
@getBlockAtIndex(index)?.text
|
346
|
+
|
347
|
+
getTextAtPosition: (position) ->
|
348
|
+
{index} = @locationFromPosition(position)
|
349
|
+
@getTextAtIndex(index)
|
350
|
+
|
351
|
+
getPieceAtPosition: (position) ->
|
352
|
+
{index, offset} = @locationFromPosition(position)
|
353
|
+
@getTextAtIndex(index).getPieceAtPosition(offset)
|
354
|
+
|
355
|
+
getCharacterAtPosition: (position) ->
|
356
|
+
{index, offset} = @locationFromPosition(position)
|
357
|
+
@getTextAtIndex(index).getStringAtRange([offset, offset + 1])
|
358
|
+
|
359
|
+
getLength: ->
|
360
|
+
@blockList.getEndPosition()
|
361
|
+
|
362
|
+
getBlocks: ->
|
363
|
+
@blockList.toArray()
|
364
|
+
|
365
|
+
getBlockCount: ->
|
366
|
+
@blockList.length
|
367
|
+
|
368
|
+
getEditCount: ->
|
369
|
+
@editCount
|
370
|
+
|
371
|
+
eachBlock: (callback) ->
|
372
|
+
@blockList.eachObject(callback)
|
373
|
+
|
374
|
+
eachBlockAtRange: (range, callback) ->
|
375
|
+
[startPosition, endPosition] = range = normalizeRange(range)
|
376
|
+
startLocation = @locationFromPosition(startPosition)
|
377
|
+
endLocation = @locationFromPosition(endPosition)
|
378
|
+
|
379
|
+
if startLocation.index is endLocation.index
|
380
|
+
block = @getBlockAtIndex(startLocation.index)
|
381
|
+
textRange = [startLocation.offset, endLocation.offset]
|
382
|
+
callback(block, textRange, startLocation.index)
|
383
|
+
else
|
384
|
+
for index in [startLocation.index..endLocation.index]
|
385
|
+
if block = @getBlockAtIndex(index)
|
386
|
+
textRange = switch index
|
387
|
+
when startLocation.index
|
388
|
+
[startLocation.offset, block.text.getLength()]
|
389
|
+
when endLocation.index
|
390
|
+
[0, endLocation.offset]
|
391
|
+
else
|
392
|
+
[0, block.text.getLength()]
|
393
|
+
callback(block, textRange, index)
|
394
|
+
|
395
|
+
getCommonAttributesAtRange: (range) ->
|
396
|
+
[startPosition] = range = normalizeRange(range)
|
397
|
+
if rangeIsCollapsed(range)
|
398
|
+
@getCommonAttributesAtPosition(startPosition)
|
399
|
+
else
|
400
|
+
textAttributes = []
|
401
|
+
blockAttributes = []
|
402
|
+
|
403
|
+
@eachBlockAtRange range, (block, textRange) ->
|
404
|
+
unless textRange[0] is textRange[1]
|
405
|
+
textAttributes.push(block.text.getCommonAttributesAtRange(textRange))
|
406
|
+
blockAttributes.push(attributesForBlock(block))
|
407
|
+
|
408
|
+
Trix.Hash.fromCommonAttributesOfObjects(textAttributes)
|
409
|
+
.merge(Trix.Hash.fromCommonAttributesOfObjects(blockAttributes))
|
410
|
+
.toObject()
|
411
|
+
|
412
|
+
getCommonAttributesAtPosition: (position) ->
|
413
|
+
{index, offset} = @locationFromPosition(position)
|
414
|
+
block = @getBlockAtIndex(index)
|
415
|
+
return {} unless block
|
416
|
+
|
417
|
+
commonAttributes = attributesForBlock(block)
|
418
|
+
attributes = block.text.getAttributesAtPosition(offset)
|
419
|
+
attributesLeft = block.text.getAttributesAtPosition(offset - 1)
|
420
|
+
inheritableAttributes = (key for key, value of Trix.config.textAttributes when value.inheritable)
|
421
|
+
|
422
|
+
for key, value of attributesLeft
|
423
|
+
if value is attributes[key] or key in inheritableAttributes
|
424
|
+
commonAttributes[key] = value
|
425
|
+
|
426
|
+
commonAttributes
|
427
|
+
|
428
|
+
getRangeOfCommonAttributeAtPosition: (attributeName, position) ->
|
429
|
+
{index, offset} = @locationFromPosition(position)
|
430
|
+
text = @getTextAtIndex(index)
|
431
|
+
[startOffset, endOffset] = text.getExpandedRangeForAttributeAtOffset(attributeName, offset)
|
432
|
+
|
433
|
+
start = @positionFromLocation {index, offset: startOffset}
|
434
|
+
end = @positionFromLocation {index, offset: endOffset}
|
435
|
+
normalizeRange([start, end])
|
436
|
+
|
437
|
+
getBaseBlockAttributes: ->
|
438
|
+
baseBlockAttributes = @getBlockAtIndex(0).getAttributes()
|
439
|
+
|
440
|
+
for blockIndex in [1...@getBlockCount()]
|
441
|
+
blockAttributes = @getBlockAtIndex(blockIndex).getAttributes()
|
442
|
+
lastAttributeIndex = Math.min(baseBlockAttributes.length, blockAttributes.length)
|
443
|
+
|
444
|
+
baseBlockAttributes = for index in [0...lastAttributeIndex]
|
445
|
+
break unless blockAttributes[index] is baseBlockAttributes[index]
|
446
|
+
blockAttributes[index]
|
447
|
+
|
448
|
+
baseBlockAttributes
|
449
|
+
|
450
|
+
attributesForBlock = (block) ->
|
451
|
+
attributes = {}
|
452
|
+
if attributeName = block.getLastAttribute()
|
453
|
+
attributes[attributeName] = true
|
454
|
+
attributes
|
455
|
+
|
456
|
+
getAttachmentById: (attachmentId) ->
|
457
|
+
return attachment for attachment in @getAttachments() when attachment.id is attachmentId
|
458
|
+
|
459
|
+
getAttachmentPieces: ->
|
460
|
+
attachmentPieces = []
|
461
|
+
@blockList.eachObject ({text}) ->
|
462
|
+
attachmentPieces = attachmentPieces.concat(text.getAttachmentPieces())
|
463
|
+
attachmentPieces
|
464
|
+
|
465
|
+
getAttachments: ->
|
466
|
+
piece.attachment for piece in @getAttachmentPieces()
|
467
|
+
|
468
|
+
getRangeOfAttachment: (attachment) ->
|
469
|
+
position = 0
|
470
|
+
for {text}, index in @blockList.toArray()
|
471
|
+
if textRange = text.getRangeOfAttachment(attachment)
|
472
|
+
return normalizeRange([position + textRange[0], position + textRange[1]])
|
473
|
+
position += text.getLength()
|
474
|
+
return
|
475
|
+
|
476
|
+
getLocationRangeOfAttachment: (attachment) ->
|
477
|
+
range = @getRangeOfAttachment(attachment)
|
478
|
+
@locationRangeFromRange(range)
|
479
|
+
|
480
|
+
getAttachmentPieceForAttachment: (attachment) ->
|
481
|
+
return piece for piece in @getAttachmentPieces() when piece.attachment is attachment
|
482
|
+
|
483
|
+
locationFromPosition: (position) ->
|
484
|
+
location = @blockList.findIndexAndOffsetAtPosition(Math.max(0, position))
|
485
|
+
if location.index?
|
486
|
+
location
|
487
|
+
else
|
488
|
+
blocks = @getBlocks()
|
489
|
+
index: blocks.length - 1, offset: blocks[blocks.length - 1].getLength()
|
490
|
+
|
491
|
+
positionFromLocation: (location) ->
|
492
|
+
@blockList.findPositionAtIndexAndOffset(location.index, location.offset)
|
493
|
+
|
494
|
+
locationRangeFromPosition: (position) ->
|
495
|
+
normalizeRange(@locationFromPosition(position))
|
496
|
+
|
497
|
+
locationRangeFromRange: (range) ->
|
498
|
+
return unless range = normalizeRange(range)
|
499
|
+
[startPosition, endPosition] = range
|
500
|
+
startLocation = @locationFromPosition(startPosition)
|
501
|
+
endLocation = @locationFromPosition(endPosition)
|
502
|
+
normalizeRange([startLocation, endLocation])
|
503
|
+
|
504
|
+
rangeFromLocationRange: (locationRange) ->
|
505
|
+
locationRange = normalizeRange(locationRange)
|
506
|
+
leftPosition = @positionFromLocation(locationRange[0])
|
507
|
+
rightPosition = @positionFromLocation(locationRange[1]) unless rangeIsCollapsed(locationRange)
|
508
|
+
normalizeRange([leftPosition, rightPosition])
|
509
|
+
|
510
|
+
isEqualTo: (document) ->
|
511
|
+
@blockList.isEqualTo(document?.blockList)
|
512
|
+
|
513
|
+
getTexts: ->
|
514
|
+
block.text for block in @getBlocks()
|
515
|
+
|
516
|
+
getPieces: ->
|
517
|
+
pieces = []
|
518
|
+
for text in @getTexts()
|
519
|
+
pieces.push(text.getPieces()...)
|
520
|
+
pieces
|
521
|
+
|
522
|
+
getObjects: ->
|
523
|
+
@getBlocks().concat(@getTexts()).concat(@getPieces())
|
524
|
+
|
525
|
+
toSerializableDocument: ->
|
526
|
+
blocks = []
|
527
|
+
@blockList.eachObject (block) ->
|
528
|
+
blocks.push(block.copyWithText(block.text.toSerializableText()))
|
529
|
+
new @constructor blocks
|
530
|
+
|
531
|
+
toString: ->
|
532
|
+
@blockList.toString()
|
533
|
+
|
534
|
+
toJSON: ->
|
535
|
+
@blockList.toJSON()
|
536
|
+
|
537
|
+
toConsole: ->
|
538
|
+
JSON.stringify(JSON.parse(block.text.toConsole()) for block in @blockList.toArray())
|