- Security fix: 'extPath', 'imgPath', 'extIconsPath', 'canvgPath', 'langPath', 'jGraduatePath', and 'jspdfPath' were not being prevented

- Breaking change: Rename "svgutils.js" to "utilities.js" (make in conformity with JSDoc module naming convention)
- Breaking change: Rename "svgedit.js" to "namespaces.js" (to make clear purpose and avoid confusing with editor)
- Breaking change: Rename "jquery-svg.js" to "jQuery.attr.js"
- Breaking change: Rename "jquery.contextMenu.js" to "jQuery.contextMenu.js"
- Breaking change: Rename "jquery.jpicker.js" to "jQuery.jPicker.js"
- Breaking change: Rename "JQuerySpinBtn.css" to "jQuery.SpinButton.css"
- Breaking change: Rename "JQuerySpinBtn.js" to "jQuery.SpinButton.js" (to have file name more closely reflect name)
- Breaking change: Rename "jquery.svgicons.js" to "jQuery.svgIcons.js"
- Breaking change: Rename "jquery.jgraduate.js" to "jQuery.jGraduate.js"
- Breaking change: Rename "pathseg.js" to "svgpathseg.js" (as it is a poyfill of SVGPathSeg)
- Breaking change: Rename `addSvgElementFromJson()` to `addSVGElementFromJson` for consistency
- Breaking change: Rename `changeSvgContent()` to `changeSVGContent()` for consistency
- Breaking change: Have `exportPDF` resolve with `output` and `outputType` rather than `dataurlstring` (as type may vary)
- Breaking change: Rename `extensions/mathjax/MathJax.js` to `extensions/mathjax/MathJax.min.js`
- Breaking change: Avoid recent change to have editor ready callbacks return Promises (we're not using and advantageous to keep sequential)
- Breaking change: Avoid recent addition of locale-side function in ext-imagelib for l10n
- Breaking change: Change name of ext-arrows.js from `Arrows` to `arrows` for sake of file path (not localized anyways).
- Breaking change: Change `addlangData` extension event to `addLangData` for consistency with method name
- Breaking change: Have `readLang`  return lang and data but do not call `setLang`
- Fix: Have general locales load first so extensions may use
- Fix: Provide `importLocale` to extensions `init` so it may delay adding of the extension until locale data loaded
- Fix: Ensure call to `rasterExport` without `imgType` properly sets MIME type to PNG
- Fix: Wrong name for moinsave
- Update: Update WebAppFind per new API changes
- Enhancement: Make `setStrings` public on editor for late setting (used
  by `ext-shapes.js`)
- Enhancement: Add `extensions_added` event
- Enhancement: Add `message` event (Relay messages including those which
  have been been received prior to extension load)
- Enhancement: Allow SVGEdit to work out of the box--avoid need for copying sample config file. Should also help with Github-based file servers
- Enhancement: Allow avoiding "name" in extension export (just extract out of file name)
- Enhancement: Add stack blur to canvg by default (and refactoring it)
- Enhancement: Return `Promise` for `embedImage` (as with some other loading methods)
- Enhancement: Supply `importLocale` to `langReady` to facilitate extension locale loading
- Enhancement: Recover if an extension fails to load (just log and otherwise ignore)
- Enhancement: More i18n of extensions (also fixed issue with some console warnings about missing locale strings); i18nize Hello World too
- Enhancement: Allowing importing of locales within `addLangData`
- npm: Update devDeps
- Docs: Migrate copies of all old wiki pages to docs/from-old-wiki folder; intended for a possible move to Markdown, so raw HTML (with formatting) was not preserved, though named links had their absolute URL links preserved
- Docs: Begin deleting `SvgCanvas.md` as ensuring jsdoc has replacements
- Docs: Add Edtior doc file for help to general users
- Docs: Clarify/simplify install instructions
- npm/Docs (JSDoc): Add script to check for overly generic types
- Docs (JSDoc): For config/prefs and extension creating, link to tutorials (moved tutorials to own directory to avoid recursion problems by jsdoc)
- Docs (JSDoc): Add modules (upper case for usual main entrance files or regular names)
- Docs (JSDoc): Fill out missing areas; indicate return of `undefined`; consistency with `@returns`
- Docs (JSDoc): Add our own layout template to support overflow
- Docs (JSDoc): Use cleverLinks and disallow unknown tags
- Docs (JSDoc): Insist on "pedantic" flag; put output directory in config
- Docs (JSDoc): Use more precise Integer/Float over number, the specific type of array/function/object
- Docs (JSDoc): Use `@throws`, `@enum`, `@event`/`@fires`/`@listens`
- Docs: Generally update/improve docs (fixes #92)
- Docs: Update links to `latest` path (Avoid needing to update such references upon each release)
- Docs: 80 chars max
- Refactoring: Drop code for extension as function (already requiring export to be an object)
- Refactoring: Object destructuring, `Object.entries`, Object shorthand, array extras, more camelCase variable names
- Refactoring: Add a `Command` base class
- Refactoring: Simplify svgicons `callback` ready detection
- Refactoring: Put `let` or `const` closer to scope
- Refactoring: Remove unneeded `delimiter` from regex escaping utility
- Refactoring: Clearer variable names
- Refactoring: Use (non-deprecated) Event constructors
- Testing: Use new Sinon
This commit is contained in:
Brett Zamir
2018-06-06 15:26:20 +08:00
parent 057f5a5dc2
commit a3f0b8e501
334 changed files with 60808 additions and 16650 deletions

View File

@@ -1,20 +1,41 @@
/* globals jQuery */
/*
/**
* Localizing script for SVG-edit UI
* @module locale
* @license MIT
*
* Licensed under the MIT License
*
* Copyright(c) 2010 Narendra Sisodya
* Copyright(c) 2010 Alexis Deveria
* @copyright 2010 Narendra Sisodya
* @copyright 2010 Alexis Deveria
*
*/
/**
* Used, for example, in the ImageLibs extension, to present libraries (with name/URL/description) in order
* @typedef {GenericArray.<module:locale.LocaleStrings>} module:locale.LocaleArray
*/
/**
* The string keys of the object are two-letter language codes
* @tutorial LocaleDocs
* @typedef {PlainObject.<string, string|module:locale.LocaleStrings|module:locale.LocaleArray>} module:locale.LocaleStrings
*/
// keyed to an array of objects with "id" and "title" or "textContent" properties
/**
* @typedef {PlainObject.<string, string>} module:locale.LocaleSelectorValue
*/
import {importSetGlobalDefault} from '../external/dynamic-import-polyfill/importModule.js';
const $ = jQuery;
let langParam;
function setStrings (type, obj, ids) {
/**
* @param {"content"|"title"} type
* @param {module:locale.LocaleSelectorValue} obj
* @param {boolean} ids
* @returns {undefined}
*/
export const setStrings = function (type, obj, ids) {
// Root element to look for element from
const parent = $('#svg_editor').parent();
Object.entries(obj).forEach(([sel, val]) => {
@@ -43,15 +64,49 @@ function setStrings (type, obj, ids) {
console.log('Missing: ' + sel);
}
});
}
};
/**
* The "data" property is generally set to an an array of objects with
* "id" and "title" or "textContent" properties
* @typedef {PlainObject} module:locale.AddLangExtensionLocaleData
* @property {module:locale.LocaleStrings[]} data See {@tutorial LocaleDocs}
*/
/**
* @interface module:locale.LocaleEditorInit
*/
/**
* @function module:locale.LocaleEditorInit#addLangData
* @param {string} langParam
* @returns {module:locale.AddLangExtensionLocaleData}
*/
let editor_;
/**
* @function init
* @memberof module:locale
* @param {module:locale.LocaleEditorInit} editor
* @returns {undefined}
*/
export const init = (editor) => {
editor_ = editor;
};
export const readLang = function (langData) {
const more = editor_.addLangData(langParam);
/**
* @typedef {PlainObject} module:locale.LangAndData
* @property {string} langParam
* @property {module:locale.LocaleStrings} langData
*/
/**
* @function module:locale.readLang
* @param {module:locale.LocaleStrings} langData See {@tutorial LocaleDocs}
* @fires module:svgcanvas.SvgCanvas#event:ext-addLangData
* @returns {Promise} Resolves to [`LangAndData`]{@link module:locale.LangAndData}
*/
export const readLang = async function (langData) {
const more = await editor_.addLangData(langParam);
$.each(more, function (i, m) {
if (m.data) {
langData = $.merge(langData, m.data);
@@ -136,17 +191,6 @@ export const readLang = function (langData) {
svginfo_grid_color: config.grid_color
}, true);
// Shape categories
const cats = {};
for (const o in langData.shape_cats) {
cats['#shape_cats [data-cat="' + o + '"]'] = langData.shape_cats[o];
}
// TODO: Find way to make this run after shapelib ext has loaded
setTimeout(() => {
setStrings('content', cats);
}, 2000);
// Context menus
const opts = {};
$.each(['cut', 'copy', 'paste', 'paste_in_place', 'delete', 'group', 'ungroup', 'move_front', 'move_up', 'move_down', 'move_back'], function () {
@@ -194,8 +238,6 @@ export const readLang = function (langData) {
linejoin_miter: properties.linejoin_miter,
linejoin_round: properties.linejoin_round,
main_icon: tools.main_menu,
mode_connect: tools.mode_connect,
tools_shapelib_show: tools.mode_shapelib,
palette: ui.palette_info,
zoom_panel: ui.zoom_level,
path_node_x: properties.node_x,
@@ -228,7 +270,6 @@ export const readLang = function (langData) {
tool_delete: tools.del,
tool_delete_multi: tools.del,
tool_ellipse: tools.mode_ellipse,
tool_eyedropper: tools.mode_eyedropper,
tool_fhellipse: tools.mode_fhellipse,
tool_fhpath: tools.mode_fhpath,
tool_fhrect: tools.mode_fhrect,
@@ -259,15 +300,24 @@ export const readLang = function (langData) {
tool_undo: tools.undo,
tool_ungroup: tools.ungroup,
tool_wireframe: tools.wireframe_mode,
view_grid: tools.toggle_grid,
tool_zoom: tools.mode_zoom,
url_notice: tools.no_embed
}, true);
editor_.setLang(langParam, langData);
return {langParam, langData};
};
/**
* @function module:locale.putLocale
* @param {string} givenParam
* @param {string[]} goodLangs
* @param {{langPath: string}} conf
* @fires module:svgcanvas.SvgCanvas#event:ext-addLangData
* @fires module:svgcanvas.SvgCanvas#event:ext-langReady
* @fires module:svgcanvas.SvgCanvas#event:ext-langChanged
* @returns {Promise} Resolves to result of {@link module:locale.readLang}
*/
export const putLocale = async function (givenParam, goodLangs, conf) {
if (givenParam) {
langParam = givenParam;