@angular-wave/angular.ts 0.4.3 → 0.4.5

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/src/public.js CHANGED
@@ -1,93 +1,92 @@
1
- import { CompileProvider } from "./core/compile/compile";
1
+ import { CompileProvider } from "./core/compile/compile.js";
2
2
  import {
3
3
  inputDirective,
4
4
  ngValueDirective,
5
5
  hiddenInputBrowserCacheDirective,
6
- } from "./directive/input/input";
7
- import { formDirective, ngFormDirective } from "./directive/form/form";
8
- import { scriptDirective } from "./directive/script/script";
9
- import { selectDirective, optionDirective } from "./directive/select/select";
6
+ } from "./directive/input/input.js";
7
+ import { formDirective, ngFormDirective } from "./directive/form/form.js";
8
+ import { scriptDirective } from "./directive/script/script.js";
9
+ import { selectDirective, optionDirective } from "./directive/select/select.js";
10
10
  import {
11
11
  ngBindDirective,
12
12
  ngBindHtmlDirective,
13
13
  ngBindTemplateDirective,
14
- } from "./directive/bind/bind";
14
+ } from "./directive/bind/bind.js";
15
15
  import {
16
16
  ngClassDirective,
17
17
  ngClassEvenDirective,
18
18
  ngClassOddDirective,
19
- } from "./directive/class/class";
20
- import { ngCloakDirective } from "./directive/cloak/cloak";
21
- import { ngControllerDirective } from "./directive/controller/controller";
19
+ } from "./directive/class/class.js";
20
+ import { ngCloakDirective } from "./directive/cloak/cloak.js";
21
+ import { ngControllerDirective } from "./directive/controller/controller.js";
22
22
  import {
23
23
  ngHideDirective,
24
24
  ngShowDirective,
25
- } from "./directive/show-hide/show-hide";
26
- import { ngIfDirective } from "./directive/if/if";
25
+ } from "./directive/show-hide/show-hide.js";
26
+ import { ngIfDirective } from "./directive/if/if.js";
27
27
  import {
28
28
  ngIncludeDirective,
29
29
  ngIncludeFillContentDirective,
30
- } from "./directive/include/include";
31
- import { ngInitDirective } from "./directive/init/init";
32
- import { ngNonBindableDirective } from "./directive/non-bindable/non-bindable";
33
- import { ngRefDirective } from "./directive/ref/ref";
34
- import { ngRepeatDirective } from "./directive/repeat/repeat";
35
- import { ngStyleDirective } from "./directive/style/style";
30
+ } from "./directive/include/include.js";
31
+ import { ngInitDirective } from "./directive/init/init.js";
32
+ import { ngNonBindableDirective } from "./directive/non-bindable/non-bindable.js";
33
+ import { ngRefDirective } from "./directive/ref/ref.js";
34
+ import { ngRepeatDirective } from "./directive/repeat/repeat.js";
35
+ import { ngStyleDirective } from "./directive/style/style.js";
36
36
  import {
37
37
  ngSwitchDirective,
38
38
  ngSwitchWhenDirective,
39
39
  ngSwitchDefaultDirective,
40
- } from "./directive/switch/switch";
41
- import { ngOptionsDirective } from "./directive/options/options";
42
- import { ngTranscludeDirective } from "./directive/transclude/transclude";
43
- import { ngModelDirective } from "./directive/model/model";
44
- import { ngListDirective } from "./directive/list/list";
45
- import { ngChangeDirective } from "./directive/change/change";
40
+ } from "./directive/switch/switch.js";
41
+ import { ngOptionsDirective } from "./directive/options/options.js";
42
+ import { ngTranscludeDirective } from "./directive/transclude/transclude.js";
43
+ import { ngModelDirective } from "./directive/model/model.js";
44
+ import { ngChangeDirective } from "./directive/change/change.js";
46
45
  import {
47
46
  maxlengthDirective,
48
47
  minlengthDirective,
49
48
  patternDirective,
50
49
  requiredDirective,
51
- } from "./directive/validators/validators";
52
- import { ngModelOptionsDirective } from "./directive/model-options/model-options";
53
- import { ngAttributeAliasDirectives } from "./directive/attrs/attrs";
54
- import { ngEventDirectives } from "./directive/events/events";
55
- import { AnchorScrollProvider } from "./services/anchor-scroll";
56
- import { AnimateProvider } from "./animations/animate";
57
- import { BrowserProvider } from "./services/browser";
50
+ } from "./directive/validators/validators.js";
51
+ import { ngModelOptionsDirective } from "./directive/model-options/model-options.js";
52
+ import { ngAttributeAliasDirectives } from "./directive/attrs/attrs.js";
53
+ import { ngEventDirectives } from "./directive/events/events.js";
54
+ import { AnchorScrollProvider } from "./services/anchor-scroll.js";
55
+ import { AnimateProvider } from "./animations/animate.js";
56
+ import { BrowserProvider } from "./services/browser.js";
58
57
  import {
59
58
  AnimateAsyncRunFactoryProvider,
60
59
  AnimateRunnerFactoryProvider,
61
- } from "./animations/animate-runner";
62
- import { TemplateCacheProvider } from "./core/cache/cache-factory";
63
- import { ControllerProvider } from "./core/controller/controller";
64
- import { ExceptionHandlerProvider } from "./core/exception-handler";
65
- import { FilterProvider } from "./core/filter/filter";
66
- import { IntervalProvider } from "./core/interval/interval";
67
- import { InterpolateProvider } from "./core/interpolate/interpolate";
68
- import { $IntervalFactoryProvider } from "./core/interval/interval-factory";
60
+ } from "./animations/animate-runner.js";
61
+ import { TemplateCacheProvider } from "./core/cache/cache-factory.js";
62
+ import { ControllerProvider } from "./core/controller/controller.js";
63
+ import { ExceptionHandlerProvider } from "./core/exception-handler.js";
64
+ import { FilterProvider } from "./core/filter/filter.js";
65
+ import { IntervalProvider } from "./core/interval/interval.js";
66
+ import { InterpolateProvider } from "./core/interpolate/interpolate.js";
67
+ import { $IntervalFactoryProvider } from "./core/interval/interval-factory.js";
69
68
  import {
70
69
  HttpProvider,
71
70
  HttpParamSerializerProvider,
72
- } from "./services/http/http";
73
- import { HttpBackendProvider } from "./services/http-backend/http-backend";
74
- import { LocationProvider } from "./core/location/location";
75
- import { LogProvider } from "./services/log";
71
+ } from "./services/http/http.js";
72
+ import { HttpBackendProvider } from "./services/http-backend/http-backend.js";
73
+ import { LocationProvider } from "./core/location/location.js";
74
+ import { LogProvider } from "./services/log.js";
76
75
  import { ParseProvider } from "./core/parse/parse.js";
77
- import { RootScopeProvider } from "./core/scope/scope";
78
- import { $QProvider } from "./core/q/q";
79
- import { SceProvider, SceDelegateProvider } from "./core/sce/sce";
80
- import { TaskTrackerFactoryProvider } from "./core/task-tracker-factory";
81
- import { TemplateRequestProvider } from "./services/template-request";
82
- import { TimeoutProvider } from "./core/timeout/timeout";
83
- import { SanitizeUriProvider } from "./core/sanitize/sanitize-uri";
76
+ import { RootScopeProvider } from "./core/scope/scope.js";
77
+ import { $QProvider } from "./core/q/q.js";
78
+ import { SceProvider, SceDelegateProvider } from "./core/sce/sce.js";
79
+ import { TaskTrackerFactoryProvider } from "./core/task-tracker-factory.js";
80
+ import { TemplateRequestProvider } from "./services/template-request.js";
81
+ import { TimeoutProvider } from "./core/timeout/timeout.js";
82
+ import { SanitizeUriProvider } from "./core/sanitize/sanitize-uri.js";
84
83
  import {
85
84
  ngMessageDefaultDirective,
86
85
  ngMessageDirective,
87
86
  ngMessageExpDirective,
88
87
  ngMessagesDirective,
89
88
  ngMessagesIncludeDirective,
90
- } from "./directive/messages/messages";
89
+ } from "./directive/messages/messages.js";
91
90
  import {
92
91
  AriaProvider,
93
92
  ngCheckedAriaDirective,
@@ -101,34 +100,38 @@ import {
101
100
  ngRequiredAriaDirective,
102
101
  ngShowAriaDirective,
103
102
  ngValueAriaDirective,
104
- } from "./directive/aria/aria";
105
- import { AnimateCssProvider } from "./animations/animate-css";
106
- import { AnimateQueueProvider } from "./animations/animate-queue";
107
- import { AnimateJsProvider } from "./animations/animate-js";
108
- import { AnimationProvider } from "./animations/animation";
109
- import { RafSchedulerProvider } from "./animations/raf-scheduler";
110
- import { AnimateCacheProvider } from "./animations/animate-cache";
111
- import { AnimateCssDriverProvider } from "./animations/animate-css-driver";
112
- import { AnimateJsDriverProvider } from "./animations/animate-js-driver";
113
- import { ngAnimateSwapDirective } from "./animations/animate-swap";
114
- import { $$AnimateChildrenDirective } from "./animations/animate-children-directive";
115
- import { UrlConfigProvider } from "./router/url/url-config";
116
- import { UIRouterGlobals } from "./router/globals";
117
- import { ViewService } from "./router/view/view";
118
- import { TransitionProvider } from "./router/transition/transition-service";
119
- import { StateProvider } from "./router/state/state-service";
120
- import { ViewScrollProvider } from "./router/view-scroll";
121
- import { TemplateFactoryProvider } from "./router/template-factory";
122
- import { UrlService } from "./router/url/url-service";
123
- import { StateRegistryProvider } from "./router/state/state-registry";
124
- import { trace } from "./router/common/trace";
103
+ } from "./directive/aria/aria.js";
104
+ import { AnimateCssProvider } from "./animations/animate-css.js";
105
+ import { AnimateQueueProvider } from "./animations/animate-queue.js";
106
+ import { AnimateJsProvider } from "./animations/animate-js.js";
107
+ import { AnimationProvider } from "./animations/animation.js";
108
+ import { RafSchedulerProvider } from "./animations/raf-scheduler.js";
109
+ import { AnimateCacheProvider } from "./animations/animate-cache.js";
110
+ import { AnimateCssDriverProvider } from "./animations/animate-css-driver.js";
111
+ import { AnimateJsDriverProvider } from "./animations/animate-js-driver.js";
112
+ import { ngAnimateSwapDirective } from "./animations/animate-swap.js";
113
+ import { $$AnimateChildrenDirective } from "./animations/animate-children-directive.js";
114
+ import { UrlConfigProvider } from "./router/url/url-config.js";
115
+ import { UIRouterGlobals } from "./router/globals.js";
116
+ import { ViewService } from "./router/view/view.js";
117
+ import { TransitionProvider } from "./router/transition/transition-service.js";
118
+ import { StateProvider } from "./router/state/state-service.js";
119
+ import { ViewScrollProvider } from "./router/view-scroll.js";
120
+ import { TemplateFactoryProvider } from "./router/template-factory.js";
121
+ import { UrlService } from "./router/url/url-service.js";
122
+ import { StateRegistryProvider } from "./router/state/state-registry.js";
123
+ import { trace } from "./router/common/trace.js";
125
124
  import {
126
125
  $StateRefActiveDirective,
127
126
  $StateRefDirective,
128
127
  $StateRefDynamicDirective,
129
- } from "./router/directives/state-directives";
130
- import { $ViewDirectiveFill, ngView } from "./router/directives/view-directive";
131
- import { ngObserveDirective } from "./directive/observe/observe";
128
+ } from "./router/directives/state-directives.js";
129
+ import {
130
+ $ViewDirectiveFill,
131
+ ngView,
132
+ } from "./router/directives/view-directive.js";
133
+ import { ngObserveDirective } from "./directive/observe/observe.js";
134
+ import { ngChannelDirective } from "./directive/channel/channel.js";
132
135
 
133
136
  /**
134
137
  * @type {string} `version` from `package.json`, injected by Rollup plugin
@@ -192,7 +195,6 @@ export function publishExternalAPI(angular) {
192
195
  ngOptions: ngOptionsDirective,
193
196
  ngTransclude: ngTranscludeDirective,
194
197
  ngModel: ngModelDirective,
195
- ngList: ngListDirective,
196
198
  ngChange: ngChangeDirective,
197
199
  pattern: patternDirective,
198
200
  ngPattern: patternDirective,
@@ -225,6 +227,7 @@ export function publishExternalAPI(angular) {
225
227
  ngSrefActiveEq: $StateRefActiveDirective,
226
228
  ngState: $StateRefDynamicDirective,
227
229
  ngView: ngView,
230
+ ngChannel: ngChannelDirective,
228
231
  })
229
232
  .directive({
230
233
  ngView: $ViewDirectiveFill,
@@ -1,6 +1,6 @@
1
1
  import { test, expect } from "@playwright/test";
2
2
 
3
- const TEST_URL = "src/router/state/state.html";
3
+ const TEST_URL = "src/router/state/state.html?random=false";
4
4
 
5
5
  test("unit tests contain no errors", async ({ page }) => {
6
6
  await page.goto(TEST_URL);
@@ -110,15 +110,12 @@ export class Browser {
110
110
  * @private
111
111
  */
112
112
  cacheState() {
113
- this.cachedState = history.state;
114
- this.cachedState = this.cachedState === undefined ? null : this.cachedState;
115
-
116
- if (equals(this.cachedState, this.lastCachedState)) {
117
- this.cachedState = this.lastCachedState;
113
+ const currentState = history.state ?? null;
114
+ if (!equals(currentState, this.lastCachedState)) {
115
+ this.cachedState = currentState;
116
+ this.lastCachedState = currentState;
117
+ this.lastHistoryState = currentState;
118
118
  }
119
-
120
- this.lastCachedState = this.cachedState;
121
- this.lastHistoryState = this.cachedState;
122
119
  }
123
120
 
124
121
  /**
@@ -1095,9 +1095,6 @@ function createEventHandler(element, events) {
1095
1095
  }
1096
1096
  };
1097
1097
 
1098
- // TODO: this is a hack for angularMocks/clearDataCache that makes it possible to deregister all
1099
- // events on `element`
1100
- eventHandler.elem = element;
1101
1098
  return eventHandler;
1102
1099
  }
1103
1100
 
@@ -6,7 +6,7 @@
6
6
  * @property {?Function} handle
7
7
  *
8
8
  */
9
- export const EXPANDO: "ngId";
9
+ export const EXPANDO: "ng";
10
10
  /**
11
11
  * Expando cache for adding properties to DOM nodes with JavaScript.
12
12
  * This used to be an Object in JQLite decorator, but swapped out for a Map
@@ -1,34 +1,3 @@
1
- export function LocationProvider(): void;
2
- export class LocationProvider {
3
- /**
4
- * The default value for the prefix is `'!'`.
5
- * @param {string=} prefix Prefix for hash part (containing path and search)
6
- * @returns {*} current value if used as getter or itself (chaining) if used as setter
7
- */
8
- hashPrefix: (prefix?: string | undefined) => any;
9
- /**
10
- * @param {(boolean|Object)=} mode If boolean, sets `html5Mode.enabled` to value.
11
- * If object, sets `enabled`, `requireBase` and `rewriteLinks` to respective values. Supported
12
- * properties:
13
- * - **enabled** – `{boolean}` – (default: false) If true, will rely on `history.pushState` to
14
- * change urls where supported. Will fall back to hash-prefixed paths in browsers that do not
15
- * support `pushState`.
16
- * - **requireBase** - `{boolean}` - (default: `true`) When html5Mode is enabled, specifies
17
- * whether or not a <base> tag is required to be present. If `enabled` and `requireBase` are
18
- * true, and a base tag is not present, an error will be thrown when `$location` is injected.
19
- * See the {@link guide/$location $location guide for more information}
20
- * - **rewriteLinks** - `{boolean|string}` - (default: `true`) When html5Mode is enabled,
21
- * enables/disables URL rewriting for relative links. If set to a string, URL rewriting will
22
- * only happen on links with an attribute that matches the given string. For example, if set
23
- * to `'internal-link'`, then the URL will only be rewritten for `<a internal-link>` links.
24
- * Note that [attribute name normalization](guide/directive#normalization) does not apply
25
- * here, so `'internalLink'` will **not** match `'internal-link'`.
26
- *
27
- * @returns {Object} html5Mode object if used as getter or itself (chaining) if used as setter
28
- */
29
- html5Mode: (mode?: (boolean | any) | undefined) => any;
30
- $get: (string | (($rootScope: import("../scope/scope").Scope, $browser: import("../../services/browser").Browser, $rootElement: JQLite) => Location))[];
31
- }
32
1
  /**
33
2
  *
34
3
  * @param {string} base
@@ -276,6 +245,42 @@ export class LocationHashbangUrl extends Location {
276
245
  */
277
246
  $$parseLinkUrl(url: string): boolean;
278
247
  }
248
+ export class LocationProvider {
249
+ hashPrefixValue: string;
250
+ html5ModeConfig: {
251
+ enabled: boolean;
252
+ requireBase: boolean;
253
+ rewriteLinks: boolean;
254
+ };
255
+ /**
256
+ * The default value for the prefix is `'!'`.
257
+ * @param {string=} prefix - Prefix for hash part (containing path and search)
258
+ * @returns {string|LocationProvider} current value if used as getter or itself (chaining) if used as setter
259
+ */
260
+ hashPrefix(prefix?: string | undefined): string | LocationProvider;
261
+ /**
262
+ * @param {(boolean|Object)=} mode If boolean, sets `html5Mode.enabled` to value.
263
+ * If object, sets `enabled`, `requireBase` and `rewriteLinks` to respective values. Supported
264
+ * properties:
265
+ * - **enabled** – `{boolean}` – (default: false) If true, will rely on `history.pushState` to
266
+ * change urls where supported. Will fall back to hash-prefixed paths in browsers that do not
267
+ * support `pushState`.
268
+ * - **requireBase** - `{boolean}` - (default: `true`) When html5Mode is enabled, specifies
269
+ * whether or not a <base> tag is required to be present. If `enabled` and `requireBase` are
270
+ * true, and a base tag is not present, an error will be thrown when `$location` is injected.
271
+ * See the {@link guide/$location $location guide for more information}
272
+ * - **rewriteLinks** - `{boolean|string}` - (default: `true`) When html5Mode is enabled,
273
+ * enables/disables URL rewriting for relative links. If set to a string, URL rewriting will
274
+ * only happen on links with an attribute that matches the given string. For example, if set
275
+ * to `'internal-link'`, then the URL will only be rewritten for `<a internal-link>` links.
276
+ * Note that [attribute name normalization](guide/directive#normalization) does not apply
277
+ * here, so `'internalLink'` will **not** match `'internal-link'`.
278
+ *
279
+ * @returns {Object} html5Mode object if used as getter or itself (chaining) if used as setter
280
+ */
281
+ html5Mode(mode?: (boolean | any) | undefined): any;
282
+ $get: (string | (($rootScope: import("../scope/scope").Scope, $browser: import("../../services/browser").Browser, $rootElement: JQLite) => Location))[];
283
+ }
279
284
  export type DefaultPorts = {
280
285
  http: number;
281
286
  https: number;
@@ -158,10 +158,6 @@ export class Scope {
158
158
  /** @type {number} */
159
159
  $$watchersCount: number;
160
160
  $$isolateBindings: any;
161
- /**
162
- * @type {?Scope}
163
- */
164
- $$ChildScope: Scope | null;
165
161
  /**
166
162
  * Creates a new child {@link Scope}.
167
163
  *
@@ -177,16 +173,21 @@ export class Scope {
177
173
  * When creating widgets, it is useful for the widget to not accidentally read parent
178
174
  * state.
179
175
  *
180
- * @param {?Scope} [parent=this] The {@link ng.$rootScope.Scope `Scope`} that will be the `$parent`
181
- * of the newly created scope. Defaults to `this` scope if not provided.
182
- * This is used when creating a transclude scope to correctly place it
183
- * in the scope hierarchy while maintaining the correct prototypical
184
- * inheritance.
185
176
  *
186
177
  * @returns {Scope} The newly created child scope.
187
178
  *
188
179
  */
189
- $new(isolate: boolean | null, parent?: Scope | null): Scope;
180
+ $new(isolate: boolean | null): Scope;
181
+ /**
182
+ * Creates a transcluded scope
183
+ * @param {Scope} parent The {@link ng.$rootScope.Scope `Scope`} that will be the `$parent`
184
+ * of the newly created scope. This is used when creating a transclude scope to correctly place it
185
+ * in the scope hierarchy while maintaining the correct prototypical inheritance.
186
+ *
187
+ * @returns {Scope} The newly created child scope.
188
+ *
189
+ */
190
+ $transcluded(parent: Scope): Scope;
190
191
  /**
191
192
  * Registers a `listener` callback to be executed whenever the `watchExpression` changes.
192
193
  *
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Dynamically updates an element's content based on events published on a specified channel.
3
+ * When the directive is applied, it listens for data sent via `EventBus` and
4
+ * updates the inner HTML of the element accordingly.
5
+ *
6
+ * When the scope is destroyed, the directive automatically unsubscribes from the channel.
7
+ *
8
+ *
9
+ * @returns {import("../../types").Directive}
10
+ */
11
+ export function ngChannelDirective(): import("../../types").Directive;
@@ -1,46 +0,0 @@
1
- import { isUndefined, trim } from "../../shared/utils";
2
-
3
- /**
4
- * @returns {import('../../types').Directive}
5
- */
6
- export function ngListDirective() {
7
- return {
8
- restrict: "A",
9
- priority: 100,
10
- require: "ngModel",
11
- link(_scope, _element, attr, ctrl) {
12
- const ngList = attr.ngList || ", ";
13
- const trimValues = attr.ngTrim !== "false";
14
- const separator = trimValues ? trim(ngList) : ngList;
15
-
16
- const parse = function (viewValue) {
17
- // If the viewValue is invalid (say required but empty) it will be `undefined`
18
- if (isUndefined(viewValue)) return;
19
-
20
- const list = [];
21
-
22
- if (viewValue) {
23
- viewValue.split(separator).forEach((value) => {
24
- if (value) list.push(trimValues ? trim(value) : value);
25
- });
26
- }
27
-
28
- return list;
29
- };
30
-
31
- ctrl["$parsers"].push(parse);
32
- ctrl["$formatters"].push((value) => {
33
- if (Array.isArray(value)) {
34
- return value.join(ngList);
35
- }
36
-
37
- return undefined;
38
- });
39
-
40
- // Override the standard $isEmpty because an empty array means the input is empty.
41
- ctrl["$isEmpty"] = function (value) {
42
- return !value || !value.length;
43
- };
44
- },
45
- };
46
- }
@@ -1,22 +0,0 @@
1
- ## `ngList` Directive
2
-
3
- ### Restrict
4
-
5
- `A`
6
-
7
- ### Priority
8
-
9
- 100
10
-
11
- ### Parameter
12
-
13
- - `{string=} ngList`: Optional delimiter that should be used to split the value.
14
-
15
- ### Description
16
-
17
- Text input that converts between a delimited string and an array of strings. The default delimiter is a comma followed by a space - equivalent to `ng-list=", "`. You can specify a custom delimiter as the value of the `ngList` attribute - for example, `ng-list=" | "`.
18
-
19
- The behavior of the directive is affected by the use of the `ngTrim` attribute.
20
-
21
- - If `ngTrim` is set to `"false"` then whitespace around both the separator and each list item is respected. This implies that the user of the directive is responsible for dealing with whitespace but also allows you to use whitespace as a delimiter, such as a tab or newline character.
22
- - Otherwise, whitespace around the delimiter is ignored when splitting (although it is respected when joining the list items back together) and whitespace around each list item is stripped before it is added to the model.
@@ -1,172 +0,0 @@
1
- import { dealoc } from "../../shared/jqlite/jqlite";
2
- import { Angular } from "../../loader";
3
-
4
- describe("ngList", () => {
5
- let $rootScope;
6
- let element;
7
- let $compile;
8
- let injector;
9
- let inputElm;
10
-
11
- beforeEach(() => {
12
- window.angular = new Angular();
13
- window.angular.module("test", []);
14
- injector = window.angular.bootstrap(document.getElementById("dummy"), [
15
- "test",
16
- ]);
17
- $compile = injector.get("$compile");
18
- $rootScope = injector.get("$rootScope");
19
- });
20
-
21
- afterEach(() => {
22
- dealoc(element);
23
- });
24
-
25
- function changeInputValue(val) {
26
- inputElm[0].value = val;
27
- inputElm[0].dispatchEvent(new Event("change"));
28
- }
29
-
30
- it("should parse text into an array", () => {
31
- inputElm = $compile('<input type="text" ng-model="list" ng-list />')(
32
- $rootScope,
33
- );
34
-
35
- // model -> view
36
- $rootScope.$apply("list = ['x', 'y', 'z']");
37
- expect(inputElm.val()).toBe("x, y, z");
38
-
39
- // view -> model
40
- changeInputValue("1, 2, 3");
41
- expect($rootScope.list).toEqual(["1", "2", "3"]);
42
- });
43
-
44
- it("should not clobber text if model changes due to itself", () => {
45
- // When the user types 'a,b' the 'a,' stage parses to ['a'] but if the
46
- // $parseModel function runs it will change to 'a', in essence preventing
47
- // the user from ever typing ','.
48
- inputElm = $compile('<input type="text" ng-model="list" ng-list />')(
49
- $rootScope,
50
- );
51
-
52
- changeInputValue("a ");
53
- expect(inputElm.val()).toEqual("a ");
54
- expect($rootScope.list).toEqual(["a"]);
55
-
56
- changeInputValue("a ,");
57
- expect(inputElm.val()).toEqual("a ,");
58
- expect($rootScope.list).toEqual(["a"]);
59
-
60
- changeInputValue("a , ");
61
- expect(inputElm.val()).toEqual("a , ");
62
- expect($rootScope.list).toEqual(["a"]);
63
-
64
- changeInputValue("a , b");
65
- expect(inputElm.val()).toEqual("a , b");
66
- expect($rootScope.list).toEqual(["a", "b"]);
67
- });
68
-
69
- it("should convert empty string to an empty array", () => {
70
- inputElm = $compile('<input type="text" ng-model="list" ng-list />')(
71
- $rootScope,
72
- );
73
-
74
- changeInputValue("");
75
- expect($rootScope.list).toEqual([]);
76
- });
77
-
78
- it("should be invalid if required and empty", () => {
79
- inputElm = $compile('<input type="text" ng-list ng-model="list" required>')(
80
- $rootScope,
81
- );
82
- changeInputValue("");
83
- expect($rootScope.list).toBeUndefined();
84
- expect(inputElm[0].classList.contains("ng-invalid")).toBeTrue();
85
- changeInputValue("a,b");
86
- expect($rootScope.list).toEqual(["a", "b"]);
87
- expect(inputElm[0].classList.contains("ng-valid")).toBeTrue();
88
- });
89
-
90
- describe("with a custom separator", () => {
91
- it("should split on the custom separator", () => {
92
- inputElm = $compile('<input type="text" ng-model="list" ng-list=":" />')(
93
- $rootScope,
94
- );
95
-
96
- changeInputValue("a,a");
97
- expect($rootScope.list).toEqual(["a,a"]);
98
-
99
- changeInputValue("a:b");
100
- expect($rootScope.list).toEqual(["a", "b"]);
101
- });
102
-
103
- it("should join the list back together with the custom separator", () => {
104
- inputElm = $compile(
105
- '<input type="text" ng-model="list" ng-list=" : " />',
106
- )($rootScope);
107
-
108
- $rootScope.$apply(() => {
109
- $rootScope.list = ["x", "y", "z"];
110
- });
111
- expect(inputElm.val()).toBe("x : y : z");
112
- });
113
- });
114
-
115
- describe("(with ngTrim undefined or true)", () => {
116
- it("should ignore separator whitespace when splitting", () => {
117
- inputElm = $compile(
118
- '<input type="text" ng-model="list" ng-list=" | " />',
119
- )($rootScope);
120
-
121
- changeInputValue("a|b");
122
- expect($rootScope.list).toEqual(["a", "b"]);
123
- });
124
-
125
- it("should trim whitespace from each list item", () => {
126
- inputElm = $compile('<input type="text" ng-model="list" ng-list="|" />')(
127
- $rootScope,
128
- );
129
-
130
- changeInputValue("a | b");
131
- expect($rootScope.list).toEqual(["a", "b"]);
132
- });
133
- });
134
-
135
- describe("(with ngTrim set to false)", () => {
136
- it("should use separator whitespace when splitting", () => {
137
- inputElm = $compile(
138
- '<input type="text" ng-model="list" ng-trim="false" ng-list=" | " />',
139
- )($rootScope);
140
-
141
- changeInputValue("a|b");
142
- expect($rootScope.list).toEqual(["a|b"]);
143
-
144
- changeInputValue("a | b");
145
- expect($rootScope.list).toEqual(["a", "b"]);
146
- });
147
-
148
- it("should not trim whitespace from each list item", () => {
149
- inputElm = $compile(
150
- '<input type="text" ng-model="list" ng-trim="false" ng-list="|" />',
151
- )($rootScope);
152
- changeInputValue("a | b");
153
- expect($rootScope.list).toEqual(["a ", " b"]);
154
- });
155
-
156
- it("should support splitting on newlines", () => {
157
- inputElm = $compile(
158
- '<textarea type="text" ng-model="list" ng-trim="false" ng-list="&#10;"></textarea>',
159
- )($rootScope);
160
- changeInputValue("a\nb");
161
- expect($rootScope.list).toEqual(["a", "b"]);
162
- });
163
-
164
- it("should support splitting on whitespace", () => {
165
- inputElm = $compile(
166
- '<textarea type="text" ng-model="list" ng-trim="false" ng-list=" "></textarea>',
167
- )($rootScope);
168
- changeInputValue("a b");
169
- expect($rootScope.list).toEqual(["a", "b"]);
170
- });
171
- });
172
- });
@@ -1,4 +0,0 @@
1
- /**
2
- * @returns {import('../../types').Directive}
3
- */
4
- export function ngListDirective(): import("../../types").Directive;