diff --git a/.github/workflows/api-verification.yml b/.github/workflows/api-verification.yml index 7d4a473978a..786e8ebad2d 100644 --- a/.github/workflows/api-verification.yml +++ b/.github/workflows/api-verification.yml @@ -37,7 +37,6 @@ jobs: id: environment_step run: | cat artifacts/env >> $GITHUB_OUTPUT - cat artifacts/env - name: Set pending status on PR builds id: set_status @@ -68,22 +67,14 @@ jobs: - name: "Verify API for libkeymancore*.so (${{ steps.environment_step.outputs.GIT_BRANCH }}, branch ${{ steps.environment_step.outputs.GIT_BASE_BRANCH }}, by ${{ steps.environment_step.outputs.GIT_USER }})" run: | - echo "VERSION=${{ steps.environment_step.outputs.VERSION }}" - echo "PRERELEASE_TAG=${{ steps.environment_step.outputs.PRERELEASE_TAG }}" - echo "GIT_SHA=${{ steps.environment_step.outputs.GIT_SHA }}" - echo "GIT_BASE=${{ steps.environment_step.outputs.GIT_BASE }}" - ls -al ${GITHUB_WORKSPACE} - ls -al ${GITHUB_WORKSPACE}/artifacts BIN_PACKAGE=$(ls "${GITHUB_WORKSPACE}/artifacts/" | grep "${PKG_NAME}[0-9]*_${{ steps.environment_step.outputs.VERSION }}-1${{ steps.environment_step.outputs.PRERELEASE_TAG }}+$(lsb_release -c -s)1_amd64.deb") - echo "BIN_PACKAGE=${BIN_PACKAGE}" - ls -al ${BIN_PACKAGE} cd ${{ github.workspace }}/keyman/linux ./scripts/deb-packaging.sh \ --gha \ - --bin-pkg "${BIN_PACKAGE}" \ + --bin-pkg "${GITHUB_WORKSPACE}/artifacts/${BIN_PACKAGE}" \ --git-sha "${{ steps.environment_step.outputs.GIT_SHA }}" \ --git-base "${{ steps.environment_step.outputs.GIT_BASE }}" \ - verify # 2>> $GITHUB_STEP_SUMMARY + verify 2>> $GITHUB_STEP_SUMMARY - name: Archive .symbols file uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0 @@ -99,23 +90,22 @@ jobs: if: ${{ always() && needs.api_verification.outputs.IS_TEST_BUILD == 'true' }} steps: - name: Set success - # TEMP commented until things are working! - # if: needs.api_verification.result == 'success' + if: needs.api_verification.result == 'success' run: | echo "RESULT=success" >> $GITHUB_ENV echo "MSG=Package build succeeded" >> $GITHUB_ENV - # - name: Set cancelled - # if: needs.api_verification.result == 'cancelled' - # run: | - # echo "RESULT=error" >> $GITHUB_ENV - # echo "MSG=Package build cancelled" >> $GITHUB_ENV + - name: Set cancelled + if: needs.api_verification.result == 'cancelled' + run: | + echo "RESULT=error" >> $GITHUB_ENV + echo "MSG=Package build cancelled" >> $GITHUB_ENV - # - name: Set failure - # if: needs.api_verification.result == 'failure' - # run: | - # echo "RESULT=failure" >> $GITHUB_ENV - # echo "MSG=Package build failed" >> $GITHUB_ENV + - name: Set failure + if: needs.api_verification.result == 'failure' + run: | + echo "RESULT=failure" >> $GITHUB_ENV + echo "MSG=Package build failed" >> $GITHUB_ENV - name: Set final status run: | diff --git a/HISTORY.md b/HISTORY.md index 815254b7d4b..21cceb07eb7 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,25 @@ # Keyman Version History +## 18.0.50 alpha 2024-06-06 + +* chore(common): adds retry mechanism for build script npm ci calls (#11451) +* fix(web): get row-height for flick constraints after performing layout (#11691) +* chore(ios): enable webview debugging (#11229) +* fix(android): handle `IllegalArgumentException` when initializing `CloudDownloadMgr`, add logging to check for unhandled side-effects (#11626) +* chore: replace git dep on restructure with 3.0.1 in npm (#11657) +* chore: move xml2js into the repo to eliminate npm git dependency (#11660) +* chore(common): move CLDR import copy into build step for common/web/types (#11690) +* fix(developer): handle editor initializing after debugger when setting execution point (#11587) +* fix(developer): treat js files with unrecognized encodings as non-keyboard files (#11698) +* fix(developer): disable example edit controls if no examples in Package Editor (#11701) + +## 18.0.49 alpha 2024-06-05 + +* fix(web): revert #11598 to eliminate use of `finalInput` which caused crash after moving caret (#11685) +* fix(common): correctly display result of multiple option parameters in builder (#11679) +* fix(linux): specify path with package name (#11694) +* fix(linux): remove debug output and re-enable failures (#11695) + ## 18.0.48 alpha 2024-06-04 * fix(linux): add debug output (#11668) diff --git a/VERSION.md b/VERSION.md index 7a839a09658..dd6ab3716f8 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1 @@ -18.0.49 \ No newline at end of file +18.0.51 \ No newline at end of file diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/cloud/CloudDownloadMgr.java b/android/KMEA/app/src/main/java/com/keyman/engine/cloud/CloudDownloadMgr.java index 8c0d4403cb1..8a25ab09bab 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/cloud/CloudDownloadMgr.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/cloud/CloudDownloadMgr.java @@ -40,6 +40,7 @@ private synchronized static void createInstance() { if(instance!=null) return; + KMLog.LogBreadcrumb("CloudDownloadMgr", "CloudDownloadMgr.createInstance() - first call", true); instance = new CloudDownloadMgr(); } @@ -60,6 +61,7 @@ public synchronized void initialize(Context aContext) if(isInitialized) return; try { + KMLog.LogBreadcrumb("CloudDownloadMgr", "attempting CloudDownloadMgr.initialize()", true); // Runtime-registered boradcasts receivers must specify export behavior to indicate whether // or not the receiver should be exported to all other apps on the device // https://developer.android.com/about/versions/14/behavior-changes-14#runtime-receivers-exported @@ -69,11 +71,12 @@ public synchronized void initialize(Context aContext) } else { aContext.registerReceiver(completeListener, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } - } catch (IllegalStateException e) { + } catch (IllegalArgumentException e) { String message = "initialize error: "; KMLog.LogException(TAG, message, e); } isInitialized = true; + KMLog.LogBreadcrumb("CloudDownloadMgr", ".initialize() call complete", false); } /** @@ -82,11 +85,15 @@ public synchronized void initialize(Context aContext) */ public synchronized void shutdown(Context aContext) { - if(!isInitialized) + if(!isInitialized) { return; + } + + KMLog.LogBreadcrumb("CloudDownloadMgr", "CloudDownloadMgr.shutdown()", true); + try { aContext.unregisterReceiver(completeListener); - } catch (IllegalStateException e) { + } catch (IllegalArgumentException e) { String message = "shutdown error: "; KMLog.LogException(TAG, message, e); } @@ -206,8 +213,10 @@ public void executeAsDownload(Context aContext, String aD CloudApiTypes.CloudApiParam... params) { if(!isInitialized) { - Log.w(TAG, "Downloadmanager not initialized. Initializing CloudDownloadMgr."); + Log.w(TAG, "DownloadManager not initialized. Initializing CloudDownloadMgr."); initialize(aContext); + } else { + KMLog.LogBreadcrumb("CloudDownloadMgr", "CloudDownloadMgr.executeAsDownload() called; already initialized", true); } synchronized (downloadSetByDownloadIdentifier) { @@ -218,7 +227,7 @@ public void executeAsDownload(Context aContext, String aD DownloadManager downloadManager = (DownloadManager) aContext.getSystemService(Context.DOWNLOAD_SERVICE); if(downloadManager==null) - throw new IllegalStateException("Downloadmanager is not available"); + throw new IllegalStateException("DownloadManager is not available"); aCallback.initializeContext(aContext); diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/util/KMLog.java b/android/KMEA/app/src/main/java/com/keyman/engine/util/KMLog.java index 3eeabdcbdfd..cb13cc967ed 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/util/KMLog.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/util/KMLog.java @@ -13,6 +13,7 @@ import com.keyman.engine.util.DependencyUtil; import com.keyman.engine.util.DependencyUtil.LibraryType; +import io.sentry.Breadcrumb; import io.sentry.Sentry; import io.sentry.SentryLevel; @@ -34,6 +35,48 @@ public static void LogInfo(String tag, String msg) { } } + /** + * Utility to log info and add as a Sentry breadcrumb, rather than + * as an independent message + * @param tag String of the caller + * @param msg String of the info message + */ + public static void LogBreadcrumb(String tag, String msg, boolean addStackTrace) { + if (msg == null || msg.isEmpty()) { + return; + } + + Log.i(tag, msg); + + if (!DependencyUtil.libraryExists(LibraryType.SENTRY) || !Sentry.isEnabled()) { + return; + } + + Breadcrumb crumb = new Breadcrumb(); + crumb.setMessage(msg); + crumb.setLevel(SentryLevel.INFO); + + if(addStackTrace) { + StackTraceElement[] rawTrace = Thread.currentThread().getStackTrace(); + + // The call that gets us the stack-trace above... shows up in the + // stack trace, so we'll skip the first few (redundant) entries. + int skipCount = 3; + + // Sentry does limit the size of messages... so let's just + // keep 10 entries and call it a day. + int limit = Math.min(rawTrace.length, 10 + skipCount); + if(rawTrace.length > skipCount) { + String[] trace = new String[limit - skipCount]; + for (int i = skipCount; i < limit; i++) { + trace[i-skipCount] = rawTrace[i].toString(); + } + crumb.setData("stacktrace", trace); + } + } + Sentry.addBreadcrumb(crumb); + } + /** * Utility to log error and send to Sentry * @param tag String of the caller diff --git a/common/web/lm-worker/src/main/model-compositor.ts b/common/web/lm-worker/src/main/model-compositor.ts index 492bb1c7303..1908890b64e 100644 --- a/common/web/lm-worker/src/main/model-compositor.ts +++ b/common/web/lm-worker/src/main/model-compositor.ts @@ -249,21 +249,11 @@ export default class ModelCompositor { // Worth considering: extend Traversal to allow direct prediction lookups? // let traversal = match.finalTraversal; - // Find a proper Transform ID to map the correction to. - // Without it, we can't apply the suggestion. - let finalInput: Transform; - if(match.inputSequence.length > 0) { - // common case: from the same keystroke `inputTransform`, with matching `.id`. - finalInput = match.inputSequence[match.inputSequence.length - 1].sample; - } else { - finalInput = inputTransform; // A fallback measure. Greatly matters for empty contexts. - } - // Replace the existing context with the correction. let correctionTransform: Transform = { insert: correction, // insert correction string deleteLeft: deleteLeft, - id: finalInput.id // The correction should always be based on the most recent external transform/transcription ID. + id: inputTransform.id // The correction should always be based on the most recent external transform/transcription ID. } let rootCost = match.totalCost; diff --git a/common/web/types/build.sh b/common/web/types/build.sh index 4452bc76469..df11540b424 100755 --- a/common/web/types/build.sh +++ b/common/web/types/build.sh @@ -89,10 +89,14 @@ function copy_cldr_imports() { function do_configure() { compile_schemas - copy_cldr_imports verify_npm_setup } +function do_build() { + copy_cldr_imports + tsc --build +} + function do_test() { eslint . tsc --build test @@ -103,6 +107,6 @@ function do_test() { builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo builder_run_action configure do_configure -builder_run_action build tsc --build +builder_run_action build do_build builder_run_action test do_test builder_run_action publish builder_publish_npm diff --git a/common/web/types/package.json b/common/web/types/package.json index de9ad69360c..201354b8974 100644 --- a/common/web/types/package.json +++ b/common/web/types/package.json @@ -31,9 +31,10 @@ "dependencies": { "@keymanapp/ldml-keyboard-constants": "*", "@keymanapp/keyman-version": "*", - "restructure": "git+https://github.com/keymanapp/dependency-restructure.git#7a188a1e26f8f36a175d95b67ffece8702363dfc", + "restructure": "3.0.1", "semver": "^7.5.2", - "xml2js": "git+https://github.com/keymanapp/dependency-node-xml2js#535fe732dc408d697e0f847c944cc45f0baf0829" + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" }, "devDependencies": { "@types/chai": "^4.1.7", @@ -70,6 +71,7 @@ ], "exclude-after-remap": true, "exclude": [ + "src/deps/", "src/kmx/kmx-plus-builder/", "src/kmx/kmx-plus.ts", "src/kmx/kmx-builder.ts", diff --git a/common/web/types/src/deps/xml2js/LICENSE b/common/web/types/src/deps/xml2js/LICENSE new file mode 100644 index 00000000000..e3b4222a66a --- /dev/null +++ b/common/web/types/src/deps/xml2js/LICENSE @@ -0,0 +1,19 @@ +Copyright 2010, 2011, 2012, 2013. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/common/web/types/src/deps/xml2js/README.md b/common/web/types/src/deps/xml2js/README.md new file mode 100644 index 00000000000..67f2104a513 --- /dev/null +++ b/common/web/types/src/deps/xml2js/README.md @@ -0,0 +1,507 @@ +node-xml2js +=========== + +Ever had the urge to parse XML? And wanted to access the data in some sane, +easy way? Don't want to compile a C parser, for whatever reason? Then xml2js is +what you're looking for! + +Description +=========== + +Simple XML to JavaScript object converter. It supports bi-directional conversion. +Uses [sax-js](https://github.com/isaacs/sax-js/) and +[xmlbuilder-js](https://github.com/oozcitak/xmlbuilder-js/). + +Note: If you're looking for a full DOM parser, you probably want +[JSDom](https://github.com/tmpvar/jsdom). + +Installation +============ + +Simplest way to install `xml2js` is to use [npm](http://npmjs.org), just `npm +install xml2js` which will download xml2js and all dependencies. + +xml2js is also available via [Bower](http://bower.io/), just `bower install +xml2js` which will download xml2js and all dependencies. + +Usage +===== + +No extensive tutorials required because you are a smart developer! The task of +parsing XML should be an easy one, so let's make it so! Here's some examples. + +Shoot-and-forget usage +---------------------- + +You want to parse XML as simple and easy as possible? It's dangerous to go +alone, take this: + +```javascript +var parseString = require('xml2js').parseString; +var xml = "Hello xml2js!" +parseString(xml, function (err, result) { + console.dir(result); +}); +``` + +Can't get easier than this, right? This works starting with `xml2js` 0.2.3. +With CoffeeScript it looks like this: + +```coffeescript +{parseString} = require 'xml2js' +xml = "Hello xml2js!" +parseString xml, (err, result) -> + console.dir result +``` + +If you need some special options, fear not, `xml2js` supports a number of +options (see below), you can specify these as second argument: + +```javascript +parseString(xml, {trim: true}, function (err, result) { +}); +``` + +Simple as pie usage +------------------- + +That's right, if you have been using xml-simple or a home-grown +wrapper, this was added in 0.1.11 just for you: + +```javascript +var fs = require('fs'), + xml2js = require('xml2js'); + +var parser = new xml2js.Parser(); +fs.readFile(__dirname + '/foo.xml', function(err, data) { + parser.parseString(data, function (err, result) { + console.dir(result); + console.log('Done'); + }); +}); +``` + +Look ma, no event listeners! + +You can also use `xml2js` from +[CoffeeScript](https://github.com/jashkenas/coffeescript), further reducing +the clutter: + +```coffeescript +fs = require 'fs', +xml2js = require 'xml2js' + +parser = new xml2js.Parser() +fs.readFile __dirname + '/foo.xml', (err, data) -> + parser.parseString data, (err, result) -> + console.dir result + console.log 'Done.' +``` + +But what happens if you forget the `new` keyword to create a new `Parser`? In +the middle of a nightly coding session, it might get lost, after all. Worry +not, we got you covered! Starting with 0.2.8 you can also leave it out, in +which case `xml2js` will helpfully add it for you, no bad surprises and +inexplicable bugs! + +Promise usage +------------- + +```javascript +var xml2js = require('xml2js'); +var xml = ''; + +// With parser +var parser = new xml2js.Parser(/* options */); +parser.parseStringPromise(xml).then(function (result) { + console.dir(result); + console.log('Done'); +}) +.catch(function (err) { + // Failed +}); + +// Without parser +xml2js.parseStringPromise(xml /*, options */).then(function (result) { + console.dir(result); + console.log('Done'); +}) +.catch(function (err) { + // Failed +}); +``` + +Parsing multiple files +---------------------- + +If you want to parse multiple files, you have multiple possibilities: + + * You can create one `xml2js.Parser` per file. That's the recommended one + and is promised to always *just work*. + * You can call `reset()` on your parser object. + * You can hope everything goes well anyway. This behaviour is not + guaranteed work always, if ever. Use option #1 if possible. Thanks! + +So you wanna some JSON? +----------------------- + +Just wrap the `result` object in a call to `JSON.stringify` like this +`JSON.stringify(result)`. You get a string containing the JSON representation +of the parsed object that you can feed to JSON-hungry consumers. + +Displaying results +------------------ + +You might wonder why, using `console.dir` or `console.log` the output at some +level is only `[Object]`. Don't worry, this is not because `xml2js` got lazy. +That's because Node uses `util.inspect` to convert the object into strings and +that function stops after `depth=2` which is a bit low for most XML. + +To display the whole deal, you can use `console.log(util.inspect(result, false, +null))`, which displays the whole result. + +So much for that, but what if you use +[eyes](https://github.com/cloudhead/eyes.js) for nice colored output and it +truncates the output with `…`? Don't fear, there's also a solution for that, +you just need to increase the `maxLength` limit by creating a custom inspector +`var inspect = require('eyes').inspector({maxLength: false})` and then you can +easily `inspect(result)`. + +XML builder usage +----------------- + +Since 0.4.0, objects can be also be used to build XML: + +```javascript +var xml2js = require('xml2js'); + +var obj = {name: "Super", Surname: "Man", age: 23}; + +var builder = new xml2js.Builder(); +var xml = builder.buildObject(obj); +``` +will result in: + +```xml + + + Super + Man + 23 + +``` + +At the moment, a one to one bi-directional conversion is guaranteed only for +default configuration, except for `attrkey`, `charkey` and `explicitArray` options +you can redefine to your taste. Writing CDATA is supported via setting the `cdata` +option to `true`. + +To specify attributes: +```javascript +var xml2js = require('xml2js'); + +var obj = {root: {$: {id: "my id"}, _: "my inner text"}}; + +var builder = new xml2js.Builder(); +var xml = builder.buildObject(obj); +``` +will result in: +```xml + +my inner text +``` + +### Adding xmlns attributes + +You can generate XML that declares XML namespace prefix / URI pairs with xmlns attributes. + +Example declaring a default namespace on the root element: + +```javascript +let obj = { + Foo: { + $: { + "xmlns": "http://foo.com" + } + } +}; +``` +Result of `buildObject(obj)`: +```xml + +``` +Example declaring non-default namespaces on non-root elements: +```javascript +let obj = { + 'foo:Foo': { + $: { + 'xmlns:foo': 'http://foo.com' + }, + 'bar:Bar': { + $: { + 'xmlns:bar': 'http://bar.com' + } + } + } +} +``` +Result of `buildObject(obj)`: +```xml + + + +``` + + +Processing attribute, tag names and values +------------------------------------------ + +Since 0.4.1 you can optionally provide the parser with attribute name and tag name processors as well as element value processors (Since 0.4.14, you can also optionally provide the parser with attribute value processors): + +```javascript + +function nameToUpperCase(name){ + return name.toUpperCase(); +} + +//transform all attribute and tag names and values to uppercase +parseString(xml, { + tagNameProcessors: [nameToUpperCase], + attrNameProcessors: [nameToUpperCase], + valueProcessors: [nameToUpperCase], + attrValueProcessors: [nameToUpperCase]}, + function (err, result) { + // processed data +}); +``` + +The `tagNameProcessors` and `attrNameProcessors` options +accept an `Array` of functions with the following signature: + +```javascript +function (name){ + //do something with `name` + return name +} +``` + +The `attrValueProcessors` and `valueProcessors` options +accept an `Array` of functions with the following signature: + +```javascript +function (value, name) { + //`name` will be the node name or attribute name + //do something with `value`, (optionally) dependent on the node/attr name + return value +} +``` + +Some processors are provided out-of-the-box and can be found in `lib/processors.js`: + +- `normalize`: transforms the name to lowercase. +(Automatically used when `options.normalize` is set to `true`) + +- `firstCharLowerCase`: transforms the first character to lower case. +E.g. 'MyTagName' becomes 'myTagName' + +- `stripPrefix`: strips the xml namespace prefix. E.g `` will become 'Bar'. +(N.B.: the `xmlns` prefix is NOT stripped.) + +- `parseNumbers`: parses integer-like strings as integers and float-like strings as floats +E.g. "0" becomes 0 and "15.56" becomes 15.56 + +- `parseBooleans`: parses boolean-like strings to booleans +E.g. "true" becomes true and "False" becomes false + +Options +======= + +Apart from the default settings, there are a number of options that can be +specified for the parser. Options are specified by ``new Parser({optionName: +value})``. Possible options are: + + * `attrkey` (default: `$`): Prefix that is used to access the attributes. + Version 0.1 default was `@`. + * `charkey` (default: `_`): Prefix that is used to access the character + content. Version 0.1 default was `#`. + * `explicitCharkey` (default: `false`) Determines whether or not to use + a `charkey` prefix for elements with no attributes. + * `trim` (default: `false`): Trim the whitespace at the beginning and end of + text nodes. + * `normalizeTags` (default: `false`): Normalize all tag names to lowercase. + * `normalize` (default: `false`): Trim whitespaces inside text nodes. + * `explicitRoot` (default: `true`): Set this if you want to get the root + node in the resulting object. + * `emptyTag` (default: `''`): what will the value of empty nodes be. In case + you want to use an empty object as a default value, it is better to provide a factory + function `() => ({})` instead. Without this function a plain object would + become a shared reference across all occurrences with unwanted behavior. + * `explicitArray` (default: `true`): Always put child nodes in an array if + true; otherwise an array is created only if there is more than one. + * `ignoreAttrs` (default: `false`): Ignore all XML attributes and only create + text nodes. + * `mergeAttrs` (default: `false`): Merge attributes and child elements as + properties of the parent, instead of keying attributes off a child + attribute object. This option is ignored if `ignoreAttrs` is `true`. + * `validator` (default `null`): You can specify a callable that validates + the resulting structure somehow, however you want. See unit tests + for an example. + * `xmlns` (default `false`): Give each element a field usually called '$ns' + (the first character is the same as attrkey) that contains its local name + and namespace URI. + * `explicitChildren` (default `false`): Put child elements to separate + property. Doesn't work with `mergeAttrs = true`. If element has no children + then "children" won't be created. Added in 0.2.5. + * `childkey` (default `$$`): Prefix that is used to access child elements if + `explicitChildren` is set to `true`. Added in 0.2.5. + * `preserveChildrenOrder` (default `false`): Modifies the behavior of + `explicitChildren` so that the value of the "children" property becomes an + ordered array. When this is `true`, every node will also get a `#name` field + whose value will correspond to the XML nodeName, so that you may iterate + the "children" array and still be able to determine node names. The named + (and potentially unordered) properties are also retained in this + configuration at the same level as the ordered "children" array. Added in + 0.4.9. + * `charsAsChildren` (default `false`): Determines whether chars should be + considered children if `explicitChildren` is on. Added in 0.2.5. + * `includeWhiteChars` (default `false`): Determines whether whitespace-only + text nodes should be included. Added in 0.4.17. + * `async` (default `false`): Should the callbacks be async? This *might* be + an incompatible change if your code depends on sync execution of callbacks. + Future versions of `xml2js` might change this default, so the recommendation + is to not depend on sync execution anyway. Added in 0.2.6. + * `strict` (default `true`): Set sax-js to strict or non-strict parsing mode. + Defaults to `true` which is *highly* recommended, since parsing HTML which + is not well-formed XML might yield just about anything. Added in 0.2.7. + * `attrNameProcessors` (default: `null`): Allows the addition of attribute + name processing functions. Accepts an `Array` of functions with following + signature: + ```javascript + function (name){ + //do something with `name` + return name + } + ``` + Added in 0.4.14 + * `attrValueProcessors` (default: `null`): Allows the addition of attribute + value processing functions. Accepts an `Array` of functions with following + signature: + ```javascript + function (value, name){ + //do something with `name` + return name + } + ``` + Added in 0.4.1 + * `tagNameProcessors` (default: `null`): Allows the addition of tag name + processing functions. Accepts an `Array` of functions with following + signature: + ```javascript + function (name){ + //do something with `name` + return name + } + ``` + Added in 0.4.1 + * `valueProcessors` (default: `null`): Allows the addition of element value + processing functions. Accepts an `Array` of functions with following + signature: + ```javascript + function (value, name){ + //do something with `name` + return name + } + ``` + Added in 0.4.6 + +Options for the `Builder` class +------------------------------- +These options are specified by ``new Builder({optionName: value})``. +Possible options are: + + * `attrkey` (default: `$`): Prefix that is used to access the attributes. + Version 0.1 default was `@`. + * `charkey` (default: `_`): Prefix that is used to access the character + content. Version 0.1 default was `#`. + * `rootName` (default `root` or the root key name): root element name to be used in case + `explicitRoot` is `false` or to override the root element name. + * `renderOpts` (default `{ 'pretty': true, 'indent': ' ', 'newline': '\n' }`): + Rendering options for xmlbuilder-js. + * pretty: prettify generated XML + * indent: whitespace for indentation (only when pretty) + * newline: newline char (only when pretty) + * `xmldec` (default `{ 'version': '1.0', 'encoding': 'UTF-8', 'standalone': true }`: + XML declaration attributes. + * `xmldec.version` A version number string, e.g. 1.0 + * `xmldec.encoding` Encoding declaration, e.g. UTF-8 + * `xmldec.standalone` standalone document declaration: true or false + * `doctype` (default `null`): optional DTD. Eg. `{'ext': 'hello.dtd'}` + * `headless` (default: `false`): omit the XML header. Added in 0.4.3. + * `allowSurrogateChars` (default: `false`): allows using characters from the Unicode + surrogate blocks. + * `cdata` (default: `false`): wrap text nodes in `` instead of + escaping when necessary. Does not add `` if it is not required. + Added in 0.4.5. + +`renderOpts`, `xmldec`,`doctype` and `headless` pass through to +[xmlbuilder-js](https://github.com/oozcitak/xmlbuilder-js). + +Updating to new version +======================= + +Version 0.2 changed the default parsing settings, but version 0.1.14 introduced +the default settings for version 0.2, so these settings can be tried before the +migration. + +```javascript +var xml2js = require('xml2js'); +var parser = new xml2js.Parser(xml2js.defaults["0.2"]); +``` + +To get the 0.1 defaults in version 0.2 you can just use +`xml2js.defaults["0.1"]` in the same place. This provides you with enough time +to migrate to the saner way of parsing in `xml2js` 0.2. We try to make the +migration as simple and gentle as possible, but some breakage cannot be +avoided. + +So, what exactly did change and why? In 0.2 we changed some defaults to parse +the XML in a more universal and sane way. So we disabled `normalize` and `trim` +so `xml2js` does not cut out any text content. You can reenable this at will of +course. A more important change is that we return the root tag in the resulting +JavaScript structure via the `explicitRoot` setting, so you need to access the +first element. This is useful for anybody who wants to know what the root node +is and preserves more information. The last major change was to enable +`explicitArray`, so everytime it is possible that one might embed more than one +sub-tag into a tag, xml2js >= 0.2 returns an array even if the array just +includes one element. This is useful when dealing with APIs that return +variable amounts of subtags. + +Running tests, development +========================== + +[![Build Status](https://travis-ci.org/Leonidas-from-XIV/node-xml2js.svg?branch=master)](https://travis-ci.org/Leonidas-from-XIV/node-xml2js) +[![Coverage Status](https://coveralls.io/repos/Leonidas-from-XIV/node-xml2js/badge.svg?branch=)](https://coveralls.io/r/Leonidas-from-XIV/node-xml2js?branch=master) +[![Dependency Status](https://david-dm.org/Leonidas-from-XIV/node-xml2js.svg)](https://david-dm.org/Leonidas-from-XIV/node-xml2js) + +The development requirements are handled by npm, you just need to install them. +We also have a number of unit tests, they can be run using `npm test` directly +from the project root. This runs zap to discover all the tests and execute +them. + +If you like to contribute, keep in mind that `xml2js` is written in +CoffeeScript, so don't develop on the JavaScript files that are checked into +the repository for convenience reasons. Also, please write some unit test to +check your behaviour and if it is some user-facing thing, add some +documentation to this README, so people will know it exists. Thanks in advance! + +Getting support +=============== + +Please, if you have a problem with the library, first make sure you read this +README. If you read this far, thanks, you're good. Then, please make sure your +problem really is with `xml2js`. It is? Okay, then I'll look at it. Send me a +mail and we can talk. Please don't open issues, as I don't think that is the +proper forum for support problems. Some problems might as well really be bugs +in `xml2js`, if so I'll let you know to open an issue instead :) + +But if you know you really found a bug, feel free to open an issue instead. diff --git a/common/web/types/src/deps/xml2js/bom.js b/common/web/types/src/deps/xml2js/bom.js new file mode 100644 index 00000000000..0ad6e2a4a43 --- /dev/null +++ b/common/web/types/src/deps/xml2js/bom.js @@ -0,0 +1,8 @@ +"use strict"; +export function stripBOM(str) { + if (str[0] === '\uFEFF') { + return str.substring(1); + } else { + return str; + } +}; diff --git a/common/web/types/src/deps/xml2js/builder.js b/common/web/types/src/deps/xml2js/builder.js new file mode 100644 index 00000000000..5dfca61c9f6 --- /dev/null +++ b/common/web/types/src/deps/xml2js/builder.js @@ -0,0 +1,118 @@ +var escapeCDATA, requiresCDATA, wrapCDATA, + hasProp = {}.hasOwnProperty; + +import * as builder from 'xmlbuilder'; +import { defaults } from './defaults.js'; + +requiresCDATA = function(entry) { + return typeof entry === "string" && (entry.indexOf('&') >= 0 || entry.indexOf('>') >= 0 || entry.indexOf('<') >= 0); +}; + +wrapCDATA = function(entry) { + return ""; +}; + +escapeCDATA = function(entry) { + return entry.replace(']]>', ']]]]>'); +}; + +export class Builder { + constructor(opts) { + var key, ref, value; + this.options = {}; + ref = defaults["0.2"]; + for (key in ref) { + if (!hasProp.call(ref, key)) continue; + value = ref[key]; + this.options[key] = value; + } + for (key in opts) { + if (!hasProp.call(opts, key)) continue; + value = opts[key]; + this.options[key] = value; + } + } + + buildObject(rootObj) { + var attrkey, charkey, render, rootElement, rootName; + attrkey = this.options.attrkey; + charkey = this.options.charkey; + if ((Object.keys(rootObj).length === 1) && (this.options.rootName === defaults['0.2'].rootName)) { + rootName = Object.keys(rootObj)[0]; + rootObj = rootObj[rootName]; + } else { + rootName = this.options.rootName; + } + render = (function(_this) { + return function(element, obj) { + var attr, child, entry, index, key, value; + if (typeof obj !== 'object') { + if (_this.options.cdata && requiresCDATA(obj)) { + element.raw(wrapCDATA(obj)); + } else { + element.txt(obj); + } + } else if (Array.isArray(obj)) { + for (index in obj) { + if (!hasProp.call(obj, index)) continue; + child = obj[index]; + for (key in child) { + entry = child[key]; + element = render(element.ele(key), entry).up(); + } + } + } else { + for (key in obj) { + if (!hasProp.call(obj, key)) continue; + child = obj[key]; + if (key === attrkey) { + if (typeof child === "object") { + for (attr in child) { + value = child[attr]; + element = element.att(attr, value); + } + } + } else if (key === charkey) { + if (_this.options.cdata && requiresCDATA(child)) { + element = element.raw(wrapCDATA(child)); + } else { + element = element.txt(child); + } + } else if (Array.isArray(child)) { + for (index in child) { + if (!hasProp.call(child, index)) continue; + entry = child[index]; + if (typeof entry === 'string') { + if (_this.options.cdata && requiresCDATA(entry)) { + element = element.ele(key).raw(wrapCDATA(entry)).up(); + } else { + element = element.ele(key, entry).up(); + } + } else { + element = render(element.ele(key), entry).up(); + } + } + } else if (typeof child === "object") { + element = render(element.ele(key), child).up(); + } else { + if (typeof child === 'string' && _this.options.cdata && requiresCDATA(child)) { + element = element.ele(key).raw(wrapCDATA(child)).up(); + } else { + if (child == null) { + child = ''; + } + element = element.ele(key, child.toString()).up(); + } + } + } + } + return element; + }; + })(this); + rootElement = builder.create(rootName, this.options.xmldec, this.options.doctype, { + headless: this.options.headless, + allowSurrogateChars: this.options.allowSurrogateChars + }); + return render(rootElement, rootObj).end(this.options.renderOpts); + }; +} diff --git a/common/web/types/src/deps/xml2js/defaults.js b/common/web/types/src/deps/xml2js/defaults.js new file mode 100644 index 00000000000..d1009281792 --- /dev/null +++ b/common/web/types/src/deps/xml2js/defaults.js @@ -0,0 +1,69 @@ +// Generated by CoffeeScript 1.12.7 +export const defaults = { + "0.1": { + explicitCharkey: false, + trim: true, + normalize: true, + normalizeTags: false, + attrkey: "@", + charkey: "#", + explicitArray: false, + ignoreAttrs: false, + mergeAttrs: false, + explicitRoot: false, + validator: null, + xmlns: false, + explicitChildren: false, + childkey: '@@', + charsAsChildren: false, + includeWhiteChars: false, + async: false, + strict: true, + attrNameProcessors: null, + attrValueProcessors: null, + tagNameProcessors: null, + valueProcessors: null, + emptyTag: '' + }, + "0.2": { + explicitCharkey: false, + trim: false, + normalize: false, + normalizeTags: false, + attrkey: "$", + charkey: "_", + explicitArray: true, + ignoreAttrs: false, + mergeAttrs: false, + explicitRoot: true, + validator: null, + xmlns: false, + explicitChildren: false, + preserveChildrenOrder: false, + childkey: '$$', + charsAsChildren: false, + includeWhiteChars: false, + async: false, + strict: true, + attrNameProcessors: null, + attrValueProcessors: null, + tagNameProcessors: null, + valueProcessors: null, + rootName: 'root', + xmldec: { + 'version': '1.0', + 'encoding': 'UTF-8', + 'standalone': true + }, + doctype: null, + renderOpts: { + 'pretty': true, + 'indent': ' ', + 'newline': '\n' + }, + headless: false, + chunkSize: 10000, + emptyTag: '', + cdata: false + } + }; diff --git a/common/web/types/src/deps/xml2js/parser.js b/common/web/types/src/deps/xml2js/parser.js new file mode 100644 index 00000000000..aa0101ea7d2 --- /dev/null +++ b/common/web/types/src/deps/xml2js/parser.js @@ -0,0 +1,377 @@ + var isEmpty, processItem, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + +import sax from 'sax'; +import { EventEmitter } from 'events'; +import * as bom from './bom.js'; +import * as processors from './processors.js'; +import { setImmediate } from 'timers'; +import { defaults } from './defaults.js'; + + isEmpty = function(thing) { + return typeof thing === "object" && (thing != null) && Object.keys(thing).length === 0; + }; + + processItem = function(processors, item, key) { + var i, len, process; + for (i = 0, len = processors.length; i < len; i++) { + process = processors[i]; + item = process(item, key); + } + return item; + }; + +/** @type Class */ +export class Parser extends EventEmitter { +// export const Parser = (function(superClass) { + // extend(Parser, superClass); + + constructor(opts) { + super(); + this.parseStringPromise = bind(this.parseStringPromise, this); + this.parseString = bind(this.parseString, this); + this.reset = bind(this.reset, this); + this.assignOrPush = bind(this.assignOrPush, this); + this.processAsync = bind(this.processAsync, this); + var key, ref, value; + if (!(this instanceof Parser)) { + return new Parser(opts); + } + this.options = {}; + ref = defaults["0.2"]; + for (key in ref) { + if (!hasProp.call(ref, key)) continue; + value = ref[key]; + this.options[key] = value; + } + for (key in opts) { + if (!hasProp.call(opts, key)) continue; + value = opts[key]; + this.options[key] = value; + } + if (this.options.xmlns) { + this.options.xmlnskey = this.options.attrkey + "ns"; + } + if (this.options.normalizeTags) { + if (!this.options.tagNameProcessors) { + this.options.tagNameProcessors = []; + } + this.options.tagNameProcessors.unshift(processors.normalize); + } + this.reset(); + } + + processAsync() { + var chunk, err; + try { + if (this.remaining.length <= this.options.chunkSize) { + chunk = this.remaining; + this.remaining = ''; + this.saxParser = this.saxParser.write(chunk); + return this.saxParser.close(); + } else { + chunk = this.remaining.substr(0, this.options.chunkSize); + this.remaining = this.remaining.substr(this.options.chunkSize, this.remaining.length); + this.saxParser = this.saxParser.write(chunk); + return setImmediate(this.processAsync); + } + } catch (error1) { + err = error1; + if (!this.saxParser.errThrown) { + this.saxParser.errThrown = true; + return this.emit(err); + } + } + }; + + assignOrPush(obj, key, newValue) { + if (!(key in obj)) { + if (!this.options.explicitArray) { + return obj[key] = newValue; + } else { + return obj[key] = [newValue]; + } + } else { + if (!(obj[key] instanceof Array)) { + obj[key] = [obj[key]]; + } + return obj[key].push(newValue); + } + }; + + reset() { + var attrkey, charkey, ontext, stack; + this.removeAllListeners(); + this.saxParser = sax.parser(this.options.strict, { + trim: false, + normalize: false, + xmlns: this.options.xmlns + }); + this.saxParser.errThrown = false; + this.saxParser.onerror = (function(_this) { + return function(error) { + _this.saxParser.resume(); + if (!_this.saxParser.errThrown) { + _this.saxParser.errThrown = true; + return _this.emit("error", error); + } + }; + })(this); + this.saxParser.onend = (function(_this) { + return function() { + if (!_this.saxParser.ended) { + _this.saxParser.ended = true; + return _this.emit("end", _this.resultObject); + } + }; + })(this); + this.saxParser.ended = false; + this.EXPLICIT_CHARKEY = this.options.explicitCharkey; + this.resultObject = null; + stack = []; + attrkey = this.options.attrkey; + charkey = this.options.charkey; + this.saxParser.onopentag = (function(_this) { + return function(node) { + var key, newValue, obj, processedKey, ref; + obj = Object.create(null); + obj[charkey] = ""; + if (!_this.options.ignoreAttrs) { + ref = node.attributes; + for (key in ref) { + if (!hasProp.call(ref, key)) continue; + if (!(attrkey in obj) && !_this.options.mergeAttrs) { + obj[attrkey] = Object.create(null); + } + newValue = _this.options.attrValueProcessors ? processItem(_this.options.attrValueProcessors, node.attributes[key], key) : node.attributes[key]; + processedKey = _this.options.attrNameProcessors ? processItem(_this.options.attrNameProcessors, key) : key; + if (_this.options.mergeAttrs) { + _this.assignOrPush(obj, processedKey, newValue); + } else { + obj[attrkey][processedKey] = newValue; + } + } + } + obj["#name"] = _this.options.tagNameProcessors ? processItem(_this.options.tagNameProcessors, node.name) : node.name; + if (_this.options.xmlns) { + obj[_this.options.xmlnskey] = { + uri: node.uri, + local: node.local + }; + } + return stack.push(obj); + }; + })(this); + this.saxParser.onclosetag = (function(_this) { + return function() { + var cdata, emptyStr, key, node, nodeName, obj, objClone, old, s, xpath; + obj = stack.pop(); + nodeName = obj["#name"]; + if (!_this.options.explicitChildren || !_this.options.preserveChildrenOrder) { + delete obj["#name"]; + } + if (obj.cdata === true) { + cdata = obj.cdata; + delete obj.cdata; + } + s = stack[stack.length - 1]; + if (obj[charkey].match(/^\s*$/) && !cdata && !_this.options.includeWhiteChars) { + emptyStr = obj[charkey]; + delete obj[charkey]; + } else { + if (_this.options.trim) { + obj[charkey] = obj[charkey].trim(); + } + if (_this.options.normalize) { + obj[charkey] = obj[charkey].replace(/\s{2,}/g, " ").trim(); + } + obj[charkey] = _this.options.valueProcessors ? processItem(_this.options.valueProcessors, obj[charkey], nodeName) : obj[charkey]; + if (Object.keys(obj).length === 1 && charkey in obj && !_this.EXPLICIT_CHARKEY) { + obj = obj[charkey]; + } + } + if (isEmpty(obj)) { + if (typeof _this.options.emptyTag === 'function') { + obj = _this.options.emptyTag(); + } else { + obj = _this.options.emptyTag !== '' ? _this.options.emptyTag : emptyStr; + } + } + if (_this.options.validator != null) { + xpath = "/" + ((function() { + var i, len, results; + results = []; + for (i = 0, len = stack.length; i < len; i++) { + node = stack[i]; + results.push(node["#name"]); + } + return results; + })()).concat(nodeName).join("/"); + (function() { + var err; + try { + return obj = _this.options.validator(xpath, s && s[nodeName], obj); + } catch (error1) { + err = error1; + return _this.emit("error", err); + } + })(); + } + if (_this.options.explicitChildren && !_this.options.mergeAttrs && typeof obj === 'object') { + if (!_this.options.preserveChildrenOrder) { + node = Object.create(null); + if (_this.options.attrkey in obj) { + node[_this.options.attrkey] = obj[_this.options.attrkey]; + delete obj[_this.options.attrkey]; + } + if (!_this.options.charsAsChildren && _this.options.charkey in obj) { + node[_this.options.charkey] = obj[_this.options.charkey]; + delete obj[_this.options.charkey]; + } + if (Object.getOwnPropertyNames(obj).length > 0) { + node[_this.options.childkey] = obj; + } + obj = node; + } else if (s) { + s[_this.options.childkey] = s[_this.options.childkey] || []; + objClone = Object.create(null); + for (key in obj) { + if (!hasProp.call(obj, key)) continue; + objClone[key] = obj[key]; + } + s[_this.options.childkey].push(objClone); + delete obj["#name"]; + if (Object.keys(obj).length === 1 && charkey in obj && !_this.EXPLICIT_CHARKEY) { + obj = obj[charkey]; + } + } + } + if (stack.length > 0) { + return _this.assignOrPush(s, nodeName, obj); + } else { + if (_this.options.explicitRoot) { + old = obj; + obj = Object.create(null); + obj[nodeName] = old; + } + _this.resultObject = obj; + _this.saxParser.ended = true; + return _this.emit("end", _this.resultObject); + } + }; + })(this); + ontext = (function(_this) { + return function(text) { + var charChild, s; + s = stack[stack.length - 1]; + if (s) { + s[charkey] += text; + if (_this.options.explicitChildren && _this.options.preserveChildrenOrder && _this.options.charsAsChildren && (_this.options.includeWhiteChars || text.replace(/\\n/g, '').trim() !== '')) { + s[_this.options.childkey] = s[_this.options.childkey] || []; + charChild = { + '#name': '__text__' + }; + charChild[charkey] = text; + if (_this.options.normalize) { + charChild[charkey] = charChild[charkey].replace(/\s{2,}/g, " ").trim(); + } + s[_this.options.childkey].push(charChild); + } + return s; + } + }; + })(this); + this.saxParser.ontext = ontext; + return this.saxParser.oncdata = (function(_this) { + return function(text) { + var s; + s = ontext(text); + if (s) { + return s.cdata = true; + } + }; + })(this); + }; + + parseString(str, cb) { + var err; + if ((cb != null) && typeof cb === "function") { + this.on("end", function(result) { + this.reset(); + return cb(null, result); + }); + this.on("error", function(err) { + this.reset(); + return cb(err); + }); + } + try { + str = str.toString(); + if (str.trim() === '') { + this.emit("end", null); + return true; + } + str = bom.stripBOM(str); + if (this.options.async) { + this.remaining = str; + setImmediate(this.processAsync); + return this.saxParser; + } + return this.saxParser.write(str).close(); + } catch (error1) { + err = error1; + if (!(this.saxParser.errThrown || this.saxParser.ended)) { + this.emit('error', err); + return this.saxParser.errThrown = true; + } else if (this.saxParser.ended) { + throw err; + } + } + }; + + parseStringPromise(str) { + return new Promise((function(_this) { + return function(resolve, reject) { + return _this.parseString(str, function(err, value) { + if (err) { + return reject(err); + } else { + return resolve(value); + } + }); + }; + })(this)); + }; + + } + + export const parseString = function(str, a, b) { + var cb, options, parser; + if (b != null) { + if (typeof b === 'function') { + cb = b; + } + if (typeof a === 'object') { + options = a; + } + } else { + if (typeof a === 'function') { + cb = a; + } + options = {}; + } + parser = new Parser(options); + return parser.parseString(str, cb); + }; + + export const parseStringPromise = function(str, a) { + var options, parser; + if (typeof a === 'object') { + options = a; + } + parser = new Parser(options); + return parser.parseStringPromise(str); + }; + diff --git a/common/web/types/src/deps/xml2js/processors.js b/common/web/types/src/deps/xml2js/processors.js new file mode 100644 index 00000000000..2a6849088c1 --- /dev/null +++ b/common/web/types/src/deps/xml2js/processors.js @@ -0,0 +1,31 @@ + "use strict"; + var prefixMatch; + + prefixMatch = new RegExp(/(?!xmlns)^.*:/); + + export const normalize = function(str) { + return str.toLowerCase(); + }; + + export const firstCharLowerCase = function(str) { + return str.charAt(0).toLowerCase() + str.slice(1); + }; + + export const stripPrefix = function(str) { + return str.replace(prefixMatch, ''); + }; + + export const parseNumbers = function(str) { + if (!isNaN(str)) { + str = str % 1 === 0 ? parseInt(str, 10) : parseFloat(str); + } + return str; + }; + + export const parseBooleans = function(str) { + if (/^(?:true|false)$/i.test(str)) { + str = str.toLowerCase() === 'true'; + } + return str; + }; + diff --git a/common/web/types/src/deps/xml2js/xml2js.js b/common/web/types/src/deps/xml2js/xml2js.js new file mode 100644 index 00000000000..8ecbe3bcf2f --- /dev/null +++ b/common/web/types/src/deps/xml2js/xml2js.js @@ -0,0 +1,27 @@ +var + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + // import { defaults } from './defaults.js'; + import * as builder from './builder.js'; + import * as parser from './parser.js'; + import * as processors from './processors.js'; + + // export const defaults = defaults.defaults; + // export const processors = processors; + + /** @type Class */ + export class ValidationError extends Error { + constructor(message) { + super(message); + this.message = message; + } + }; + + export const Parser = parser.Parser; + + export const Builder = builder.Builder; + + export const parseString = parser.parseString; + + export const parseStringPromise = parser.parseStringPromise; diff --git a/common/web/types/src/kpj/kpj-file-reader.ts b/common/web/types/src/kpj/kpj-file-reader.ts index d005e0a0abb..eb2a168a48c 100644 --- a/common/web/types/src/kpj/kpj-file-reader.ts +++ b/common/web/types/src/kpj/kpj-file-reader.ts @@ -1,4 +1,4 @@ -import * as xml2js from 'xml2js'; +import * as xml2js from '../deps/xml2js/xml2js.js'; import { KPJFile, KPJFileProject } from './kpj-file.js'; import { boxXmlArray } from '../util/util.js'; import { KeymanDeveloperProject, KeymanDeveloperProjectFile10, KeymanDeveloperProjectType } from './keyman-developer-project.js'; diff --git a/common/web/types/src/kvk/kvks-file-reader.ts b/common/web/types/src/kvk/kvks-file-reader.ts index 532818946d4..ff3a094e6f0 100644 --- a/common/web/types/src/kvk/kvks-file-reader.ts +++ b/common/web/types/src/kvk/kvks-file-reader.ts @@ -1,4 +1,4 @@ -import * as xml2js from 'xml2js'; +import * as xml2js from '../deps/xml2js/xml2js.js'; import KVKSourceFile from './kvks-file.js'; import { boxXmlArray } from '../util/util.js'; import { DEFAULT_KVK_FONT, VisualKeyboard, VisualKeyboardHeaderFlags, VisualKeyboardKey, VisualKeyboardKeyFlags, VisualKeyboardLegalShiftStates, VisualKeyboardShiftState } from './visual-keyboard.js'; diff --git a/common/web/types/src/kvk/kvks-file-writer.ts b/common/web/types/src/kvk/kvks-file-writer.ts index 3ca94aa2583..19327e779da 100644 --- a/common/web/types/src/kvk/kvks-file-writer.ts +++ b/common/web/types/src/kvk/kvks-file-writer.ts @@ -1,4 +1,4 @@ -import * as xml2js from 'xml2js'; +import * as xml2js from '../deps/xml2js/xml2js.js'; import KVKSourceFile, { KVKSEncoding, KVKSFlags, KVKSKey, KVKSLayer } from './kvks-file.js'; import { VisualKeyboard, VisualKeyboardHeaderFlags, VisualKeyboardKeyFlags, VisualKeyboardLegalShiftStates, VisualKeyboardShiftState } from './visual-keyboard.js'; import { USVirtualKeyCodes } from '../consts/virtual-key-constants.js'; diff --git a/common/web/types/src/ldml-keyboard/ldml-keyboard-xml-reader.ts b/common/web/types/src/ldml-keyboard/ldml-keyboard-xml-reader.ts index 4f5c30bb1ac..9055e8ed1de 100644 --- a/common/web/types/src/ldml-keyboard/ldml-keyboard-xml-reader.ts +++ b/common/web/types/src/ldml-keyboard/ldml-keyboard-xml-reader.ts @@ -1,4 +1,4 @@ -import * as xml2js from 'xml2js'; +import * as xml2js from '../deps/xml2js/xml2js.js'; import { LDMLKeyboardXMLSourceFile, LKImport, ImportStatus } from './ldml-keyboard-xml.js'; import { boxXmlArray } from '../util/util.js'; import { CompilerCallbacks } from '../util/compiler-interfaces.js'; diff --git a/common/web/types/src/main.ts b/common/web/types/src/main.ts index 5c79ed67614..3d18812876c 100644 --- a/common/web/types/src/main.ts +++ b/common/web/types/src/main.ts @@ -55,4 +55,6 @@ export * as util from './util/util.js'; export * as KeymanFileTypes from './util/file-types.js'; export * as Schemas from './schemas.js'; -export * as SchemaValidators from './schema-validators.js'; \ No newline at end of file +export * as SchemaValidators from './schema-validators.js'; + +export * as xml2js from './deps/xml2js/xml2js.js'; \ No newline at end of file diff --git a/common/web/types/tsconfig.json b/common/web/types/tsconfig.json index cd779632a0d..0473ae92eee 100644 --- a/common/web/types/tsconfig.json +++ b/common/web/types/tsconfig.json @@ -9,6 +9,7 @@ "preserveConstEnums": true, }, "include": [ + "src/deps/xml2js/*.js", "src/**/*.ts", "src/schemas/*.mjs", // Import the validators ], diff --git a/developer/src/common/delphi/packages/Keyman.System.PackageInfoRefreshKeyboards.pas b/developer/src/common/delphi/packages/Keyman.System.PackageInfoRefreshKeyboards.pas index 01e504d7a48..23b7cb4664f 100644 --- a/developer/src/common/delphi/packages/Keyman.System.PackageInfoRefreshKeyboards.pas +++ b/developer/src/common/delphi/packages/Keyman.System.PackageInfoRefreshKeyboards.pas @@ -227,7 +227,15 @@ function TPackageInfoRefreshKeyboards.IsKeyboardFileByContent(f: TPackageContent // Look for Keyboard_ with TStringStream.Create('', TEncoding.UTF8) do try - LoadFromFile(f.FileName); + try + LoadFromFile(f.FileName); + except + on E:EEncodingError do + begin + // If the file cannot be loaded as UTF-8, we'll ignore it; #11687 + Exit(False); + end; + end; Result := TRegEx.IsMatch(DataString, '\bKeyboard_'+id+'\b', []); finally Free; diff --git a/developer/src/kmc-ldml/package.json b/developer/src/kmc-ldml/package.json index dea5ffb5b29..0cdddcb8c9f 100644 --- a/developer/src/kmc-ldml/package.json +++ b/developer/src/kmc-ldml/package.json @@ -28,7 +28,6 @@ "@keymanapp/keyman-version": "*", "@keymanapp/kmc-kmn": "*", "@keymanapp/ldml-keyboard-constants": "*", - "restructure": "git+https://github.com/keymanapp/dependency-restructure.git#7a188a1e26f8f36a175d95b67ffece8702363dfc", "semver": "^7.5.2" }, "devDependencies": { diff --git a/developer/src/kmc-package/package.json b/developer/src/kmc-package/package.json index fb88591fdc7..dd821e3008e 100644 --- a/developer/src/kmc-package/package.json +++ b/developer/src/kmc-package/package.json @@ -31,8 +31,7 @@ "dependencies": { "@keymanapp/common-types": "*", "jszip": "^3.7.0", - "marked": "^7.0.0", - "xml2js": "git+https://github.com/keymanapp/dependency-node-xml2js#535fe732dc408d697e0f847c944cc45f0baf0829" + "marked": "^7.0.0" }, "devDependencies": { "@keymanapp/developer-test-helpers": "*", diff --git a/developer/src/kmc-package/src/compiler/kmp-compiler.ts b/developer/src/kmc-package/src/compiler/kmp-compiler.ts index ff2901c1028..0d4740de9e0 100644 --- a/developer/src/kmc-package/src/compiler/kmp-compiler.ts +++ b/developer/src/kmc-package/src/compiler/kmp-compiler.ts @@ -1,4 +1,4 @@ -import * as xml2js from 'xml2js'; +import { xml2js } from '@keymanapp/common-types'; import JSZip from 'jszip'; import KEYMAN_VERSION from "@keymanapp/keyman-version"; diff --git a/developer/src/tike/child/UfrmPackageEditor.pas b/developer/src/tike/child/UfrmPackageEditor.pas index 39ab96b5f81..5aa02b50b36 100644 --- a/developer/src/tike/child/UfrmPackageEditor.pas +++ b/developer/src/tike/child/UfrmPackageEditor.pas @@ -1802,7 +1802,7 @@ procedure TfrmPackageEditor.EnableKeyboardTabControls; cmdKeyboardRemoveLanguage.Enabled := e; cmdKeyboardEditLanguage.Enabled := e; - e := (lbKeyboards.ItemIndex >= 0) and (gridKeyboardLanguages.Row > 0); + e := (lbKeyboards.ItemIndex >= 0) and (gridKeyboardExamples.Row > 0); gridKeyboardExamples.Enabled := e; cmdKeyboardRemoveExample.Enabled := e; cmdKeyboardEditExample.Enabled := e; diff --git a/developer/src/tike/xml/app/editor/editor.js b/developer/src/tike/xml/app/editor/editor.js index d8a076def4c..73c48a2237f 100644 --- a/developer/src/tike/xml/app/editor/editor.js +++ b/developer/src/tike/xml/app/editor/editor.js @@ -199,6 +199,13 @@ async function loadSettings() { }; context.updateExecutionPoint = function (row) { + if(!editor) { + // At debugger startup time, it initializes asynchronously at the same + // time as the editor, which means that in some circumstances the + // debugger will call to SetExecutionPointLine before the editor has + // loaded. The safest thing to do here is just exit. #11586 + return; + } if(row >= 0) { executionPoint = editor.deltaDecorations( executionPoint, diff --git a/developer/src/tike/xml/help/contexthelp.xml b/developer/src/tike/xml/help/contexthelp.xml index aa57f676ef4..cd04d5746b6 100644 --- a/developer/src/tike/xml/help/contexthelp.xml +++ b/developer/src/tike/xml/help/contexthelp.xml @@ -4,11 +4,93 @@
-

The Filter allows a user to reduce the number of characters displayed in the character map. The standard filter options used are by font name or block name.

+

The Filter allows a user to reduce the number of characters displayed in the character map. The standard filter options used are by font name or block name.

+

The Character Map Grid displays each character in a square, with a visual representation of the character and the Unicode value displayed at the bottom of the square. Each font group is divided into a block headed by the font name.

+ + +

The Filter allows a user to reduce the number of characters displayed in the + character map. The standard filter options used are by font name or block name.

+
+ + +

The filter format for a range is: [U+]XXXX-[U+]YYYY, where U+ is optional, + XXXX is the starting Unicode value and YYYY is the finishing Unicode value.

+
+ + +

The filter format for a range is: [U+]XXXX-[U+]YYYY, where U+ is optional, + XXXX is the starting Unicode value and YYYY is the finishing Unicode value.

+
+ + +

The filter format for a range is: [U+]XXXX-[U+]YYYY, where U+ is optional, + XXXX is the starting Unicode value and YYYY is the finishing Unicode value.

+
+ + +

The Filter allows a user to reduce the number of characters displayed in the + character map. The standard filter options used are by font name or block name.

+
+ + +

">" placed at the start of an entry will only show characters in the currently + selected Character Map font. This is helpful when trying to determine which characters + a given font supports.



+

Example: >LAO



+

finds all characters with names starting in "LAO" in the current font

+
+ + +

"<" placed at the start of an entry will search Unicode block names instead of + character names. This is helpful when searching for characters within related + blocks



+

Example: <Thai



+

finds the Thai Unicode block

+
+ + +

Using "*" in an entry serves as a wildcard for any number of places in that entry. + For example, searching for "greek*alpha" will find characters whose Unicode names begin + with the word "Greek" and contain the word "Alpha" any number of places later. + This is helpful when searching for characters that share a common element in + their names (e.g. capital).

+
+ + +

Using "?" anywhere in an entry serves as a wildcard for that single place in the entry. + For example, searching for "s???e" will return both the SPACE and the SMILE characters, + among others.



+
+ + +

Example: 1000-119F



+

finds all characters between U+1000 and U+119F (inclusive) - + the Myanmar alphabet in this case

+
+ + +

Example: LATIN * LETTER [AEIOU]



+

finds all all Latin A,E,I,O or U vowel combinations

+
+ + +

"$" placed at the end of an entry will match from the end of a Unicode character name. + This option works best when used with "*" or "?".



+

Example: LATIN * LETTER A$



+

finds only "a" and "A"

+
+ + +

Click OK to save changes and close the dialog.

+
+ + +

Click Cancel to close the dialog without saving changes.

+