1 | /*
|
2 | * Copyright 2018 Palantir Technologies, Inc. All rights reserved.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 | /** Returns an instance of a "Create Item" object. */
|
17 | export function getCreateNewItem() {
|
18 | return { __blueprintCreateNewItemBrand: "blueprint-create-new-item" };
|
19 | }
|
20 | /**
|
21 | * Type guard returning `true` if the provided item (e.g. the current
|
22 | * `activeItem`) is a "Create Item" option.
|
23 | */
|
24 | export function isCreateNewItem(item) {
|
25 | if (item == null) {
|
26 | return false;
|
27 | }
|
28 | // see if the provided item exactly matches the `ICreateNewItem` object,
|
29 | // with no superfluous keys.
|
30 | var keys = Object.keys(item);
|
31 | if (keys.length !== 1 || keys[0] !== "__blueprintCreateNewItemBrand") {
|
32 | return false;
|
33 | }
|
34 | return item.__blueprintCreateNewItemBrand === "blueprint-create-new-item";
|
35 | }
|
36 | /**
|
37 | * Returns the type of the the current active item. This will be a no-op unless
|
38 | * the `activeItem` is `undefined` or a "Create Item" option, in which case
|
39 | * `null` will be returned instead.
|
40 | */
|
41 | export function getActiveItem(activeItem) {
|
42 | return activeItem == null || isCreateNewItem(activeItem) ? null : activeItem;
|
43 | }
|
44 | //# sourceMappingURL=listItemsUtils.js.map |
\ | No newline at end of file |