Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support ie browser #1887

Merged
merged 7 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions es5/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
/*
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
*/
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"inlineSources": true,
"lib": [ "es6", "es2015", "dom" ],
"module": "CommonJS",
"noImplicitAny": false,
"outDir": "../dist",
SmileLifeIven marked this conversation as resolved.
Show resolved Hide resolved
"sourceMap": true,
"strict": false,
"target": "ES5"
},
"exclude": [
"../src/**/*.spec.ts",
// used for webpack h5/jq/static .js
"../src/gridstack-h5.ts",
"../src/gridstack-jq.ts",
"../src/gridstack-static.ts",
],
"include": [
"../src/**/*.ts"
],
"typeroots": [
"../node_modules/@types"
]
}
22 changes: 22 additions & 0 deletions es5/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const path = require('path');
const webpackConfig = require('../webpack.config.js');

const config = {...webpackConfig,
target: ['web', 'es5'],
module: {
rules: [
{
test: /\.ts$/,
use: {
loader: 'ts-loader',
options: {
configFile: 'es5/tsconfig.json'
}
},
exclude: ['/node_modules/', '/src/h5/', '/src/index-*.ts'],
},
],
},
};
config.output.path = path.resolve(__dirname, '../dist')
SmileLifeIven marked this conversation as resolved.
Show resolved Hide resolved
module.exports = config
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"scripts": {
"build": "yarn --no-progress && rm -rf dist/* && grunt && webpack && tsc --stripInternal && yarn doc",
SmileLifeIven marked this conversation as resolved.
Show resolved Hide resolved
"buildEs5": "yarn --no-progress && rm -rf dist/* && grunt && webpack --config es5/webpack.config.js && tsc --stripInternal --project es5/tsconfig.json && yarn doc",
"w": "rm -rf dist/* && grunt && webpack",
"t": "rm -rf dist/* && grunt && tsc --stripInternal",
"doc": "doctoc ./README.md && doctoc ./doc/README.md && doctoc ./doc/CHANGES.md",
Expand Down
98 changes: 97 additions & 1 deletion src/gridstack-poly.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,100 @@ if (!Array.prototype['forEach']) {
}
});
});
})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);
})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);

// https://developer.mozilla.org/zh-CN/docs/Web/API/Element/matches
if (!Element.prototype.matches) {
Element.prototype.matches =
Element.prototype.matchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.oMatchesSelector ||
Element.prototype.webkitMatchesSelector ||
function(s) {
var matches = (this.document || this.ownerDocument).querySelectorAll(s),
i = matches.length;
while (--i >= 0 && matches.item(i) !== this) {}
return i > -1;
};
}

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
// Production steps of ECMA-262, Edition 6, 22.1.2.1
if (!Array.from) {
Array.from = (function () {
var toStr = Object.prototype.toString;
var isCallable = function (fn) {
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
};
var toInteger = function (value) {
var number = Number(value);
if (isNaN(number)) { return 0; }
if (number === 0 || !isFinite(number)) { return number; }
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
};
var maxSafeInteger = Math.pow(2, 53) - 1;
var toLength = function (value) {
var len = toInteger(value);
return Math.min(Math.max(len, 0), maxSafeInteger);
};

// The length property of the from method is 1.
return function from(arrayLike/*, mapFn, thisArg */) {
// 1. Let C be the this value.
var C = this;

// 2. Let items be ToObject(arrayLike).
var items = Object(arrayLike);

// 3. ReturnIfAbrupt(items).
if (arrayLike == null) {
throw new TypeError("Array.from requires an array-like object - not null or undefined");
}

// 4. If mapfn is undefined, then let mapping be false.
var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
var T;
if (typeof mapFn !== 'undefined') {
// 5. else
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
if (!isCallable(mapFn)) {
throw new TypeError('Array.from: when provided, the second argument must be a function');
}

// 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 2) {
T = arguments[2];
}
}

// 10. Let lenValue be Get(items, "length").
// 11. Let len be ToLength(lenValue).
var len = toLength(items.length);

// 13. If IsConstructor(C) is true, then
// 13. a. Let A be the result of calling the [[Construct]] internal method
// of C with an argument list containing the single item len.
// 14. a. Else, Let A be ArrayCreate(len).
var A = isCallable(C) ? Object(new C(len)) : new Array(len);

// 16. Let k be 0.
var k = 0;
// 17. Repeat, while k < len… (also steps a - h)
var kValue;
while (k < len) {
kValue = items[k];
if (mapFn) {
A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
} else {
A[k] = kValue;
}
k += 1;
}
// 18. Let putStatus be Put(A, "length", len, true).
A.length = len;
// 20. Return A.
return A;
};
}());
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"outDir": "./dist",
"sourceMap": true,
"strict": false,
// "target": "ES6",
"target": "ES5"
"target": "ES6"
},
"exclude": [
"./src/**/*.spec.ts",
Expand Down
1 change: 0 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = {
mode: 'production', // production vs development
devtool: 'source-map',
// devtool: 'eval-source-map', // for best (large .js) debugging. see https://survivejs.com/webpack/building/source-maps/
target: ['web', 'es5'],
module: {
rules: [
{
Expand Down