From d11f844a42391b1ba49f2fd196671b42fe2f74e1 Mon Sep 17 00:00:00 2001 From: chaksc Date: Wed, 25 Jan 2017 22:18:17 -0800 Subject: [PATCH] Webpack extension sample. --- samples/js-extend-webpack/.editorconfig | 25 + samples/js-extend-webpack/.gitattributes | 1 + samples/js-extend-webpack/.gitignore | 32 + samples/js-extend-webpack/.npmignore | 14 + samples/js-extend-webpack/.yo-rc.json | 7 + samples/js-extend-webpack/README.md | 26 + samples/js-extend-webpack/config/config.json | 13 + .../config/copy-static-assets.json | 5 + .../config/deploy-azure-storage.json | 6 + .../config/package-solution.json | 10 + .../config/prepare-deploy.json | 3 + samples/js-extend-webpack/config/serve.json | 9 + samples/js-extend-webpack/config/tslint.json | 50 ++ .../config/write-manifests.json | 3 + samples/js-extend-webpack/gulpfile.js | 16 + samples/js-extend-webpack/package.json | 29 + samples/js-extend-webpack/src/my-markdown.md | 5 + samples/js-extend-webpack/src/tests.js | 5 + .../IWebpackExampleWebPartProps.ts | 3 + .../webpackExample/WebpackExample.module.scss | 39 ++ .../WebpackExampleWebPart.manifest.json | 20 + .../webpackExample/WebpackExampleWebPart.ts | 43 ++ .../src/webparts/webpackExample/loc/en-us.js | 7 + .../webpackExample/loc/mystrings.d.ts | 10 + .../tests/WebpackExample.test.ts | 9 + samples/js-extend-webpack/tsconfig.json | 13 + .../js-extend-webpack/typings/@ms/odsp.d.ts | 5 + .../assertion-error/assertion-error.d.ts | 15 + .../typings/knockout/knockout.d.ts | 631 ++++++++++++++++++ samples/js-extend-webpack/typings/tsd.d.ts | 3 + 30 files changed, 1057 insertions(+) create mode 100644 samples/js-extend-webpack/.editorconfig create mode 100644 samples/js-extend-webpack/.gitattributes create mode 100644 samples/js-extend-webpack/.gitignore create mode 100644 samples/js-extend-webpack/.npmignore create mode 100644 samples/js-extend-webpack/.yo-rc.json create mode 100644 samples/js-extend-webpack/README.md create mode 100644 samples/js-extend-webpack/config/config.json create mode 100644 samples/js-extend-webpack/config/copy-static-assets.json create mode 100644 samples/js-extend-webpack/config/deploy-azure-storage.json create mode 100644 samples/js-extend-webpack/config/package-solution.json create mode 100644 samples/js-extend-webpack/config/prepare-deploy.json create mode 100644 samples/js-extend-webpack/config/serve.json create mode 100644 samples/js-extend-webpack/config/tslint.json create mode 100644 samples/js-extend-webpack/config/write-manifests.json create mode 100644 samples/js-extend-webpack/gulpfile.js create mode 100644 samples/js-extend-webpack/package.json create mode 100644 samples/js-extend-webpack/src/my-markdown.md create mode 100644 samples/js-extend-webpack/src/tests.js create mode 100644 samples/js-extend-webpack/src/webparts/webpackExample/IWebpackExampleWebPartProps.ts create mode 100644 samples/js-extend-webpack/src/webparts/webpackExample/WebpackExample.module.scss create mode 100644 samples/js-extend-webpack/src/webparts/webpackExample/WebpackExampleWebPart.manifest.json create mode 100644 samples/js-extend-webpack/src/webparts/webpackExample/WebpackExampleWebPart.ts create mode 100644 samples/js-extend-webpack/src/webparts/webpackExample/loc/en-us.js create mode 100644 samples/js-extend-webpack/src/webparts/webpackExample/loc/mystrings.d.ts create mode 100644 samples/js-extend-webpack/src/webparts/webpackExample/tests/WebpackExample.test.ts create mode 100644 samples/js-extend-webpack/tsconfig.json create mode 100644 samples/js-extend-webpack/typings/@ms/odsp.d.ts create mode 100644 samples/js-extend-webpack/typings/assertion-error/assertion-error.d.ts create mode 100644 samples/js-extend-webpack/typings/knockout/knockout.d.ts create mode 100644 samples/js-extend-webpack/typings/tsd.d.ts diff --git a/samples/js-extend-webpack/.editorconfig b/samples/js-extend-webpack/.editorconfig new file mode 100644 index 000000000..8ffcdc4ec --- /dev/null +++ b/samples/js-extend-webpack/.editorconfig @@ -0,0 +1,25 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + + +[*] + +# change these settings to your own preference +indent_style = space +indent_size = 2 + +# we recommend you to keep these unchanged +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[{package,bower}.json] +indent_style = space +indent_size = 2 \ No newline at end of file diff --git a/samples/js-extend-webpack/.gitattributes b/samples/js-extend-webpack/.gitattributes new file mode 100644 index 000000000..212566614 --- /dev/null +++ b/samples/js-extend-webpack/.gitattributes @@ -0,0 +1 @@ +* text=auto \ No newline at end of file diff --git a/samples/js-extend-webpack/.gitignore b/samples/js-extend-webpack/.gitignore new file mode 100644 index 000000000..b19bbe123 --- /dev/null +++ b/samples/js-extend-webpack/.gitignore @@ -0,0 +1,32 @@ +# Logs +logs +*.log +npm-debug.log* + +# Dependency directories +node_modules + +# Build generated files +dist +lib +solution +temp +*.sppkg + +# Coverage directory used by tools like istanbul +coverage + +# OSX +.DS_Store + +# Visual Studio files +.ntvs_analysis.dat +.vs +bin +obj + +# Resx Generated Code +*.resx.ts + +# Styles Generated Code +*.scss.ts diff --git a/samples/js-extend-webpack/.npmignore b/samples/js-extend-webpack/.npmignore new file mode 100644 index 000000000..2c93a9384 --- /dev/null +++ b/samples/js-extend-webpack/.npmignore @@ -0,0 +1,14 @@ +# Folders +.vscode +coverage +node_modules +sharepoint +src +temp + +# Files +*.csproj +.git* +.yo-rc.json +gulpfile.js +tsconfig.json diff --git a/samples/js-extend-webpack/.yo-rc.json b/samples/js-extend-webpack/.yo-rc.json new file mode 100644 index 000000000..2ee0b3496 --- /dev/null +++ b/samples/js-extend-webpack/.yo-rc.json @@ -0,0 +1,7 @@ +{ + "@microsoft/generator-sharepoint": { + "libraryName": "js-extend-webpack", + "libraryId": "c7111d96-6665-4d90-8b74-30a533b8c7b4", + "framework": "none" + } +} \ No newline at end of file diff --git a/samples/js-extend-webpack/README.md b/samples/js-extend-webpack/README.md new file mode 100644 index 000000000..0e2ea212e --- /dev/null +++ b/samples/js-extend-webpack/README.md @@ -0,0 +1,26 @@ +## js-extend-webpack + +This is where you include your web part docs. + +### Building the code + +```bash +git clone the repo +npm i +npm i -g gulp +gulp +``` + +This package produces the following: + +* lib/* commonjs components - this allows this package to be reused from other packages. +* dist/* - a single bundle containing the components used for uploading to a cdn pointing a registered Sharepoint webpart library to. +* example/* a test page that hosts all components in this package. + +### Build options + +gulp clean - TODO +gulp test - TODO +gulp watch - TODO +gulp build - TODO +gulp deploy - TODO diff --git a/samples/js-extend-webpack/config/config.json b/samples/js-extend-webpack/config/config.json new file mode 100644 index 000000000..7cd1f3f3f --- /dev/null +++ b/samples/js-extend-webpack/config/config.json @@ -0,0 +1,13 @@ +{ + "entries": [ + { + "entry": "./lib/webparts/webpackExample/WebpackExampleWebPart.js", + "manifest": "./src/webparts/webpackExample/WebpackExampleWebPart.manifest.json", + "outputPath": "./dist/webpack-example.bundle.js" + } + ], + "externals": {}, + "localizedResources": { + "webpackExampleStrings": "webparts/webpackExample/loc/{locale}.js" + } +} diff --git a/samples/js-extend-webpack/config/copy-static-assets.json b/samples/js-extend-webpack/config/copy-static-assets.json new file mode 100644 index 000000000..010f9a1f4 --- /dev/null +++ b/samples/js-extend-webpack/config/copy-static-assets.json @@ -0,0 +1,5 @@ +{ + "includeExtensions": [ + "md" + ] +} \ No newline at end of file diff --git a/samples/js-extend-webpack/config/deploy-azure-storage.json b/samples/js-extend-webpack/config/deploy-azure-storage.json new file mode 100644 index 000000000..6e582411f --- /dev/null +++ b/samples/js-extend-webpack/config/deploy-azure-storage.json @@ -0,0 +1,6 @@ +{ + "workingDir": "./temp/deploy/", + "account": "", + "container": "js-extend-webpack", + "accessKey": "" +} \ No newline at end of file diff --git a/samples/js-extend-webpack/config/package-solution.json b/samples/js-extend-webpack/config/package-solution.json new file mode 100644 index 000000000..01be9a380 --- /dev/null +++ b/samples/js-extend-webpack/config/package-solution.json @@ -0,0 +1,10 @@ +{ + "solution": { + "name": "js-extend-webpack-client-side-solution", + "id": "c7111d96-6665-4d90-8b74-30a533b8c7b4", + "version": "1.0.0.0" + }, + "paths": { + "zippedPackage": "solution/js-extend-webpack.sppkg" + } +} diff --git a/samples/js-extend-webpack/config/prepare-deploy.json b/samples/js-extend-webpack/config/prepare-deploy.json new file mode 100644 index 000000000..6aca63656 --- /dev/null +++ b/samples/js-extend-webpack/config/prepare-deploy.json @@ -0,0 +1,3 @@ +{ + "deployCdnPath": "temp/deploy" +} diff --git a/samples/js-extend-webpack/config/serve.json b/samples/js-extend-webpack/config/serve.json new file mode 100644 index 000000000..087899637 --- /dev/null +++ b/samples/js-extend-webpack/config/serve.json @@ -0,0 +1,9 @@ +{ + "port": 4321, + "initialPage": "https://localhost:5432/workbench", + "https": true, + "api": { + "port": 5432, + "entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/" + } +} diff --git a/samples/js-extend-webpack/config/tslint.json b/samples/js-extend-webpack/config/tslint.json new file mode 100644 index 000000000..0010b6105 --- /dev/null +++ b/samples/js-extend-webpack/config/tslint.json @@ -0,0 +1,50 @@ +{ + // Display errors as warnings + "displayAsWarning": true, + // The TSLint task may have been configured with several custom lint rules + // before this config file is read (for example lint rules from the tslint-microsoft-contrib + // project). If true, this flag will deactivate any of these rules. + "removeExistingRules": true, + // When true, the TSLint task is configured with some default TSLint "rules.": + "useDefaultConfigAsBase": false, + // Since removeExistingRules=true and useDefaultConfigAsBase=false, there will be no lint rules + // which are active, other than the list of rules below. + "lintConfig": { + // Opt-in to Lint rules which help to eliminate bugs in JavaScript + "rules": { + "class-name": false, + "export-name": false, + "forin": false, + "label-position": false, + "label-undefined": false, + "member-access": true, + "no-arg": false, + "no-console": false, + "no-construct": false, + "no-duplicate-case": true, + "no-duplicate-key": false, + "no-duplicate-variable": true, + "no-eval": false, + "no-function-expression": true, + "no-internal-module": true, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-unnecessary-semicolons": true, + "no-unused-expression": true, + "no-unused-imports": true, + "no-unused-variable": true, + "no-unreachable": true, + "no-use-before-declare": true, + "no-with-statement": true, + "semicolon": true, + "trailing-comma": false, + "typedef": false, + "typedef-whitespace": false, + "use-named-parameter": true, + "valid-typeof": true, + "variable-name": false, + "whitespace": false, + "prefer-const": true + } + } +} \ No newline at end of file diff --git a/samples/js-extend-webpack/config/write-manifests.json b/samples/js-extend-webpack/config/write-manifests.json new file mode 100644 index 000000000..0a4bafb06 --- /dev/null +++ b/samples/js-extend-webpack/config/write-manifests.json @@ -0,0 +1,3 @@ +{ + "cdnBasePath": "" +} \ No newline at end of file diff --git a/samples/js-extend-webpack/gulpfile.js b/samples/js-extend-webpack/gulpfile.js new file mode 100644 index 000000000..03dd3c59d --- /dev/null +++ b/samples/js-extend-webpack/gulpfile.js @@ -0,0 +1,16 @@ +'use strict'; + +const gulp = require('gulp'); +const build = require('@microsoft/sp-build-web'); + +build.configureWebpack.mergeConfig({ + additionalConfiguration: (generatedConfiguration) => { + generatedConfiguration.module.loaders.push([ + { test: /\.md$/, loader: "html!markdown" } + ]); + + return generatedConfiguration; + } +}); + +build.initialize(gulp); diff --git a/samples/js-extend-webpack/package.json b/samples/js-extend-webpack/package.json new file mode 100644 index 000000000..d22bfc7c3 --- /dev/null +++ b/samples/js-extend-webpack/package.json @@ -0,0 +1,29 @@ +{ + "name": "js-extend-webpack", + "version": "0.0.1", + "private": true, + "engines": { + "node": ">=0.10.0" + }, + "dependencies": { + "@microsoft/sp-client-base": "~0.7.0", + "@microsoft/sp-core-library": "~0.1.2", + "@microsoft/sp-webpart-base": "~0.4.0", + "@microsoft/sp-client-preview": "~0.9.0", + "@types/webpack-env": ">=1.12.1 <1.14.0" + }, + "devDependencies": { + "@microsoft/sp-build-web": "~0.9.0", + "@microsoft/sp-module-interfaces": "~0.7.0", + "@microsoft/sp-webpart-workbench": "~0.8.0", + "@types/chai": ">=3.4.34 <3.6.0", + "@types/mocha": ">=2.2.33 <2.6.0", + "gulp": "~3.9.1", + "markdown-loader": "^0.1.7" + }, + "scripts": { + "build": "gulp bundle", + "clean": "gulp clean", + "test": "gulp test" + } +} diff --git a/samples/js-extend-webpack/src/my-markdown.md b/samples/js-extend-webpack/src/my-markdown.md new file mode 100644 index 000000000..fe9500f2d --- /dev/null +++ b/samples/js-extend-webpack/src/my-markdown.md @@ -0,0 +1,5 @@ +# Hello Markdown + +*Markdown* is a simple markup format to write content. + +You can also format text as **bold** or *italics* or ***bold italics***. \ No newline at end of file diff --git a/samples/js-extend-webpack/src/tests.js b/samples/js-extend-webpack/src/tests.js new file mode 100644 index 000000000..cb4bb5cf2 --- /dev/null +++ b/samples/js-extend-webpack/src/tests.js @@ -0,0 +1,5 @@ +var context = require.context('.', true, /.+\.test\.js?$/); + +context.keys().forEach(context); + +module.exports = context; diff --git a/samples/js-extend-webpack/src/webparts/webpackExample/IWebpackExampleWebPartProps.ts b/samples/js-extend-webpack/src/webparts/webpackExample/IWebpackExampleWebPartProps.ts new file mode 100644 index 000000000..ffa373400 --- /dev/null +++ b/samples/js-extend-webpack/src/webparts/webpackExample/IWebpackExampleWebPartProps.ts @@ -0,0 +1,3 @@ +export interface IWebpackExampleWebPartProps { + description: string; +} diff --git a/samples/js-extend-webpack/src/webparts/webpackExample/WebpackExample.module.scss b/samples/js-extend-webpack/src/webparts/webpackExample/WebpackExample.module.scss new file mode 100644 index 000000000..1ed27277a --- /dev/null +++ b/samples/js-extend-webpack/src/webparts/webpackExample/WebpackExample.module.scss @@ -0,0 +1,39 @@ +@import "~/office-ui-fabric-react/dist/sass/Fabric.Common"; + +.row { + @include ms-Grid-row; + @include ms-bgColor-themeDark; + @include ms-fontColor-white; + + box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1); + max-width: 700px; + margin: 0 auto; + padding: 20px; +} + +.column { + @include ms-Grid-col; + @include ms-u-lg10; + @include ms-u-xl8; + @include ms-u-lgPush1; + @include ms-u-xlPush2; +} + +.title { + @include ms-font-xl; + @include ms-fontColor-white; +} + +.subtitle { + @include ms-font-l; + @include ms-fontColor-white; +} + +.description { + @include ms-font-l; + @include ms-fontColor-white; +} + +.button { + text-decoration: none; +} diff --git a/samples/js-extend-webpack/src/webparts/webpackExample/WebpackExampleWebPart.manifest.json b/samples/js-extend-webpack/src/webparts/webpackExample/WebpackExampleWebPart.manifest.json new file mode 100644 index 000000000..9b23a7d65 --- /dev/null +++ b/samples/js-extend-webpack/src/webparts/webpackExample/WebpackExampleWebPart.manifest.json @@ -0,0 +1,20 @@ +{ + "$schema": "../../../node_modules/@microsoft/sp-module-interfaces/lib/manifestSchemas/jsonSchemas/clientSideComponentManifestSchema.json", + + "id": "753c662b-c73a-4755-a1ee-747c9f265513", + "alias": "WebpackExampleWebPart", + "componentType": "WebPart", + "version": "0.0.1", + "manifestVersion": 2, + + "preconfiguredEntries": [{ + "groupId": "753c662b-c73a-4755-a1ee-747c9f265513", + "group": { "default": "Under Development" }, + "title": { "default": "WebpackExample" }, + "description": { "default": "Extend webpack sample" }, + "officeFabricIconFontName": "Page", + "properties": { + "description": "WebpackExample" + } + }] +} diff --git a/samples/js-extend-webpack/src/webparts/webpackExample/WebpackExampleWebPart.ts b/samples/js-extend-webpack/src/webparts/webpackExample/WebpackExampleWebPart.ts new file mode 100644 index 000000000..e0bf4a173 --- /dev/null +++ b/samples/js-extend-webpack/src/webparts/webpackExample/WebpackExampleWebPart.ts @@ -0,0 +1,43 @@ +import { Version } from '@microsoft/sp-core-library'; +import { + BaseClientSideWebPart, + IPropertyPaneConfiguration, + PropertyPaneTextField +} from '@microsoft/sp-webpart-base'; +import * as strings from 'webpackExampleStrings'; +import { IWebpackExampleWebPartProps } from './IWebpackExampleWebPartProps'; + +const strMarkdown = require('../../my-markdown.md') as string; + +export default class WebpackExampleWebPart extends BaseClientSideWebPart { + + public render(): void { + this.domElement.innerHTML = strMarkdown; + } + + protected get dataVersion(): Version { + return Version.parse('1.0'); + } + + protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration { + return { + pages: [ + { + header: { + description: strings.PropertyPaneDescription + }, + groups: [ + { + groupName: strings.BasicGroupName, + groupFields: [ + PropertyPaneTextField('description', { + label: strings.DescriptionFieldLabel + }) + ] + } + ] + } + ] + }; + } +} diff --git a/samples/js-extend-webpack/src/webparts/webpackExample/loc/en-us.js b/samples/js-extend-webpack/src/webparts/webpackExample/loc/en-us.js new file mode 100644 index 000000000..89f98bc1e --- /dev/null +++ b/samples/js-extend-webpack/src/webparts/webpackExample/loc/en-us.js @@ -0,0 +1,7 @@ +define([], function() { + return { + "PropertyPaneDescription": "Description", + "BasicGroupName": "Group Name", + "DescriptionFieldLabel": "Description Field" + } +}); \ No newline at end of file diff --git a/samples/js-extend-webpack/src/webparts/webpackExample/loc/mystrings.d.ts b/samples/js-extend-webpack/src/webparts/webpackExample/loc/mystrings.d.ts new file mode 100644 index 000000000..d2d2c6c82 --- /dev/null +++ b/samples/js-extend-webpack/src/webparts/webpackExample/loc/mystrings.d.ts @@ -0,0 +1,10 @@ +declare interface IWebpackExampleStrings { + PropertyPaneDescription: string; + BasicGroupName: string; + DescriptionFieldLabel: string; +} + +declare module 'webpackExampleStrings' { + const strings: IWebpackExampleStrings; + export = strings; +} diff --git a/samples/js-extend-webpack/src/webparts/webpackExample/tests/WebpackExample.test.ts b/samples/js-extend-webpack/src/webparts/webpackExample/tests/WebpackExample.test.ts new file mode 100644 index 000000000..6719be1a9 --- /dev/null +++ b/samples/js-extend-webpack/src/webparts/webpackExample/tests/WebpackExample.test.ts @@ -0,0 +1,9 @@ +/// + +import { assert } from 'chai'; + +describe('WebpackExampleWebPart', () => { + it('should do something', () => { + assert.ok(true); + }); +}); diff --git a/samples/js-extend-webpack/tsconfig.json b/samples/js-extend-webpack/tsconfig.json new file mode 100644 index 000000000..dadbf6f8f --- /dev/null +++ b/samples/js-extend-webpack/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es5", + "forceConsistentCasingInFileNames": true, + "module": "commonjs", + "jsx": "react", + "declaration": true, + "sourceMap": true, + "types": [ + "webpack-env" + ] + } +} diff --git a/samples/js-extend-webpack/typings/@ms/odsp.d.ts b/samples/js-extend-webpack/typings/@ms/odsp.d.ts new file mode 100644 index 000000000..077127131 --- /dev/null +++ b/samples/js-extend-webpack/typings/@ms/odsp.d.ts @@ -0,0 +1,5 @@ +// Type definitions for Microsoft ODSP projects +// Project: ODSP + +/* Global definition for UNIT_TEST builds */ +declare const UNIT_TEST: boolean; \ No newline at end of file diff --git a/samples/js-extend-webpack/typings/assertion-error/assertion-error.d.ts b/samples/js-extend-webpack/typings/assertion-error/assertion-error.d.ts new file mode 100644 index 000000000..08217c9e5 --- /dev/null +++ b/samples/js-extend-webpack/typings/assertion-error/assertion-error.d.ts @@ -0,0 +1,15 @@ +// Type definitions for assertion-error 1.0.0 +// Project: https://github.com/chaijs/assertion-error +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'assertion-error' { + class AssertionError implements Error { + constructor(message: string, props?: any, ssf?: Function); + name: string; + message: string; + showDiff: boolean; + stack: string; + } + export = AssertionError; +} diff --git a/samples/js-extend-webpack/typings/knockout/knockout.d.ts b/samples/js-extend-webpack/typings/knockout/knockout.d.ts new file mode 100644 index 000000000..267f3174c --- /dev/null +++ b/samples/js-extend-webpack/typings/knockout/knockout.d.ts @@ -0,0 +1,631 @@ +// Type definitions for Knockout v3.2.0 +// Project: http://knockoutjs.com +// Definitions by: Boris Yankov , Igor Oleinikov , Clément Bourgeois +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +interface KnockoutSubscribableFunctions { + [key: string]: KnockoutBindingHandler; + + notifySubscribers(valueToWrite?: T, event?: string): void; +} + +interface KnockoutComputedFunctions { + [key: string]: KnockoutBindingHandler; +} + +interface KnockoutObservableFunctions { + [key: string]: KnockoutBindingHandler; + + equalityComparer(a: any, b: any): boolean; +} + +interface KnockoutObservableArrayFunctions { + // General Array functions + indexOf(searchElement: T, fromIndex?: number): number; + slice(start: number, end?: number): T[]; + splice(start: number): T[]; + splice(start: number, deleteCount: number, ...items: T[]): T[]; + pop(): T; + push(...items: T[]): void; + shift(): T; + unshift(...items: T[]): number; + reverse(): KnockoutObservableArray; + sort(): KnockoutObservableArray; + sort(compareFunction: (left: T, right: T) => number): KnockoutObservableArray; + + // Ko specific + [key: string]: KnockoutBindingHandler; + + replace(oldItem: T, newItem: T): void; + + remove(item: T): T[]; + remove(removeFunction: (item: T) => boolean): T[]; + removeAll(items: T[]): T[]; + removeAll(): T[]; + + destroy(item: T): void; + destroy(destroyFunction: (item: T) => boolean): void; + destroyAll(items: T[]): void; + destroyAll(): void; +} + +interface KnockoutSubscribableStatic { + fn: KnockoutSubscribableFunctions; + + new (): KnockoutSubscribable; +} + +interface KnockoutSubscription { + dispose(): void; +} + +interface KnockoutSubscribable extends KnockoutSubscribableFunctions { + subscribe(callback: (newValue: T) => void, target?: any, event?: string): KnockoutSubscription; + subscribe(callback: (newValue: TEvent) => void, target: any, event: string): KnockoutSubscription; + extend(requestedExtenders: { [key: string]: any; }): KnockoutSubscribable; + getSubscriptionsCount(): number; +} + +interface KnockoutComputedStatic { + fn: KnockoutComputedFunctions; + + (): KnockoutComputed; + (func: () => T, context?: any, options?: any): KnockoutComputed; + (def: KnockoutComputedDefine, context?: any): KnockoutComputed; +} + +interface KnockoutComputed extends KnockoutObservable, KnockoutComputedFunctions { + fn: KnockoutComputedFunctions; + + dispose(): void; + isActive(): boolean; + getDependenciesCount(): number; + extend(requestedExtenders: { [key: string]: any; }): KnockoutComputed; +} + +interface KnockoutObservableArrayStatic { + fn: KnockoutObservableArrayFunctions; + + (value?: T[]): KnockoutObservableArray; +} + +interface KnockoutObservableArray extends KnockoutObservable, KnockoutObservableArrayFunctions { + extend(requestedExtenders: { [key: string]: any; }): KnockoutObservableArray; +} + +interface KnockoutObservableStatic { + fn: KnockoutObservableFunctions; + + (value?: T): KnockoutObservable; +} + +interface KnockoutObservable extends KnockoutSubscribable, KnockoutObservableFunctions { + (): T; + (value: T): void; + + peek(): T; + valueHasMutated?:{(): void;}; + valueWillMutate?:{(): void;}; + extend(requestedExtenders: { [key: string]: any; }): KnockoutObservable; +} + +interface KnockoutComputedDefine { + read(): T; + write? (value: T): void; + disposeWhenNodeIsRemoved?: Node; + disposeWhen? (): boolean; + owner?: any; + deferEvaluation?: boolean; + pure?: boolean; +} + +interface KnockoutBindingContext { + $parent: any; + $parents: any[]; + $root: any; + $data: any; + $rawData: any | KnockoutObservable; + $index?: KnockoutObservable; + $parentContext?: KnockoutBindingContext; + $component: any; + $componentTemplateNodes: Node[]; + + extend(properties: any): any; + createChildContext(dataItemOrAccessor: any, dataItemAlias?: any, extendCallback?: Function): any; +} + +interface KnockoutAllBindingsAccessor { + (): any; + get(name: string): any; + has(name: string): boolean; +} + +interface KnockoutBindingHandler { + after?: Array; + init?: (element: any, valueAccessor: () => any, allBindingsAccessor?: KnockoutAllBindingsAccessor, viewModel?: any, bindingContext?: KnockoutBindingContext) => void | { controlsDescendantBindings: boolean; }; + update?: (element: any, valueAccessor: () => any, allBindingsAccessor?: KnockoutAllBindingsAccessor, viewModel?: any, bindingContext?: KnockoutBindingContext) => void; + options?: any; + preprocess?: (value: string, name: string, addBindingCallback?: (name: string, value: string) => void) => string; +} + +interface KnockoutBindingHandlers { + [bindingHandler: string]: KnockoutBindingHandler; + + // Controlling text and appearance + visible: KnockoutBindingHandler; + text: KnockoutBindingHandler; + html: KnockoutBindingHandler; + css: KnockoutBindingHandler; + style: KnockoutBindingHandler; + attr: KnockoutBindingHandler; + + // Control Flow + foreach: KnockoutBindingHandler; + if: KnockoutBindingHandler; + ifnot: KnockoutBindingHandler; + with: KnockoutBindingHandler; + + // Working with form fields + click: KnockoutBindingHandler; + event: KnockoutBindingHandler; + submit: KnockoutBindingHandler; + enable: KnockoutBindingHandler; + disable: KnockoutBindingHandler; + value: KnockoutBindingHandler; + textInput: KnockoutBindingHandler; + hasfocus: KnockoutBindingHandler; + checked: KnockoutBindingHandler; + options: KnockoutBindingHandler; + selectedOptions: KnockoutBindingHandler; + uniqueName: KnockoutBindingHandler; + + // Rendering templates + template: KnockoutBindingHandler; + + // Components (new for v3.2) + component: KnockoutBindingHandler; +} + +interface KnockoutMemoization { + memoize(callback: () => string): string; + unmemoize(memoId: string, callbackParams: any[]): boolean; + unmemoizeDomNodeAndDescendants(domNode: any, extraCallbackParamsArray: any[]): boolean; + parseMemoText(memoText: string): string; +} + +interface KnockoutVirtualElement {} + +interface KnockoutVirtualElements { + allowedBindings: { [bindingName: string]: boolean; }; + emptyNode(node: KnockoutVirtualElement ): void; + firstChild(node: KnockoutVirtualElement ): KnockoutVirtualElement; + insertAfter( container: KnockoutVirtualElement, nodeToInsert: Node, insertAfter: Node ): void; + nextSibling(node: KnockoutVirtualElement): Node; + prepend(node: KnockoutVirtualElement, toInsert: Node ): void; + setDomNodeChildren(node: KnockoutVirtualElement, newChildren: { length: number;[index: number]: Node; } ): void; + childNodes(node: KnockoutVirtualElement ): Node[]; +} + +interface KnockoutExtenders { + throttle(target: any, timeout: number): KnockoutComputed; + notify(target: any, notifyWhen: string): any; + + rateLimit(target: any, timeout: number): any; + rateLimit(target: any, options: { timeout: number; method?: string; }): any; + + trackArrayChanges(target: any): any; +} + +// +// NOTE TO MAINTAINERS AND CONTRIBUTORS : pay attention to only include symbols that are +// publicly exported in the minified version of ko, without that you can give the false +// impression that some functions will be available in production builds. +// +interface KnockoutUtils { + ////////////////////////////////// + // utils.domData.js + ////////////////////////////////// + + domData: { + get (node: Element, key: string): any; + + set (node: Element, key: string, value: any): void; + + getAll(node: Element, createIfNotFound: boolean): any; + + clear(node: Element): boolean; + }; + + ////////////////////////////////// + // utils.domNodeDisposal.js + ////////////////////////////////// + + domNodeDisposal: { + addDisposeCallback(node: Element, callback: Function): void; + + removeDisposeCallback(node: Element, callback: Function): void; + + cleanNode(node: Node): Element; + + removeNode(node: Node): void; + }; + + addOrRemoveItem(array: T[] | KnockoutObservable, value: T, included: T): void; + + arrayFilter(array: T[], predicate: (item: T) => boolean): T[]; + + arrayFirst(array: T[], predicate: (item: T) => boolean, predicateOwner?: any): T; + + arrayForEach(array: T[], action: (item: T, index: number) => void): void; + + arrayGetDistinctValues(array: T[]): T[]; + + arrayIndexOf(array: T[], item: T): number; + + arrayMap(array: T[], mapping: (item: T) => U): U[]; + + arrayPushAll(array: T[] | KnockoutObservableArray, valuesToPush: T[]): T[]; + + arrayRemoveItem(array: any[], itemToRemove: any): void; + + compareArrays(a: T[], b: T[]): Array>; + + extend(target: Object, source: Object): Object; + + fieldsIncludedWithJsonPost: any[]; + + getFormFields(form: any, fieldName: string): any[]; + + objectForEach(obj: any, action: (key: any, value: any) => void): void; + + parseHtmlFragment(html: string): any[]; + + parseJson(jsonString: string): any; + + postJson(urlOrForm: any, data: any, options: any): void; + + peekObservable(value: KnockoutObservable): T; + + range(min: any, max: any): any; + + registerEventHandler(element: any, eventType: any, handler: Function): void; + + setHtml(node: Element, html: () => string): void; + + setHtml(node: Element, html: string): void; + + setTextContent(element: any, textContent: string | KnockoutObservable): void; + + stringifyJson(data: any, replacer?: Function, space?: string): string; + + toggleDomNodeCssClass(node: any, className: string, shouldHaveClass: boolean): void; + + triggerEvent(element: any, eventType: any): void; + + unwrapObservable(value: KnockoutObservable | T): T; + + // NOT PART OF THE MINIFIED API SURFACE (ONLY IN knockout-{version}.debug.js) https://github.com/SteveSanderson/knockout/issues/670 + // forceRefresh(node: any): void; + // ieVersion: number; + // isIe6: boolean; + // isIe7: boolean; + // jQueryHtmlParse(html: string): any[]; + // makeArray(arrayLikeObject: any): any[]; + // moveCleanedNodesToContainerElement(nodes: any[]): HTMLElement; + // replaceDomNodes(nodeToReplaceOrNodeArray: any, newNodesArray: any[]): void; + // setDomNodeChildren(domNode: any, childNodes: any[]): void; + // setElementName(element: any, name: string): void; + // setOptionNodeSelectionState(optionNode: any, isSelected: boolean): void; + // simpleHtmlParse(html: string): any[]; + // stringStartsWith(str: string, startsWith: string): boolean; + // stringTokenize(str: string, delimiter: string): string[]; + // stringTrim(str: string): string; + // tagNameLower(element: any): string; +} + +interface KnockoutArrayChange { + status: string; + value: T; + index: number; + moved?: number; +} + +////////////////////////////////// +// templateSources.js +////////////////////////////////// + +interface KnockoutTemplateSourcesDomElement { + text(): any; + text(value: any): void; + + data(key: string): any; + data(key: string, value: any): any; +} + +interface KnockoutTemplateAnonymous extends KnockoutTemplateSourcesDomElement { + nodes(): any; + nodes(value: any): void; +} + +interface KnockoutTemplateSources { + + domElement: { + prototype: KnockoutTemplateSourcesDomElement + new (element: Element): KnockoutTemplateSourcesDomElement + }; + + anonymousTemplate: { + prototype: KnockoutTemplateAnonymous; + new (element: Element): KnockoutTemplateAnonymous; + }; +} + +////////////////////////////////// +// nativeTemplateEngine.js +////////////////////////////////// + +interface KnockoutNativeTemplateEngine { + + renderTemplateSource(templateSource: Object, bindingContext?: KnockoutBindingContext, options?: Object): any[]; +} + +////////////////////////////////// +// templateEngine.js +////////////////////////////////// + +interface KnockoutTemplateEngine extends KnockoutNativeTemplateEngine { + + createJavaScriptEvaluatorBlock(script: string): string; + + makeTemplateSource(template: any, templateDocument?: Document): any; + + renderTemplate(template: any, bindingContext: KnockoutBindingContext, options: Object, templateDocument: Document): any; + + isTemplateRewritten(template: any, templateDocument: Document): boolean; + + rewriteTemplate(template: any, rewriterCallback: Function, templateDocument: Document): void; +} + +///////////////////////////////// + +interface KnockoutStatic { + utils: KnockoutUtils; + memoization: KnockoutMemoization; + + bindingHandlers: KnockoutBindingHandlers; + getBindingHandler(handler: string): KnockoutBindingHandler; + + virtualElements: KnockoutVirtualElements; + extenders: KnockoutExtenders; + + applyBindings(viewModelOrBindingContext?: any, rootNode?: any): void; + applyBindingsToDescendants(viewModelOrBindingContext: any, rootNode: any): void; + applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, bindingContext: KnockoutBindingContext): void; + applyBindingAccessorsToNode(node: Node, bindings: {}, bindingContext: KnockoutBindingContext): void; + applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, viewModel: any): void; + applyBindingAccessorsToNode(node: Node, bindings: {}, viewModel: any): void; + applyBindingsToNode(node: Node, bindings: any, viewModelOrBindingContext?: any): any; + + subscribable: KnockoutSubscribableStatic; + observable: KnockoutObservableStatic; + + computed: KnockoutComputedStatic; + pureComputed(evaluatorFunction: () => T, context?: any): KnockoutComputed; + pureComputed(options: KnockoutComputedDefine, context?: any): KnockoutComputed; + + observableArray: KnockoutObservableArrayStatic; + + contextFor(node: any): any; + isSubscribable(instance: any): boolean; + toJSON(viewModel: any, replacer?: Function, space?: any): string; + toJS(viewModel: any): any; + isObservable(instance: any): boolean; + isWriteableObservable(instance: any): boolean; + isComputed(instance: any): boolean; + dataFor(node: any): any; + removeNode(node: Element): void; + cleanNode(node: Element): Element; + renderTemplate(template: Function, viewModel: any, options?: any, target?: any, renderMode?: any): any; + renderTemplate(template: string, viewModel: any, options?: any, target?: any, renderMode?: any): any; + unwrap(value: KnockoutObservable | T): T; + + computedContext: KnockoutComputedContext; + + ////////////////////////////////// + // templateSources.js + ////////////////////////////////// + + templateSources: KnockoutTemplateSources; + + ////////////////////////////////// + // templateEngine.js + ////////////////////////////////// + + templateEngine: { + + prototype: KnockoutTemplateEngine; + + new (): KnockoutTemplateEngine; + }; + + ////////////////////////////////// + // templateRewriting.js + ////////////////////////////////// + + templateRewriting: { + + ensureTemplateIsRewritten(template: Node, templateEngine: KnockoutTemplateEngine, templateDocument: Document): any; + ensureTemplateIsRewritten(template: string, templateEngine: KnockoutTemplateEngine, templateDocument: Document): any; + + memoizeBindingAttributeSyntax(htmlString: string, templateEngine: KnockoutTemplateEngine): any; + + applyMemoizedBindingsToNextSibling(bindings: any, nodeName: string): string; + }; + + ////////////////////////////////// + // nativeTemplateEngine.js + ////////////////////////////////// + + nativeTemplateEngine: { + + prototype: KnockoutNativeTemplateEngine; + + new (): KnockoutNativeTemplateEngine; + + instance: KnockoutNativeTemplateEngine; + }; + + ////////////////////////////////// + // jqueryTmplTemplateEngine.js + ////////////////////////////////// + + jqueryTmplTemplateEngine: { + + prototype: KnockoutTemplateEngine; + + renderTemplateSource(templateSource: Object, bindingContext: KnockoutBindingContext, options: Object): Node[]; + + createJavaScriptEvaluatorBlock(script: string): string; + + addTemplate(templateName: string, templateMarkup: string): void; + }; + + ////////////////////////////////// + // templating.js + ////////////////////////////////// + + setTemplateEngine(templateEngine: KnockoutNativeTemplateEngine): void; + + renderTemplate(template: Function, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any; + renderTemplate(template: any, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any; + renderTemplate(template: Function, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any; + renderTemplate(template: any, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any; + renderTemplate(template: Function, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any; + renderTemplate(template: any, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any; + renderTemplate(template: Function, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any; + renderTemplate(template: any, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any; + + renderTemplateForEach(template: Function, arrayOrObservableArray: any[], options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any; + renderTemplateForEach(template: any, arrayOrObservableArray: any[], options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any; + renderTemplateForEach(template: Function, arrayOrObservableArray: KnockoutObservable, options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any; + renderTemplateForEach(template: any, arrayOrObservableArray: KnockoutObservable, options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any; + + expressionRewriting: { + bindingRewriteValidators: any; + parseObjectLiteral: { (objectLiteralString: string): any[] } + }; + + ///////////////////////////////// + + bindingProvider: { + instance: KnockoutBindingProvider; + new (): KnockoutBindingProvider; + } + + ///////////////////////////////// + // selectExtensions.js + ///////////////////////////////// + + selectExtensions: { + + readValue(element: HTMLElement): any; + + writeValue(element: HTMLElement, value: any): void; + }; + + components: KnockoutComponents; +} + +interface KnockoutBindingProvider { + nodeHasBindings(node: Node): boolean; + getBindings(node: Node, bindingContext: KnockoutBindingContext): {}; + getBindingAccessors?(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string; }; +} + +interface KnockoutComputedContext { + getDependenciesCount(): number; + isInitial: () => boolean; + isSleeping: boolean; +} + +// +// refactored types into a namespace to reduce global pollution +// and used Union Types to simplify overloads (requires TypeScript 1.4) +// +declare module KnockoutComponentTypes { + + interface Config { + viewModel?: ViewModelFunction | ViewModelSharedInstance | ViewModelFactoryFunction | AMDModule; + template: string | Node[]| DocumentFragment | TemplateElement | AMDModule; + synchronous?: boolean; + } + + interface ComponentConfig { + viewModel?: ViewModelFunction | ViewModelSharedInstance | ViewModelFactoryFunction | AMDModule; + template: any; + createViewModel?: any; + } + + interface EmptyConfig { + } + + // common AMD type + interface AMDModule { + require: string; + } + + // viewmodel types + interface ViewModelFunction { + (params?: any): any; + } + + interface ViewModelSharedInstance { + instance: any; + } + + interface ViewModelFactoryFunction { + createViewModel: (params?: any, componentInfo?: ComponentInfo) => any; + } + + interface ComponentInfo { + element: Node; + templateNodes: Node[]; + } + + interface TemplateElement { + element: string | Node; + } + + interface Loader { + getConfig? (componentName: string, callback: (result: ComponentConfig) => void): void; + loadComponent? (componentName: string, config: ComponentConfig, callback: (result: Definition) => void): void; + loadTemplate? (componentName: string, templateConfig: any, callback: (result: Node[]) => void): void; + loadViewModel? (componentName: string, viewModelConfig: any, callback: (result: any) => void): void; + suppressLoaderExceptions?: boolean; + } + + interface Definition { + template: Node[]; + createViewModel? (params: any, options: { element: Node; }): any; + } +} + +interface KnockoutComponents { + // overloads for register method: + register(componentName: string, config: KnockoutComponentTypes.Config | KnockoutComponentTypes.EmptyConfig): void; + + isRegistered(componentName: string): boolean; + unregister(componentName: string): void; + get(componentName: string, callback: (definition: KnockoutComponentTypes.Definition) => void): void; + clearCachedDefinition(componentName: string): void + defaultLoader: KnockoutComponentTypes.Loader; + loaders: KnockoutComponentTypes.Loader[]; + getComponentNameForNode(node: Node): string; +} + +declare var ko: KnockoutStatic; + +declare module "knockout" { + export = ko; +} diff --git a/samples/js-extend-webpack/typings/tsd.d.ts b/samples/js-extend-webpack/typings/tsd.d.ts new file mode 100644 index 000000000..151048618 --- /dev/null +++ b/samples/js-extend-webpack/typings/tsd.d.ts @@ -0,0 +1,3 @@ +/// +/// +///