@gogocat/data-bind 1.12.0 → 2.0.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.
- package/.editorconfig +14 -14
- package/.vscode/launch.json +12 -12
- package/CONFIGURATION.md +294 -0
- package/REACTIVE_MODE.md +553 -0
- package/README.md +266 -829
- package/babel.config.json +30 -0
- package/dist/js/_escape.d.ts +14 -0
- package/dist/js/_escape.d.ts.map +1 -0
- package/dist/js/applyBinding.d.ts +11 -0
- package/dist/js/applyBinding.d.ts.map +1 -0
- package/dist/js/attrBinding.d.ts +12 -0
- package/dist/js/attrBinding.d.ts.map +1 -0
- package/dist/js/binder.d.ts +67 -0
- package/dist/js/binder.d.ts.map +1 -0
- package/dist/js/changeBinding.d.ts +19 -0
- package/dist/js/changeBinding.d.ts.map +1 -0
- package/dist/js/commentWrapper.d.ts +39 -0
- package/dist/js/commentWrapper.d.ts.map +1 -0
- package/dist/js/config.d.ts +55 -0
- package/dist/js/config.d.ts.map +1 -0
- package/dist/js/createBindingOption.d.ts +32 -0
- package/dist/js/createBindingOption.d.ts.map +1 -0
- package/dist/js/createEventBinding.d.ts +10 -0
- package/dist/js/createEventBinding.d.ts.map +1 -0
- package/dist/js/cssBinding.d.ts +15 -0
- package/dist/js/cssBinding.d.ts.map +1 -0
- package/dist/js/dataBind.js +2756 -2530
- package/dist/js/dataBind.min.js +8 -1
- package/dist/js/dataBind.min.js.map +1 -1
- package/dist/js/domWalker.d.ts +9 -0
- package/dist/js/domWalker.d.ts.map +1 -0
- package/dist/js/forOfBinding.d.ts +12 -0
- package/dist/js/forOfBinding.d.ts.map +1 -0
- package/dist/js/hoverBinding.d.ts +13 -0
- package/dist/js/hoverBinding.d.ts.map +1 -0
- package/dist/js/ifBinding.d.ts +12 -0
- package/dist/js/ifBinding.d.ts.map +1 -0
- package/dist/js/index.d.ts +10 -0
- package/dist/js/index.d.ts.map +1 -0
- package/dist/js/modelBinding.d.ts +12 -0
- package/dist/js/modelBinding.d.ts.map +1 -0
- package/dist/js/postProcess.d.ts +3 -0
- package/dist/js/postProcess.d.ts.map +1 -0
- package/dist/js/pubSub.d.ts +11 -0
- package/dist/js/pubSub.d.ts.map +1 -0
- package/dist/js/reactiveProxy.d.ts +28 -0
- package/dist/js/reactiveProxy.d.ts.map +1 -0
- package/dist/js/renderForOfBinding.d.ts +8 -0
- package/dist/js/renderForOfBinding.d.ts.map +1 -0
- package/dist/js/renderIfBinding.d.ts +22 -0
- package/dist/js/renderIfBinding.d.ts.map +1 -0
- package/dist/js/renderIteration.d.ts +16 -0
- package/dist/js/renderIteration.d.ts.map +1 -0
- package/dist/js/renderTemplate.d.ts +14 -0
- package/dist/js/renderTemplate.d.ts.map +1 -0
- package/dist/js/renderTemplatesBinding.d.ts +19 -0
- package/dist/js/renderTemplatesBinding.d.ts.map +1 -0
- package/dist/js/showBinding.d.ts +13 -0
- package/dist/js/showBinding.d.ts.map +1 -0
- package/dist/js/switchBinding.d.ts +13 -0
- package/dist/js/switchBinding.d.ts.map +1 -0
- package/dist/js/textBinding.d.ts +13 -0
- package/dist/js/textBinding.d.ts.map +1 -0
- package/dist/js/types/_escape.d.ts +14 -0
- package/dist/js/types/_escape.d.ts.map +1 -0
- package/dist/js/types/applyBinding.d.ts +11 -0
- package/dist/js/types/applyBinding.d.ts.map +1 -0
- package/dist/js/types/attrBinding.d.ts +12 -0
- package/dist/js/types/attrBinding.d.ts.map +1 -0
- package/dist/js/types/binder.d.ts +67 -0
- package/dist/js/types/binder.d.ts.map +1 -0
- package/dist/js/types/changeBinding.d.ts +19 -0
- package/dist/js/types/changeBinding.d.ts.map +1 -0
- package/dist/js/types/commentWrapper.d.ts +39 -0
- package/dist/js/types/commentWrapper.d.ts.map +1 -0
- package/dist/js/types/config.d.ts +55 -0
- package/dist/js/types/config.d.ts.map +1 -0
- package/dist/js/types/createBindingOption.d.ts +32 -0
- package/dist/js/types/createBindingOption.d.ts.map +1 -0
- package/dist/js/types/createEventBinding.d.ts +10 -0
- package/dist/js/types/createEventBinding.d.ts.map +1 -0
- package/dist/js/types/cssBinding.d.ts +15 -0
- package/dist/js/types/cssBinding.d.ts.map +1 -0
- package/dist/js/types/domWalker.d.ts +9 -0
- package/dist/js/types/domWalker.d.ts.map +1 -0
- package/dist/js/types/forOfBinding.d.ts +12 -0
- package/dist/js/types/forOfBinding.d.ts.map +1 -0
- package/dist/js/types/hoverBinding.d.ts +13 -0
- package/dist/js/types/hoverBinding.d.ts.map +1 -0
- package/dist/js/types/ifBinding.d.ts +12 -0
- package/dist/js/types/ifBinding.d.ts.map +1 -0
- package/dist/js/types/index.d.ts +10 -0
- package/dist/js/types/index.d.ts.map +1 -0
- package/dist/js/types/modelBinding.d.ts +12 -0
- package/dist/js/types/modelBinding.d.ts.map +1 -0
- package/dist/js/types/postProcess.d.ts +3 -0
- package/dist/js/types/postProcess.d.ts.map +1 -0
- package/dist/js/types/pubSub.d.ts +11 -0
- package/dist/js/types/pubSub.d.ts.map +1 -0
- package/dist/js/types/reactiveProxy.d.ts +28 -0
- package/dist/js/types/reactiveProxy.d.ts.map +1 -0
- package/dist/js/types/renderForOfBinding.d.ts +8 -0
- package/dist/js/types/renderForOfBinding.d.ts.map +1 -0
- package/dist/js/types/renderIfBinding.d.ts +22 -0
- package/dist/js/types/renderIfBinding.d.ts.map +1 -0
- package/dist/js/types/renderIteration.d.ts +16 -0
- package/dist/js/types/renderIteration.d.ts.map +1 -0
- package/dist/js/types/renderTemplate.d.ts +14 -0
- package/dist/js/types/renderTemplate.d.ts.map +1 -0
- package/dist/js/types/renderTemplatesBinding.d.ts +19 -0
- package/dist/js/types/renderTemplatesBinding.d.ts.map +1 -0
- package/dist/js/types/showBinding.d.ts +13 -0
- package/dist/js/types/showBinding.d.ts.map +1 -0
- package/dist/js/types/switchBinding.d.ts +13 -0
- package/dist/js/types/switchBinding.d.ts.map +1 -0
- package/dist/js/types/textBinding.d.ts +13 -0
- package/dist/js/types/textBinding.d.ts.map +1 -0
- package/dist/js/types/types.d.ts +111 -0
- package/dist/js/types/types.d.ts.map +1 -0
- package/dist/js/types/util.d.ts +119 -0
- package/dist/js/types/util.d.ts.map +1 -0
- package/dist/js/types.d.ts +111 -0
- package/dist/js/types.d.ts.map +1 -0
- package/dist/js/util.d.ts +119 -0
- package/dist/js/util.d.ts.map +1 -0
- package/eslint.config.js +124 -0
- package/examples/DBMONSTER_COMPARISON.md +123 -0
- package/examples/afterRenderDemo.html +119 -0
- package/examples/bootstrap/css/animate.css +1579 -1579
- package/examples/bootstrap/css/bootstrap.min.css +6 -6
- package/examples/bootstrap/css/homeservices.css +378 -390
- package/examples/bootstrap/css/open-iconic.css +511 -511
- package/examples/bootstrap/fonts/open-iconic.svg +543 -543
- package/examples/bootstrap/js/compMessageDialog.js +20 -19
- package/examples/bootstrap/js/compSearchBar.js +12 -19
- package/examples/bootstrap/js/compSearchResults.js +50 -46
- package/examples/bootstrap/js/featureAdsResult.json +65 -65
- package/examples/bootstrap/js/searchResult.json +57 -57
- package/examples/bootstrap.html +343 -332
- package/examples/css/baseTodo.css +141 -141
- package/examples/css/dbMonsterStyles.css +27 -27
- package/examples/css/indexTodo.css +374 -374
- package/examples/dbmonsterForOfReactive.html +40 -0
- package/examples/dbmonsterReact.html +19 -0
- package/examples/forOfBindingSimpleDebug.html +45 -0
- package/examples/globalConfig.html +131 -0
- package/examples/js/afterRenderDemo.js +190 -0
- package/examples/js/appTodo.js +46 -46
- package/examples/js/attrBindingDemo.js +2 -2
- package/examples/js/dbMonApp.js +24 -26
- package/examples/js/dbMonAppReact.jsx +79 -0
- package/examples/js/dbMonAppReactive.js +28 -0
- package/examples/js/fiberDemo.js +4 -4
- package/examples/js/filtersDemo.js +8 -8
- package/examples/js/forOfDemo.js +7 -9
- package/examples/js/forOfDemoComplex.js +44 -17
- package/examples/js/form.js +14 -14
- package/examples/js/globalConfig.js +117 -0
- package/examples/js/ifBindingDemo.js +16 -16
- package/examples/js/reactiveDemo.js +119 -0
- package/examples/js/switchBindingDemo.js +8 -8
- package/examples/react-dbmonster/dist/bundle.js +43 -0
- package/examples/react-dbmonster/package-lock.json +537 -0
- package/examples/react-dbmonster/package.json +16 -0
- package/examples/react-dbmonster/src/index.jsx +80 -0
- package/examples/reactiveDemo.html +127 -0
- package/examples/refreshRateTest.html +75 -75
- package/index.html +841 -0
- package/package.json +31 -34
- package/rollup.config.js +79 -36
- package/src/{_escape.js → _escape.ts} +19 -17
- package/src/{applyBinding.js → applyBinding.ts} +27 -18
- package/src/{attrBinding.js → attrBinding.ts} +14 -13
- package/src/{binder.js → binder.ts} +289 -181
- package/src/changeBinding.ts +93 -0
- package/src/{commentWrapper.js → commentWrapper.ts} +33 -30
- package/src/config.ts +107 -0
- package/src/{createBindingOption.js → createBindingOption.ts} +39 -15
- package/src/createEventBinding.ts +88 -0
- package/src/{cssBinding.js → cssBinding.ts} +13 -11
- package/src/{domWalker.js → domWalker.ts} +44 -30
- package/src/{forOfBinding.js → forOfBinding.ts} +4 -3
- package/src/hoverBinding.ts +84 -0
- package/src/{ifBinding.js → ifBinding.ts} +14 -12
- package/src/index.ts +53 -0
- package/src/{modelBinding.js → modelBinding.ts} +11 -9
- package/src/{postProcess.js → postProcess.ts} +6 -4
- package/src/{pubSub.js → pubSub.ts} +24 -21
- package/src/reactiveProxy.ts +285 -0
- package/src/{renderForOfBinding.js → renderForOfBinding.ts} +54 -32
- package/src/{renderIfBinding.js → renderIfBinding.ts} +41 -19
- package/src/{renderIteration.js → renderIteration.ts} +24 -8
- package/src/renderTemplate.ts +165 -0
- package/src/renderTemplatesBinding.ts +73 -0
- package/src/{showBinding.js → showBinding.ts} +4 -3
- package/src/{switchBinding.js → switchBinding.ts} +18 -15
- package/src/{textBinding.js → textBinding.ts} +5 -4
- package/src/types.ts +124 -0
- package/src/util.ts +810 -0
- package/test/css/reporter.css +9 -9
- package/test/globals.d.ts +19 -0
- package/test/helpers/testHelper.js +46 -11
- package/test/mocks/featureAdsResult.json +65 -65
- package/test/mocks/searchResult.json +57 -57
- package/test/specs/{attrBinding.spec.js → attrBinding.spec.ts} +103 -106
- package/test/specs/{binder.spec.js → binder.spec.ts} +29 -27
- package/test/specs/blurBinding.spec.ts +60 -0
- package/test/specs/chainableUse.spec.ts +125 -0
- package/test/specs/clickBinding.spec.ts +194 -0
- package/test/specs/{cssBinding.spec.js → cssBinding.spec.ts} +72 -79
- package/test/specs/{dataBindBootstrap.spec.js → dataBindBootstrap.spec.ts} +332 -313
- package/test/specs/{filter.spec.js → filter.spec.ts} +75 -76
- package/test/specs/{forOfBinding.spec.js → forOfBinding.spec.ts} +208 -219
- package/test/specs/formBinding.spec.ts +272 -0
- package/test/specs/ifBinding.spec.ts +165 -0
- package/test/specs/{nestedComponent.spec.js → nestedComponent.spec.ts} +88 -88
- package/test/specs/reactiveProxy.spec.ts +465 -0
- package/test/specs/{showBinding.spec.js → showBinding.spec.ts} +148 -149
- package/test/specs/{switchBinding.spec.js → switchBinding.spec.ts} +172 -173
- package/test/specs/templateBinding.spec.ts +273 -0
- package/test/specs/{textBinding.spec.js → textBinding.spec.ts} +47 -48
- package/test/tsconfig.json +31 -0
- package/test-output.txt +200 -0
- package/test-reactive.html +224 -0
- package/tsconfig.json +28 -0
- package/vendors/lodash.custom.js +4577 -4577
- package/vendors/lodash.custom.min.js +45 -45
- package/vitest.config.js +27 -0
- package/.eslintrc.js +0 -1
- package/.grunt/grunt-contrib-jasmine/boot.js +0 -161
- package/.grunt/grunt-contrib-jasmine/dist/js/dataBind.js +0 -9
- package/.grunt/grunt-contrib-jasmine/grunt-template-jasmine-istanbul/reporter.js +0 -23
- package/.grunt/grunt-contrib-jasmine/jasmine-html.js +0 -853
- package/.grunt/grunt-contrib-jasmine/jasmine.css +0 -271
- package/.grunt/grunt-contrib-jasmine/jasmine.js +0 -9761
- package/.grunt/grunt-contrib-jasmine/jasmine_favicon.png +0 -0
- package/.grunt/grunt-contrib-jasmine/json2.js +0 -489
- package/.grunt/grunt-contrib-jasmine/reporter.js +0 -107
- package/coverage/coverage.json +0 -1
- package/coverage/lcov/lcov-report/base.css +0 -213
- package/coverage/lcov/lcov-report/index.html +0 -93
- package/coverage/lcov/lcov-report/js/dataBind.js.html +0 -6596
- package/coverage/lcov/lcov-report/js/index.html +0 -93
- package/coverage/lcov/lcov-report/prettify.css +0 -1
- package/coverage/lcov/lcov-report/prettify.js +0 -1
- package/coverage/lcov/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov/lcov-report/sorter.js +0 -158
- package/coverage/lcov/lcov.info +0 -1991
- package/eslintrc.json +0 -40
- package/examples/bootstrap/js/bootstrap.min.js +0 -6
- package/examples/bootstrap/js/popper.min.js +0 -5
- package/examples/bootstrap/js/searchSuggestion.js +0 -58
- package/examples/bootstrap/js/typeahead.jquery.js +0 -1538
- package/gruntfile.js +0 -92
- package/gulpfile.js +0 -32
- package/src/applyBindingExport.js +0 -5
- package/src/changeBinding.js +0 -63
- package/src/config.js +0 -66
- package/src/createEventBinding.js +0 -46
- package/src/eventSystem.js +0 -46
- package/src/hoverBinding.js +0 -57
- package/src/index.js +0 -26
- package/src/renderTemplate.js +0 -128
- package/src/renderTemplatesBinding.js +0 -44
- package/src/util.js +0 -648
- package/test/specs/blurBinding.spec.js +0 -57
- package/test/specs/formBinding.spec.js +0 -316
- package/test/specs/ifBinding.spec.js +0 -169
- package/test/specs/templateBinding.spec.js +0 -117
- package/vendors/jasmine-jquery.js +0 -841
- package/vendors/jquery-3.2.1.min.js +0 -4
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gogocat/data-bind",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "dataBind is a small and fast MVVM tool for building front-end web",
|
|
5
5
|
"main": "dist/js/dataBind.js",
|
|
6
|
+
"types": "dist/js/types/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
6
8
|
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
"
|
|
9
|
+
"test": "vitest run",
|
|
10
|
+
"test:watch": "vitest",
|
|
11
|
+
"test:coverage": "vitest run --coverage",
|
|
12
|
+
"build": "npm run lint && rollup -c",
|
|
9
13
|
"watch": "rollup -c -w",
|
|
10
|
-
"
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"lint": "eslint src test --fix"
|
|
11
16
|
},
|
|
12
17
|
"repository": {
|
|
13
18
|
"type": "git",
|
|
@@ -25,35 +30,27 @@
|
|
|
25
30
|
},
|
|
26
31
|
"homepage": "https://gogocat.github.io/dataBind/",
|
|
27
32
|
"devDependencies": {
|
|
28
|
-
"@babel/cli": "^7.
|
|
29
|
-
"@babel/core": "^7.
|
|
30
|
-
"@babel/plugin-transform-object-assign": "^7.
|
|
31
|
-
"@babel/preset-env": "^7.
|
|
32
|
-
"@
|
|
33
|
-
"@rollup/plugin-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"eslint
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"gulp-replace": "^1.1.3",
|
|
51
|
-
"gulp-sourcemaps": "^3.0.0",
|
|
52
|
-
"gulp-uglify-es": "^3.0.0",
|
|
53
|
-
"jasmine-core": "^3.8.0",
|
|
54
|
-
"prettier-eslint": "^13.0.0",
|
|
55
|
-
"rollup": "^2.56.0",
|
|
56
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
57
|
-
"rollup-plugin-eslint": "^7.0.0"
|
|
33
|
+
"@babel/cli": "^7.26.4",
|
|
34
|
+
"@babel/core": "^7.26.0",
|
|
35
|
+
"@babel/plugin-transform-object-assign": "^7.25.9",
|
|
36
|
+
"@babel/preset-env": "^7.26.0",
|
|
37
|
+
"@eslint/js": "^9.17.0",
|
|
38
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
39
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
|
40
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
41
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
42
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
43
|
+
"@testing-library/dom": "^10.4.0",
|
|
44
|
+
"@types/node": "^24.7.2",
|
|
45
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
46
|
+
"eslint": "^9.17.0",
|
|
47
|
+
"globals": "^15.14.0",
|
|
48
|
+
"jsdom": "^25.0.1",
|
|
49
|
+
"rollup": "^4.30.1",
|
|
50
|
+
"rollup-plugin-banner2": "^1.3.0",
|
|
51
|
+
"tslib": "^2.8.1",
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"typescript-eslint": "^8.46.0",
|
|
54
|
+
"vitest": "^3.2.4"
|
|
58
55
|
}
|
|
59
56
|
}
|
package/rollup.config.js
CHANGED
|
@@ -1,41 +1,84 @@
|
|
|
1
1
|
import babel from '@rollup/plugin-babel';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import terser from '@rollup/plugin-terser';
|
|
3
|
+
import replace from '@rollup/plugin-replace';
|
|
4
|
+
import typescript from '@rollup/plugin-typescript';
|
|
5
|
+
import banner2 from 'rollup-plugin-banner2';
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
const pkg = require('./package.json');
|
|
8
|
+
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const bannerText = `/*
|
|
11
|
+
${pkg.name}
|
|
12
|
+
version ${pkg.version}
|
|
13
|
+
By ${pkg.author}
|
|
14
|
+
link ${pkg.homepage}
|
|
15
|
+
license ${pkg.license}
|
|
16
|
+
*/`;
|
|
17
|
+
|
|
18
|
+
export default [
|
|
19
|
+
// UMD build (unminified)
|
|
20
|
+
{
|
|
21
|
+
input: 'src/index.ts',
|
|
22
|
+
output: {
|
|
23
|
+
file: 'dist/js/dataBind.js',
|
|
24
|
+
format: 'umd',
|
|
25
|
+
name: 'dataBind',
|
|
26
|
+
sourcemap: false,
|
|
27
|
+
},
|
|
28
|
+
plugins: [
|
|
29
|
+
typescript({
|
|
30
|
+
tsconfig: './tsconfig.json',
|
|
31
|
+
declaration: true,
|
|
32
|
+
compilerOptions: {
|
|
33
|
+
outDir: './dist/js',
|
|
34
|
+
declarationDir: './dist/js/types',
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
replace({
|
|
38
|
+
preventAssignment: true,
|
|
39
|
+
values: {
|
|
40
|
+
'@version@': pkg.version,
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
babel({
|
|
44
|
+
babelHelpers: 'bundled',
|
|
45
|
+
extensions: ['.js', '.ts'],
|
|
46
|
+
}),
|
|
47
|
+
banner2(() => bannerText),
|
|
48
|
+
],
|
|
15
49
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
50
|
+
// UMD build (minified)
|
|
51
|
+
{
|
|
52
|
+
input: 'src/index.ts',
|
|
53
|
+
output: {
|
|
54
|
+
file: 'dist/js/dataBind.min.js',
|
|
55
|
+
format: 'umd',
|
|
56
|
+
name: 'dataBind',
|
|
57
|
+
sourcemap: true,
|
|
58
|
+
},
|
|
59
|
+
plugins: [
|
|
60
|
+
typescript({
|
|
61
|
+
tsconfig: './tsconfig.json',
|
|
62
|
+
compilerOptions: {
|
|
63
|
+
outDir: './dist/js',
|
|
64
|
+
}
|
|
65
|
+
}),
|
|
66
|
+
replace({
|
|
67
|
+
preventAssignment: true,
|
|
68
|
+
values: {
|
|
69
|
+
'@version@': pkg.version,
|
|
30
70
|
},
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
71
|
+
}),
|
|
72
|
+
babel({
|
|
73
|
+
babelHelpers: 'bundled',
|
|
74
|
+
extensions: ['.js', '.ts'],
|
|
75
|
+
}),
|
|
76
|
+
terser({
|
|
77
|
+
format: {
|
|
78
|
+
comments: false,
|
|
79
|
+
preamble: bannerText,
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
];
|
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
* https://github.com/lodash/lodash/blob/master/escape.js
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const baseToString = (value: unknown): string => {
|
|
8
8
|
if (typeof value == 'string') {
|
|
9
9
|
return value;
|
|
10
10
|
}
|
|
11
11
|
return value == null ? '' : `${value}`;
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
|
|
14
14
|
/** Used to match HTML entities and HTML characters. */
|
|
15
15
|
const reUnescapedHtml = /[&<>"'`]/g;
|
|
16
16
|
const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
|
17
17
|
|
|
18
18
|
/** Used to map characters to HTML entities. */
|
|
19
|
-
const htmlEscapes = {
|
|
19
|
+
const htmlEscapes: Record<string, string> = {
|
|
20
20
|
'&': '&',
|
|
21
21
|
'<': '<',
|
|
22
22
|
'>': '>',
|
|
@@ -26,15 +26,15 @@ const htmlEscapes = {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
* escapeHtmlChar
|
|
30
|
+
* @description convert characters to HTML entities.
|
|
31
|
+
* @private
|
|
32
|
+
* @param {string} chr The matched character to escape.
|
|
33
|
+
* @return {string} Returns the escaped character.
|
|
34
|
+
*/
|
|
35
|
+
const escapeHtmlChar = (chr: string): string => {
|
|
36
36
|
return htmlEscapes[chr];
|
|
37
|
-
}
|
|
37
|
+
};
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
|
|
@@ -42,10 +42,12 @@ function escapeHtmlChar(chr) {
|
|
|
42
42
|
* @param {string} string
|
|
43
43
|
* @return {string} string
|
|
44
44
|
*/
|
|
45
|
-
|
|
45
|
+
const escape = (string: unknown): string => {
|
|
46
46
|
// Reset `lastIndex` because in IE < 9 `String#replace` does not.
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
47
|
+
const strValue = baseToString(string);
|
|
48
|
+
return (strValue && reHasUnescapedHtml.test(strValue)) ?
|
|
49
|
+
strValue.replace(reUnescapedHtml, escapeHtmlChar) :
|
|
50
|
+
strValue;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default escape;
|
|
@@ -9,8 +9,17 @@ import forOfBinding from './forOfBinding'; // depends renderForOfBinding -> this
|
|
|
9
9
|
import ifBinding from './ifBinding';
|
|
10
10
|
import switchBinding from './switchBinding';
|
|
11
11
|
import createEventBinding from './createEventBinding';
|
|
12
|
+
import type {ElementCache, UpdateOption, BindingAttrs, ViewModel, BindingCache} from './types';
|
|
13
|
+
|
|
14
|
+
interface ApplyBindingParams {
|
|
15
|
+
ctx: unknown;
|
|
16
|
+
elementCache: ElementCache;
|
|
17
|
+
updateOption: UpdateOption;
|
|
18
|
+
bindingAttrs: BindingAttrs;
|
|
19
|
+
viewModel: ViewModel;
|
|
20
|
+
}
|
|
12
21
|
|
|
13
|
-
|
|
22
|
+
const applyBinding = ({ctx: _ctx, elementCache, updateOption, bindingAttrs, viewModel}: ApplyBindingParams): void => {
|
|
14
23
|
if (!elementCache || !updateOption) {
|
|
15
24
|
return;
|
|
16
25
|
}
|
|
@@ -19,63 +28,63 @@ function applyBinding({ctx, elementCache, updateOption, bindingAttrs, viewModel}
|
|
|
19
28
|
|
|
20
29
|
// apply forOf Binding
|
|
21
30
|
if (updateOption.forOfBinding && elementCache[bindingAttrs.forOf] && elementCache[bindingAttrs.forOf].length) {
|
|
22
|
-
elementCache[bindingAttrs.forOf].forEach((cache) => {
|
|
31
|
+
elementCache[bindingAttrs.forOf].forEach((cache: BindingCache) => {
|
|
23
32
|
forOfBinding(cache, viewModel, bindingAttrs, updateOption.forceRender);
|
|
24
33
|
});
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
// apply attr Binding
|
|
28
37
|
if (updateOption.attrBinding && elementCache[bindingAttrs.attr] && elementCache[bindingAttrs.attr].length) {
|
|
29
|
-
elementCache[bindingAttrs.attr].forEach((cache) => {
|
|
38
|
+
elementCache[bindingAttrs.attr].forEach((cache: BindingCache) => {
|
|
30
39
|
attrBinding(cache, viewModel, bindingAttrs, updateOption.forceRender);
|
|
31
40
|
});
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
// apply if Binding
|
|
35
44
|
if (updateOption.ifBinding && elementCache[bindingAttrs.if] && elementCache[bindingAttrs.if].length) {
|
|
36
|
-
elementCache[bindingAttrs.if].forEach((cache) => {
|
|
45
|
+
elementCache[bindingAttrs.if].forEach((cache: BindingCache) => {
|
|
37
46
|
ifBinding(cache, viewModel, bindingAttrs, updateOption.forceRender);
|
|
38
47
|
});
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
// apply show Binding
|
|
42
51
|
if (updateOption.showBinding && elementCache[bindingAttrs.show] && elementCache[bindingAttrs.show].length) {
|
|
43
|
-
elementCache[bindingAttrs.show].forEach((cache) => {
|
|
52
|
+
elementCache[bindingAttrs.show].forEach((cache: BindingCache) => {
|
|
44
53
|
showBinding(cache, viewModel, bindingAttrs, updateOption.forceRender);
|
|
45
54
|
});
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
// apply switch Binding
|
|
49
58
|
if (updateOption.switchBinding && elementCache[bindingAttrs.switch] && elementCache[bindingAttrs.switch].length) {
|
|
50
|
-
elementCache[bindingAttrs.switch].forEach((cache) => {
|
|
59
|
+
elementCache[bindingAttrs.switch].forEach((cache: BindingCache) => {
|
|
51
60
|
switchBinding(cache, viewModel, bindingAttrs, updateOption.forceRender);
|
|
52
61
|
});
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
// apply text binding
|
|
56
65
|
if (updateOption.textBinding && elementCache[bindingAttrs.text] && elementCache[bindingAttrs.text].length) {
|
|
57
|
-
elementCache[bindingAttrs.text].forEach((cache) => {
|
|
66
|
+
elementCache[bindingAttrs.text].forEach((cache: BindingCache) => {
|
|
58
67
|
textBinding(cache, viewModel, bindingAttrs, updateOption.forceRender);
|
|
59
68
|
});
|
|
60
69
|
}
|
|
61
70
|
|
|
62
71
|
// apply cssBinding
|
|
63
72
|
if (updateOption.cssBinding && elementCache[bindingAttrs.css] && elementCache[bindingAttrs.css].length) {
|
|
64
|
-
elementCache[bindingAttrs.css].forEach((cache) => {
|
|
73
|
+
elementCache[bindingAttrs.css].forEach((cache: BindingCache) => {
|
|
65
74
|
cssBinding(cache, viewModel, bindingAttrs, updateOption.forceRender);
|
|
66
75
|
});
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
// apply model binding
|
|
70
79
|
if (updateOption.modelBinding && elementCache[bindingAttrs.model] && elementCache[bindingAttrs.model].length) {
|
|
71
|
-
elementCache[bindingAttrs.model].forEach((cache) => {
|
|
80
|
+
elementCache[bindingAttrs.model].forEach((cache: BindingCache) => {
|
|
72
81
|
modelBinding(cache, viewModel, bindingAttrs, updateOption.forceRender);
|
|
73
82
|
});
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
// apply change binding
|
|
77
86
|
if (updateOption.changeBinding && elementCache[bindingAttrs.change] && elementCache[bindingAttrs.change].length) {
|
|
78
|
-
elementCache[bindingAttrs.change].forEach((cache) => {
|
|
87
|
+
elementCache[bindingAttrs.change].forEach((cache: BindingCache) => {
|
|
79
88
|
changeBinding({
|
|
80
89
|
bindingAttrs,
|
|
81
90
|
cache,
|
|
@@ -88,7 +97,7 @@ function applyBinding({ctx, elementCache, updateOption, bindingAttrs, viewModel}
|
|
|
88
97
|
|
|
89
98
|
// apply submit binding
|
|
90
99
|
if (updateOption.submitBinding && elementCache[bindingAttrs.submit] && elementCache[bindingAttrs.submit].length) {
|
|
91
|
-
elementCache[bindingAttrs.submit].forEach((cache) => {
|
|
100
|
+
elementCache[bindingAttrs.submit].forEach((cache: BindingCache) => {
|
|
92
101
|
createEventBinding({
|
|
93
102
|
cache,
|
|
94
103
|
forceRender: updateOption.forceRender,
|
|
@@ -100,7 +109,7 @@ function applyBinding({ctx, elementCache, updateOption, bindingAttrs, viewModel}
|
|
|
100
109
|
|
|
101
110
|
// apply click binding
|
|
102
111
|
if (updateOption.clickBinding && elementCache[bindingAttrs.click] && elementCache[bindingAttrs.click].length) {
|
|
103
|
-
elementCache[bindingAttrs.click].forEach((cache) => {
|
|
112
|
+
elementCache[bindingAttrs.click].forEach((cache: BindingCache) => {
|
|
104
113
|
createEventBinding({
|
|
105
114
|
cache,
|
|
106
115
|
forceRender: updateOption.forceRender,
|
|
@@ -112,7 +121,7 @@ function applyBinding({ctx, elementCache, updateOption, bindingAttrs, viewModel}
|
|
|
112
121
|
|
|
113
122
|
// apply double click binding
|
|
114
123
|
if (updateOption.dblclickBinding && elementCache[bindingAttrs.dblclick] && elementCache[bindingAttrs.dblclick].length) {
|
|
115
|
-
elementCache[bindingAttrs.dblclick].forEach((cache) => {
|
|
124
|
+
elementCache[bindingAttrs.dblclick].forEach((cache: BindingCache) => {
|
|
116
125
|
createEventBinding({
|
|
117
126
|
cache,
|
|
118
127
|
forceRender: updateOption.forceRender,
|
|
@@ -124,7 +133,7 @@ function applyBinding({ctx, elementCache, updateOption, bindingAttrs, viewModel}
|
|
|
124
133
|
|
|
125
134
|
// apply blur binding
|
|
126
135
|
if (updateOption.blurBinding && elementCache[bindingAttrs.blur] && elementCache[bindingAttrs.blur].length) {
|
|
127
|
-
elementCache[bindingAttrs.blur].forEach((cache) => {
|
|
136
|
+
elementCache[bindingAttrs.blur].forEach((cache: BindingCache) => {
|
|
128
137
|
createEventBinding({
|
|
129
138
|
cache,
|
|
130
139
|
forceRender: updateOption.forceRender,
|
|
@@ -136,7 +145,7 @@ function applyBinding({ctx, elementCache, updateOption, bindingAttrs, viewModel}
|
|
|
136
145
|
|
|
137
146
|
// apply focus binding
|
|
138
147
|
if (updateOption.focusBinding && elementCache[bindingAttrs.focus] && elementCache[bindingAttrs.focus].length) {
|
|
139
|
-
elementCache[bindingAttrs.focus].forEach((cache) => {
|
|
148
|
+
elementCache[bindingAttrs.focus].forEach((cache: BindingCache) => {
|
|
140
149
|
createEventBinding({
|
|
141
150
|
cache,
|
|
142
151
|
forceRender: updateOption.forceRender,
|
|
@@ -148,14 +157,14 @@ function applyBinding({ctx, elementCache, updateOption, bindingAttrs, viewModel}
|
|
|
148
157
|
|
|
149
158
|
// apply hover binding
|
|
150
159
|
if (updateOption.hoverBinding && elementCache[bindingAttrs.hover] && elementCache[bindingAttrs.hover].length) {
|
|
151
|
-
elementCache[bindingAttrs.hover].forEach((cache) => {
|
|
160
|
+
elementCache[bindingAttrs.hover].forEach((cache: BindingCache) => {
|
|
152
161
|
hoverBinding(cache, viewModel, bindingAttrs, updateOption.forceRender);
|
|
153
162
|
});
|
|
154
163
|
}
|
|
155
164
|
|
|
156
165
|
// apply input binding - eg html range input
|
|
157
166
|
if (updateOption.inputBinding && elementCache[bindingAttrs.input] && elementCache[bindingAttrs.input].length) {
|
|
158
|
-
elementCache[bindingAttrs.input].forEach((cache) => {
|
|
167
|
+
elementCache[bindingAttrs.input].forEach((cache: BindingCache) => {
|
|
159
168
|
changeBinding({
|
|
160
169
|
bindingAttrs,
|
|
161
170
|
cache,
|
|
@@ -165,6 +174,6 @@ function applyBinding({ctx, elementCache, updateOption, bindingAttrs, viewModel}
|
|
|
165
174
|
});
|
|
166
175
|
});
|
|
167
176
|
}
|
|
168
|
-
}
|
|
177
|
+
};
|
|
169
178
|
|
|
170
179
|
export default applyBinding;
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
parseBindingObjectString,
|
|
8
8
|
each,
|
|
9
9
|
} from './util';
|
|
10
|
+
import type {BindingCache, ViewModel, PlainObject} from './types';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* attrBinding
|
|
@@ -16,7 +17,7 @@ import {
|
|
|
16
17
|
* @param {object} viewModel
|
|
17
18
|
* @param {object} bindingAttrs
|
|
18
19
|
*/
|
|
19
|
-
const attrBinding = (cache = {}, viewModel) => {
|
|
20
|
+
const attrBinding = (cache: BindingCache = {} as BindingCache, viewModel: ViewModel, _bindingAttrs?: unknown, _forceRender?: unknown): void => {
|
|
20
21
|
if (!cache.dataKey) {
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
@@ -46,10 +47,10 @@ const attrBinding = (cache = {}, viewModel) => {
|
|
|
46
47
|
|
|
47
48
|
if (isObjLiteralStr) {
|
|
48
49
|
// resolve each value in vmAttrObj
|
|
49
|
-
each(vmAttrObj, (key, value)=> {
|
|
50
|
+
each(vmAttrObj, (key: string, value: unknown) => {
|
|
50
51
|
// resolve value from viewModel including $data and $root
|
|
51
52
|
// from viewModel.$data or viewModel.$root
|
|
52
|
-
vmAttrObj[key] = getViewModelPropValue(viewModel, {dataKey: value});
|
|
53
|
+
(vmAttrObj as PlainObject)[key] = getViewModelPropValue(viewModel, {dataKey: value, el: cache.el} as BindingCache);
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -58,30 +59,30 @@ const attrBinding = (cache = {}, viewModel) => {
|
|
|
58
59
|
|
|
59
60
|
// start set element attribute - oldAttrObj is empty meaning no previous render
|
|
60
61
|
if (isEmptyObject(oldAttrObj)) {
|
|
61
|
-
each(vmAttrObj, (key, value)=> {
|
|
62
|
+
each(vmAttrObj, (key: string, value: unknown) => {
|
|
62
63
|
if (typeof value !== 'undefined') {
|
|
63
|
-
cache.el.setAttribute(key, value);
|
|
64
|
+
cache.el.setAttribute(key, String(value));
|
|
64
65
|
// populate cache.elementData.viewModelPropValue for future comparison
|
|
65
|
-
if (!isObjLiteralStr) {
|
|
66
|
+
if (!isObjLiteralStr && cache.elementData) {
|
|
66
67
|
cache.elementData.viewModelPropValue[key] = value;
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
});
|
|
70
71
|
} else {
|
|
71
72
|
// loop oldAttrObj, remove attribute not present in current vmAttrObj
|
|
72
|
-
each(oldAttrObj, (key,
|
|
73
|
-
if (typeof vmAttrObj[key] === 'undefined') {
|
|
73
|
+
each(oldAttrObj as PlainObject, (key: string, _value: unknown) => {
|
|
74
|
+
if (typeof (vmAttrObj as PlainObject)[key] === 'undefined') {
|
|
74
75
|
cache.el.removeAttribute(key);
|
|
75
76
|
}
|
|
76
77
|
});
|
|
77
78
|
|
|
78
79
|
// loop vmAttrObj, set attribute not present in oldAttrObj
|
|
79
|
-
each(vmAttrObj, (key, value)=> {
|
|
80
|
+
each(vmAttrObj, (key: string, value: unknown) => {
|
|
80
81
|
if (typeof value !== 'undefined') {
|
|
81
|
-
if (oldAttrObj[key] !== vmAttrObj[key]) {
|
|
82
|
-
cache.el.setAttribute(key, vmAttrObj[key]);
|
|
82
|
+
if ((oldAttrObj as PlainObject)[key] !== (vmAttrObj as PlainObject)[key]) {
|
|
83
|
+
cache.el.setAttribute(key, String((vmAttrObj as PlainObject)[key]));
|
|
83
84
|
// populate cache.elementData.viewModelPropValue for future comparison
|
|
84
|
-
if (!isObjLiteralStr) {
|
|
85
|
+
if (!isObjLiteralStr && cache.elementData) {
|
|
85
86
|
cache.elementData.viewModelPropValue[key] = value;
|
|
86
87
|
}
|
|
87
88
|
}
|
|
@@ -93,7 +94,7 @@ const attrBinding = (cache = {}, viewModel) => {
|
|
|
93
94
|
// set viewModelPropValue for future diff comaprison
|
|
94
95
|
// note: vmAttrObj is a not fully resolve object, each value is still string unresloved
|
|
95
96
|
if (isObjLiteralStr) {
|
|
96
|
-
cache.elementData.viewModelPropValue = extend({}, vmAttrObj);
|
|
97
|
+
cache.elementData.viewModelPropValue = extend(false, {}, vmAttrObj);
|
|
97
98
|
}
|
|
98
99
|
};
|
|
99
100
|
|