mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-29 13:26:59 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
627d35fd0a | ||
|
|
ac5bb205aa | ||
|
|
3386e609a8 | ||
|
|
847c651c2b | ||
|
|
f66cba1816 | ||
|
|
2583effe5e | ||
|
|
2e1e5d5d44 | ||
|
|
6c1bcbdb7d | ||
|
|
c5e29ce638 | ||
|
|
7512b6436b | ||
|
|
1b362a366c | ||
|
|
1a8301b0cc | ||
|
|
79c64e5777 | ||
|
|
8ba0a2caee | ||
|
|
904d6bca55 | ||
|
|
94f4770731 | ||
|
|
fa0e243bf1 | ||
|
|
c7bb67f2ef | ||
|
|
2d1a355b23 | ||
|
|
b606e8f87a | ||
|
|
98fc4a41eb | ||
|
|
7836694b53 | ||
|
|
0866527ea0 | ||
|
|
c1b87080f1 | ||
|
|
b2e9ed2392 | ||
|
|
75548a1c04 | ||
|
|
900b03de1d | ||
|
|
cc0e88598f | ||
|
|
078186cd25 | ||
|
|
b55a4c6c61 | ||
|
|
4dad63ea90 | ||
|
|
6335169e9a | ||
|
|
1bf6db0809 | ||
|
|
4b53d920c7 | ||
|
|
fa3406a809 | ||
|
|
46c0adb62c | ||
|
|
d18170337d | ||
|
|
9c7238d578 | ||
|
|
1a63761e43 | ||
|
|
9c6bb48c7a | ||
|
|
2173ad7c71 | ||
|
|
b8db6c6a90 | ||
|
|
62f0337198 | ||
|
|
eb89496733 | ||
|
|
5d6e070e01 | ||
|
|
ae31f9737f | ||
|
|
6e42537aa1 | ||
|
|
2b14076171 | ||
|
|
55ac8681af | ||
|
|
b5d2615307 | ||
|
|
6742ec84cf | ||
|
|
61d735662e | ||
|
|
050b89f82f | ||
|
|
1b179a603a | ||
|
|
4a6382aa7f | ||
|
|
f0c44c5719 | ||
|
|
2c2076bf69 | ||
|
|
5a67fec99e | ||
|
|
7cadd5fba4 | ||
|
|
6b59844084 |
@@ -0,0 +1,11 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
||||
@@ -0,0 +1,29 @@
|
||||
name: Build CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
container:
|
||||
image: ghcr.io/pebble-dev/pebbleos-docker:v1
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up uv
|
||||
uses: astral-sh/setup-uv@v7
|
||||
- run: uv tool install pebble-tool
|
||||
- run: npm install
|
||||
- run: npm run build
|
||||
- run: pebble build
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: clay
|
||||
path: dist.zip
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
name: Lint CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: 'npm'
|
||||
- run: npm install
|
||||
- run: npm run lint
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
name: Node.js Package
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
publish-npm:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
container:
|
||||
image: ghcr.io/pebble-dev/pebbleos-docker:v1
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up uv
|
||||
uses: astral-sh/setup-uv@v7
|
||||
- run: uv tool install pebble-tool
|
||||
- run: npm install
|
||||
- run: npm run build
|
||||
- run: pebble sdk install 4.9.127
|
||||
- run: pebble build
|
||||
- name: Update npm
|
||||
run: npm install -g npm@next-11
|
||||
- run: npm publish
|
||||
@@ -0,0 +1,34 @@
|
||||
name: Test CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: 'npm'
|
||||
- name: Setup Chrome
|
||||
uses: browser-actions/setup-chrome@v2
|
||||
id: setup-chrome
|
||||
with:
|
||||
install-dependencies: true
|
||||
- run: npm install
|
||||
- run: npm run build
|
||||
- name: Run headless test
|
||||
uses: coactions/setup-xvfb@v1
|
||||
with:
|
||||
run: npm run test-travis
|
||||
env:
|
||||
CHROME_BIN: ${{ steps.setup-chrome.outputs.chrome-path }}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
name: Typecheck CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
typecheck:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: 'npm'
|
||||
- run: npm install
|
||||
- run: npm run check:types
|
||||
+3
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
/.lock-waf_darwin_build
|
||||
/.lock-waf_*_build
|
||||
|
||||
# Dependency directory
|
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||
@@ -13,4 +13,6 @@
|
||||
/tmp/
|
||||
/src/js/index.js
|
||||
/dist.zip
|
||||
/dist/
|
||||
/build/
|
||||
/dist-types/
|
||||
|
||||
@@ -3,3 +3,4 @@
|
||||
!/dist.zip
|
||||
!/src/**/*
|
||||
!/index.js
|
||||
!/index.d.ts
|
||||
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
language: node_js
|
||||
sudo: false
|
||||
node_js:
|
||||
- '4'
|
||||
|
||||
before_script:
|
||||
# Needed to include Chrome in Travis for karma tests
|
||||
- export CHROME_BIN=chromium-browser
|
||||
- export DISPLAY=:99.0
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
|
||||
script: 'npm run test-travis'
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
# Contributing
|
||||
|
||||
Thanks for checking out Clay. We accept pull requests from anybody, however we ask
|
||||
that you follow some conventions when contributing to Clay.
|
||||
|
||||
We have set up a
|
||||
[piece-of-cake](https://github.com/pebble-dev/clay/issues?q=is%3Aopen+is%3Aissue+label%3Apiece-of-cake)
|
||||
label in GitHub issues for bugs/features that are easy to implement. These issues are
|
||||
a great place to start for people that are new to the codebase.
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
- [Node](https://nodejs.org) (4.0 and later)
|
||||
- [Google Chrome](www.google.com/chrome) (To run tests)
|
||||
- [Pebble SDK](https://developer.rebble.io/sdk/) (optional)
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
### 1. Fork, then clone the repo:
|
||||
|
||||
`$ git clone git@github.com:your-username/clay.git`
|
||||
|
||||
### 2. Create a new branch with the following naming convention.
|
||||
|
||||
`#<issue-id>/description-of-change`
|
||||
|
||||
example:
|
||||
|
||||
`#90/support-message-keys`
|
||||
|
||||
If there is currently no GitHub issue open for your proposed contribution,
|
||||
then please make one. This allows us to assign milestones and triage priority.
|
||||
|
||||
### 3. Install the project dependencies.
|
||||
|
||||
`$ npm install`
|
||||
|
||||
### 4. Develop your feature
|
||||
|
||||
Commit as often as you like. Your branch will be squashed when the pull request is merged.
|
||||
|
||||
### 5. Run the tests
|
||||
|
||||
`$ npm run test`
|
||||
|
||||
### 6. Run linting
|
||||
|
||||
`$ npm run lint`
|
||||
|
||||
### 7. Submit your pull request
|
||||
|
||||
In the main comment of the pull request, you must state the GitHub issue that your PR
|
||||
resolves. You do this by using the syntax `Resolves #<issue-id>`. An example of this
|
||||
can be found [here](https://github.com/pebble/clay/pull/81)
|
||||
|
||||
|
||||
|
||||
# Project Structure and Development
|
||||
|
||||
|
||||
## Important Files
|
||||
|
||||
There are two main entry points for Clay - `index.js` and `src/scripts/config-page.js`.
|
||||
|
||||
### index.js
|
||||
|
||||
This is the main entry point for the code that will run in the Pebble app's `src/js/app.js`.
|
||||
It is responsible for serializing the provided config into a data URI that will be opened
|
||||
using `Pebble.openURL()`. It also persists data to `localStorage`.
|
||||
|
||||
### src/scripts/config-page.js
|
||||
|
||||
This is the main entry point for the code that runs on the generated config page,
|
||||
and is responsible for passing the injected config and other components to the
|
||||
`ClayConfig` class.
|
||||
|
||||
|
||||
## Building
|
||||
|
||||
Use the following command to build Clay during development.
|
||||
|
||||
`$ npm run dev`
|
||||
|
||||
This command packages up `src/scripts/config-page.js` and `dev/dev.js` into the `tmp/` directory
|
||||
so `dev/dev.html` can include them as script tags. This will also watch for changes
|
||||
in the project.
|
||||
|
||||
While developing components and other functionality for Clay, it is much easier to
|
||||
work with the files in the `dev/` directory than on a phone or emulator. Below is
|
||||
an explanation of the files and their purpose.
|
||||
|
||||
| File | Purpose |
|
||||
|----------|-----|
|
||||
| `dev.html` | Open this page in a browser after running `$ npm run dev`. |
|
||||
| `dev.js` | Injects the components and dependencies into the window the same way `index.js` would. |
|
||||
| `config.js` | Clay config to use as a sandbox for testing components. |
|
||||
| `custom-fn.js` | Clay custom function to be injected by `dev.js`. |
|
||||
| `emulator.html` | Copy of the HTML page that is used to make the Clay compatible with the Pebble SDK emulator. |
|
||||
| `uri-test.html` | Used to stress test URI creation for older browser versions. |
|
||||
|
||||
|
||||
## Testing your change inside of a test project.
|
||||
|
||||
Once your change is ready to be tested in the emulator or on the watch, follow these steps:
|
||||
|
||||
1. From your Clay fork run `$ npm run pebble-build`. This builds Clay to work with the Pebble SDK
|
||||
2. From your test Pebble project, run `$ pebble package install /path/to/your/clay/fork`.
|
||||
This will modify your `package.json` to point directly to your local copy of Clay.
|
||||
3. Run the usual`$ pebble build && pebble install --emulator basalt && pebble emu-app-config` to test your modifications
|
||||
4. If you make modifications to your fork of Clay, you must repeat the above steps.
|
||||
|
||||
|
||||
## Functionality
|
||||
|
||||
Most of the magic happens in the `src/scripts/lib` directory. `config-page.js`
|
||||
initializes a new instance of `ClayConfig` and calls the injected custom function
|
||||
(`window.customFn`) with the `ClayConfig` as its context. This allows developers to
|
||||
add extra functionality to the config page, such as setting values of items dynamically
|
||||
or registering small custom components.
|
||||
|
||||
Once the `ClayConfig` is initialized, we run the `.build()` method. This iterates over
|
||||
the config and injects each item into the page. Each item is an instance of `ClayItem`.
|
||||
It also indexes the items to later be retrieved with `.getAllItems()`,
|
||||
`.getItemByMessageKey()`, `.getItemById()`, `.getItemsByType()`.
|
||||
|
||||
|
||||
## Testing
|
||||
|
||||
Clay enforces 100% test coverage. Chances are, that if you are submitting a pull request,
|
||||
there should be tests for the proposed code changes. Have a look at the other tests in
|
||||
the repository to see some examples of how you should be writing your tests.
|
||||
|
||||
There are two commands to use while writing your tests.
|
||||
|
||||
- `$ npm run test` - Runs all tests once.
|
||||
- `$ npm run test-debug` - Watches for file changes and re-runs all tests when it
|
||||
detects a change. This also leaves an in instance of Google Chrome running.
|
||||
If you click the "Debug" button in the top right of the page, a new tab will open.
|
||||
You can then use the Google Chrome developer tools to debug your tests as they run.
|
||||
Refreshing the page will re-run the tests.
|
||||
|
||||
## Style Guide
|
||||
|
||||
Our style guide is very similar to the
|
||||
[Airbnb style guide.](https://github.com/airbnb/javascript/tree/master/es5) with the
|
||||
following exceptions:
|
||||
|
||||
- When saving a reference to `this` use `self`.
|
||||
```javascript
|
||||
// bad
|
||||
function() {
|
||||
var _this = this;
|
||||
return function() {
|
||||
console.log(_this);
|
||||
};
|
||||
}
|
||||
|
||||
// bad
|
||||
function() {
|
||||
var that = this;
|
||||
return function() {
|
||||
console.log(that);
|
||||
};
|
||||
}
|
||||
|
||||
// good
|
||||
function() {
|
||||
var self = this;
|
||||
return function() {
|
||||
console.log(self);
|
||||
};
|
||||
}
|
||||
```
|
||||
- Don't double name your functions. It makes refactoring more difficult.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
var log = function log(msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
// good
|
||||
var log = function(msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
```
|
||||
|
||||
The style guide is enforced using ESLint. Run `$ npm run lint` to ensure you are
|
||||
adhering to the style guide.
|
||||
|
||||
## Getting Help
|
||||
|
||||
- Chat to us in the `#app-dev` channel on Discord. https://discordapp.com/invite/aRUAYFN
|
||||
- Visit the [Rebble Forums](https://forum.rebble.io/)
|
||||
- Skeet at [@rebble.io](https://bsky.app/profile/rebble.io)
|
||||
- More options at https://developer.rebble.io/community/online/
|
||||
@@ -1,44 +1,30 @@
|
||||
# Clay
|
||||
Clay is a JavaScript library that makes it easy to add offline configuration pages to your Pebble apps. All you need to get started is a couple lines of JavaScript and a JSON file; no servers or HTML required.
|
||||
|
||||
Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events traditionally implemented by developers to relay configuration settings to the watch side of the app. This step is not required when using Clay, since each config item is given the same `messageKey` as defined in `appinfo.json` (or PebbleKit JS Message Keys on CloudPebble), and is automatically transmitted once the configuration page is submitted by the user. Developers can override this behavior by [handling the events manually](#handling-the-showconfiguration-and-webviewclosed-events-manually).
|
||||
Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events traditionally implemented by developers to relay configuration settings to the watch side of the app. This step is not required when using Clay, since each config item is given the same `messageKey` as defined in `package.json`, and is automatically transmitted once the configuration page is submitted by the user. Developers can override this behavior by [handling the events manually](#handling-the-showconfiguration-and-webviewclosed-events-manually).
|
||||
|
||||
Clay is distributed as a [Pebble package](https://developer.pebble.com/guides/pebble-packages/) so it is super easy to include in your project. If you are upgrading from v0.1.x of Clay you need to follow the [migration guide](#migrating-from-v01x-to-v1x) before you can get started.
|
||||
Clay is distributed as a [Pebble package](https://developer.rebble.io/guides/pebble-packages/) so it is super easy to include in your project. If you are upgrading from v0.1.x of Clay you need to follow the [migration guide](#migrating-from-v01x-to-v1x) before you can get started.
|
||||
|
||||
If you would like to contribute to Clay, check out the [contributing guide.](CONTRIBUTING.md)
|
||||
|
||||
# Getting Started (SDK 3.13 or higher)
|
||||
|
||||
1. Run `pebble package install pebble-clay` to install the package in your project
|
||||
1. Run `pebble package install @rebble/clay` to install the package in your project
|
||||
2. Create a JSON file called `config.json` and place it in your `src/js` directory.
|
||||
3. In order for JSON files to work you may need to change a line in your `wscript` from `ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob('src/js/**/*.js'))` to `ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob(['src/js/**/*.js', 'src/js/**/*.json']))`.
|
||||
4. Your `app.js` file needs to `require` clay and your config file, then be initialized. Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events. Copy and paste the following into the top of your `app.js` file:
|
||||
4. Your `index.js` (`app.js` in SDK 3) file needs to `require` clay and your config file, then be initialized. Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events. Copy and paste the following into the top of your `index.js` file:
|
||||
|
||||
```javascript
|
||||
var Clay = require('pebble-clay');
|
||||
var Clay = require('@rebble/clay');
|
||||
var clayConfig = require('./config.json');
|
||||
var clay = new Clay(clayConfig);
|
||||
```
|
||||
5. Ensure `pebble.enableMultiJS` is set to true in your `package.json`.
|
||||
6. Next is the fun part - creating your config page. Edit your `config.json` file to build a layout of elements as described in the sections below.
|
||||
7. Make sure you have defined all of your `messageKeys` in your `package.json`. More info on how that works [here.](https://developer.pebble.com/guides/communication/using-pebblekit-js/#defining-keys)
|
||||
7. Make sure you have defined all of your `messageKeys` in your `package.json`. More info on how that works [here.](https://developer.rebble.io/guides/communication/using-pebblekit-js/#defining-keys)
|
||||
|
||||
# Getting Started (CloudPebble)
|
||||
|
||||
1. Ensure `JS Handling` is set to `CommonJS-style` in your project settings.
|
||||
2. Under `Dependencies` in the project navigation, enter `pebble-clay` as the `Package Name` and `^1.0.0` for the `Version`. You may use any specific version you like, however using `^1.0.0` will ensure you receive all minor version updates.
|
||||
4. Create a JavaScript file called `config.js` with the following content. This will act as your config's root array element, from which the rest of the page is built up:
|
||||
|
||||
```javascript
|
||||
module.exports = [];
|
||||
```
|
||||
5. Your `app.js` file needs to `require` clay and your config file, then be initialized. Clay will by default automatically handle the 'showConfiguration' and 'webviewclosed' events. Copy and paste the following into the top of your `app.js` file:
|
||||
|
||||
```javascript
|
||||
var Clay = require('pebble-clay');
|
||||
var clayConfig = require('./config');
|
||||
var clay = new Clay(clayConfig);
|
||||
```
|
||||
6. Next is the fun part - creating your config page. Edit your `config.js` file to build a layout of elements as described in the sections below.
|
||||
7. Make sure you have defined all of your message keys using `Automatic assignment` in your project settings. More info on how that works [here.](https://developer.pebble.com/guides/communication/using-pebblekit-js/#defining-keys)
|
||||
# Getting Started (Rocky.js)
|
||||
If you are using [Rocky.js](https://developer.rebble.io/docs/rockyjs/) and would like to use Clay, please be aware that this is currently unsupported. It is possible to install the Clay package and override the 'showConfiguration' and 'webviewclosed' events and handle them manually, but Rocky.js does not currently support persistent storage, so the settings must be loaded from the phone each time. You can find an example of using Clay with Rocky.js [here](https://github.com/orviwan/rocky-leco-clay).
|
||||
|
||||
# Creating Your Config File
|
||||
|
||||
@@ -118,11 +104,12 @@ Headings can be used in anywhere and can have their size adjusted to suit the co
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `heading`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemById()` in your [custom function](#custom-function). |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| defaultValue | string/HTML | The heading's text. |
|
||||
| size | int | Defaults to `4`. An integer from 1 to 6 where 1 is the largest size and 6 is the smallest. (represents HTML `<h1>`, `<h2>`, `<h3>`, etc). |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -149,10 +136,11 @@ Text is used to provide descriptions of sections or to explain complex parts of
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `text`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemById()` in your [custom function](#custom-function). |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| defaultValue | string/HTML | The content of the text element. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -177,13 +165,15 @@ Standard text input field.
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `input`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemById()` in your [custom function](#custom-function). |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | string | The default value of the input field. |
|
||||
| serializeValueAs | string | target type to serialize value as. `string` means as is via cstring. `integer` means converted with `Math.trunc(Number.parseInt(value, 10))` as int32 (0 if NaN) |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| attributes | object | An object containing HTML attributes to set on the input field. Set `type` to values such as "email", "time", "date" etc to adjust the behavior of the component. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -215,12 +205,13 @@ Switch for a single item.
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `toggle`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemById()` in your [custom function](#custom-function). |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | int\|boolean | The default value of the toggle. Defaults to `false` if not specified. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
|
||||
##### Example
|
||||
@@ -247,13 +238,15 @@ A dropdown menu containing multiple options.
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `select`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemById()` in your [custom function](#custom-function). |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | string | The default value of the dropdown menu. Must match a value in the `options` array. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| options | array of objects | The options you want to appear in the dropdown menu. Each option is an object with a `label` and `value` property. |
|
||||
| serializeValueAs | string | target type to serialize value as. `string` means as is via cstring. `integer` means converted with `Math.trunc(Number.parseInt(value, 10))` as int32 (0 if NaN) |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -345,23 +338,24 @@ A color picker that allows users to choose a color from the ones that are compat
|
||||
The color picker will automatically show a different layout depending on the watch connected:
|
||||
|
||||
- Aplite (Firmware 2.x) - Black and white
|
||||
- Aplite (Firmware 3.x) - Black and white. Will also include gray (`#AAAAAA`) if `allowGray` is set to `true`
|
||||
- Basalt/chalk - The 64 colors compatible with color Pebble smartwatches.
|
||||
- Aplite/Diorite/Flint (Firmware 3.x) - Black and white. Will also include gray (`#AAAAAA`) if `allowGray` is set to `true`
|
||||
- Basalt/Chalk/Emery/Gabbro - The 64 colors compatible with color Pebble smartwatches.
|
||||
|
||||
##### Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `color`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemById()` in your [custom function](#custom-function). |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | string OR int | The default color. One of the [64 colors](https://developer.pebble.com/guides/tools-and-resources/color-picker/) compatible with Pebble smartwatches. Always use the uncorrected value even if `sunlight` is true. The component will do the conversion internally. |
|
||||
| defaultValue | string OR int | The default color. One of the [64 colors](https://developer.rebble.io/guides/tools-and-resources/color-picker/) compatible with Pebble smartwatches. Always use the uncorrected value even if `sunlight` is true. The component will do the conversion internally. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| sunlight | boolean | Use the color-corrected sunlight color palette if `true`, else the uncorrected version. Defaults to `true` if not specified. |
|
||||
| layout | string OR array | Optional. Use a custom layout for the color picker. Defaults to automatically choosing the most appropriate layout for the connected watch. The layout is represented by a two dimensional array. Use `false` to insert blank spaces. You may also use one of the preset layouts by setting `layout` to: `"COLOR"`, `"GRAY"` or `"BLACK_WHITE"` |
|
||||
| allowGray | boolean | Optional. Set this to `true` to include gray (`#AAAAAA`) in the color picker for aplite running on firmware 3 and above. This is optional because only a subset of the drawing operations support gray on aplite. Defaults to `false` |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -419,13 +413,15 @@ A list of options allowing the user can only choose one option to submit.
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `radiogroup`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemById()` in your [custom function](#custom-function). |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | string | The default selected item. Must match a value in the `options` array. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| options | array of objects | The options you want to appear in the radio group. Each option is an object with a `label` and `value` property. |
|
||||
| serializeValueAs | string | target type to serialize value as. `string` means as is via cstring. `integer` means converted with `Math.trunc(Number.parseInt(value, 10))` as int32. (0 if NaN) |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -464,13 +460,14 @@ A list of options where a user may choose more than one option to submit.
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `checkboxgroup`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemsById()` in your [custom function](#custom-function). |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. **NOTE:** The checkboxgroup component will expect you to have defined a `messageKey` in your `package.json` using array syntax. In the example below, the matching entry in the `package.json` would be `favorite_food[3]`. In CloudPebble, you must use `Automatic assignment` for message keys and the `Key Array Length` must match the number of options in the checkboxgroup |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemById()` in your [custom function](#custom-function). |
|
||||
| messageKey | string (unique) | The AppMessage key matching the `messageKey` item defined in your `package.json`. Set this to a unique string to allow this item to be looked up using `Clay.getItemsByMessageKey()` in your custom function. You must set this if you wish for the value of this item to be persisted after the user closes the config page. **NOTE:** The checkboxgroup component will expect you to have defined a `messageKey` in your `package.json` using array syntax. In the example below, the matching entry in the `package.json` would be `favorite_food[3]`. |
|
||||
| label | string | The label that should appear next to this item. |
|
||||
| defaultValue | array of booleans | The default selected items. |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| options | array of strings | The labels for each checkbox you want to appear in the checkbox group. |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -497,10 +494,12 @@ In the above example, Sushi and Burgers will be selected by default.
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `button`. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemById()` in your [custom function](#custom-function). |
|
||||
| defaultValue | string | The text displayed on the button. |
|
||||
| primary | boolean | If `true` the button will be orange, if `false`, the button will be gray (defaults to `false`)|
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -520,7 +519,7 @@ In the above example, Sushi and Burgers will be selected by default.
|
||||
|
||||
The range slider is used to allow users to select numbers between two values.
|
||||
|
||||
**NOTE** If you set the `step` property to anything less than `1`,
|
||||
**NOTE** If you set the `step` property to a fractional value,
|
||||
it will multiply the final value sent to the watch by 10 to the power of the number of decimal places in the value of `step`.
|
||||
Eg: If you set the `step` to `0.25` and the slider has value of `34.5`, the watch will receive `3450`.
|
||||
The reason why this is necessary, is because you can not send floats to the watch via `Pebble.sendAppMessage()`.
|
||||
@@ -539,6 +538,7 @@ you must just remember to divide the received value on the watch accordingly.
|
||||
| step | number | The multiple of the values allowed to be set on the slider. The slider will snap to these values. This value also determines the precision used when the value is sent to the watch. Defaults to 1 |
|
||||
| description | string | Optional sub-text to include below the component |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -569,7 +569,9 @@ The submit button for the page. You **MUST** include this component somewhere in
|
||||
|----------|------|-------------|
|
||||
| type | string | Set to `submit`. |
|
||||
| defaultValue | string | The text displayed on the button. |
|
||||
| id | string (unique) | Set this to a unique string to allow this item to be looked up using `Clay.getItemById()` in your [custom function](#custom-function). |
|
||||
| capabilities | array | Array of features that the connected watch must have for this item to be present |
|
||||
| group | string | Set this to allow this item, along with other items sharing the same group to be looked up using `Clay.getItemsByGroup()` in your [custom function](#custom-function) |
|
||||
|
||||
##### Example
|
||||
|
||||
@@ -584,7 +586,7 @@ The submit button for the page. You **MUST** include this component somewhere in
|
||||
|
||||
### Message keys and array syntax
|
||||
|
||||
Clay supports (and requires in some cases) the use of array syntax for message keys. Also known as `Automatic assignment` in CloudPebble. More info [here.](https://developer.pebble.com/guides/communication/using-pebblekit-js/#defining-keys)
|
||||
Clay supports (and requires in some cases) the use of array syntax for message keys. More info [here.](https://developer.rebble.io/guides/communication/using-pebblekit-js/#defining-keys)
|
||||
|
||||
You can assign any component that does not return an array to a particular position in your message key. This is done by appending the position (zero indexed) wrapped in brackets to the end of the `messageKey` property. Do **NOT** include any spaces in your `messageKey`.
|
||||
|
||||
@@ -664,12 +666,18 @@ Below is the full list of capabilities
|
||||
| PLATFORM_BASALT | Running on Pebble Time/Pebble Time Steel. |
|
||||
| PLATFORM_CHALK | Running on Pebble Time Round. |
|
||||
| PLATFORM_DIORITE | Running on Pebble 2 |
|
||||
| PLATFORM_EMERY | Running on Time 2. |
|
||||
| PLATFORM_EMERY | Running on Core Time 2. |
|
||||
| PLATFORM_FLINT | Running on Core 2 Duo. |
|
||||
| PLATFORM_GABBRO | Running on Core Time Round 2 |
|
||||
| BW | Running on hardware that supports only black and white. |
|
||||
| COLOR | Running on hardware that supports 64 colors. |
|
||||
| COMPASS | Running on hardware that includes a compass. |
|
||||
| MICROPHONE | Running on hardware that includes a microphone. |
|
||||
| RGB_BACKLIGHT | Running on hardware that includes a RGB backlight. |
|
||||
| SMARTSTRAP | Running on hardware that includes a smartstrap connector. |
|
||||
| SMARTSTRAP_POWER | Running on hardware that includes a powered smartstrap connector. |
|
||||
| SPEAKER | Running on hardware that includes a speaker. |
|
||||
| TOUCH | Running on hardware that includes a touch screen. |
|
||||
| HEALTH | Running on hardware that supports Pebble Health and the HealthService API. |
|
||||
| RECT | Running on hardware with a rectangular display. |
|
||||
| ROUND | Running on hardware with a round display. |
|
||||
@@ -786,7 +794,7 @@ Clay will by default, automatically handle the 'showConfiguration' and 'webviewc
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var Clay = require('./clay');
|
||||
var Clay = require('@rebble/clay');
|
||||
var clayConfig = require('./config');
|
||||
var clayConfigAplite = require('./config-aplite');
|
||||
var clay = new Clay(clayConfig, null, { autoHandleEvents: false });
|
||||
@@ -820,51 +828,6 @@ Pebble.addEventListener('webviewclosed', function(e) {
|
||||
});
|
||||
```
|
||||
|
||||
## Clay and Pebble.js
|
||||
|
||||
If you are using [Pebble.js](https://developer.pebble.com/docs/pebblejs/) and would like to use Clay, There are some extra steps to follow:
|
||||
|
||||
1. Remove all your `Settings.config` calls. Clay will handle the settings from now on.
|
||||
2. Use the example below to modify your `app.js`. Notice that `autoHandleEvents` is set to `false` in the Clay constructor.:
|
||||
|
||||
```javascript
|
||||
var Settings = require('settings');
|
||||
var Clay = require('./clay');
|
||||
var clayConfig = require('./config');
|
||||
var clay = new Clay(clayConfig, null, {autoHandleEvents: false});
|
||||
|
||||
Pebble.addEventListener('showConfiguration', function(e) {
|
||||
Pebble.openURL(clay.generateUrl());
|
||||
});
|
||||
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
if (e && !e.response) {
|
||||
return;
|
||||
}
|
||||
var dict = clay.getSettings(e.response);
|
||||
|
||||
// Save the Clay settings to the Settings module.
|
||||
Settings.option(dict);
|
||||
});
|
||||
```
|
||||
|
||||
### Caveats
|
||||
|
||||
Clay treats colors as numbers. You will need to convert these numbers to CSS colors before they can be used by Pebble.js. Use the function below to convert the colors.
|
||||
|
||||
```javascript
|
||||
function cssColor(color) {
|
||||
color = color.toString(16);
|
||||
while (color.length < 6) {
|
||||
color = '0' + color;
|
||||
}
|
||||
return '#' + color;
|
||||
}
|
||||
|
||||
// Example usage with default:
|
||||
cssColor(Settings.option('BACKGROUND_COLOR') || 0xff0000);
|
||||
```
|
||||
|
||||
## Clay API (app.js)
|
||||
|
||||
### `Clay([Array] config, [function] customFn, [object] options)`
|
||||
@@ -886,9 +849,9 @@ cssColor(Settings.option('BACKGROUND_COLOR') || 0xff0000);
|
||||
| `.config` | Array | Copy of the config passed to the constructor and used for generating the page. |
|
||||
| `.customFn` | Function | Reference to the custom function passed to the constructor. **WARNING** this is a direct reference, not a copy of the custom function so any modification you make to it, will be reflected on the original as well |
|
||||
| `.meta` | Object | Contains information about the current user and watch. **WARNING** This will only be populated in the `showConfiguration` event handler. (See example above) |
|
||||
| `.meta.activeWatchInfo` | watchinfo\|null | An object containing information on the currently connected Pebble smartwatch or null if unavailable. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getActiveWatchInfo). |
|
||||
| `.meta.accountToken` | String | A unique account token that is associated with the Pebble account of the current user. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getAccountToken). |
|
||||
| `.meta.watchToken` | String | A unique token that can be used to identify a Pebble device. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getWatchToken). |
|
||||
| `.meta.activeWatchInfo` | watchinfo\|null | An object containing information on the currently connected Pebble smartwatch or null if unavailable. Read more [here](https://developer.rebble.io/docs/js/Pebble/#getActiveWatchInfo). |
|
||||
| `.meta.accountToken` | String | A unique account token that is associated with the Pebble account of the current user. Read more [here](https://developer.rebble.io/docs/js/Pebble/#getAccountToken). |
|
||||
| `.meta.watchToken` | String | A unique token that can be used to identify a Pebble device. Read more [here](https://developer.rebble.io/docs/js/Pebble/#getWatchToken). |
|
||||
| `.meta.userData` | Any | A deep copy of the arbitrary data provided in the `options.userData`. Defaults to an empty object |
|
||||
| `.version` | String | The version of Clay currently being used. |
|
||||
|
||||
@@ -899,7 +862,41 @@ cssColor(Settings.option('BACKGROUND_COLOR') || 0xff0000);
|
||||
| `Clay( [array] config, [function] customFn=null, [object] options={autoHandleEvents: true})` <br> `config` - an Array representing your config <br> `customFn` - function to be run in the context of the generated page <br> `options.autoHandleEvents` - set to `false` to prevent Clay from automatically handling the "showConfiguration" and "webviewclosed" events | `Clay` - a new instance of Clay. |
|
||||
| `.registerComponent( [ClayComponent] component )` <br> Registers a custom component. | `void`. |
|
||||
| `.generateUrl()` | `string` - The URL to open with `Pebble.openURL()` to use the Clay-generated config page. |
|
||||
| `.getSettings( [object] response, [boolean] convert=true)` <br> `response` - the response object provided to the "webviewclosed" event <br> `convert` - Pass `false` to not convert the settings to be compatible with `Pebble.sendAppMessage()` | `Object` - object of keys and values for each config page item with an `messageKey`, where the key is the `messageKey` and the value is the chosen value of that item. This method will do some conversions depending on the type of the setting. Arrays containing strings will have zeros inserted before each item. eg `['one', 'two']` becomes `['one', 0, 'two', 0]`. Booleans will be converted to numbers. eg `true` becomes `1` and `false` becomes `0`. Pass `false` as the second parameter to disable this behavior |
|
||||
| `.getSettings( [object] response, [boolean] convert=true)` <br> `response` - the response object provided to the "webviewclosed" event <br> `convert` - Pass `false` to not convert the settings to be compatible with `Pebble.sendAppMessage()` | `Object` - object of keys and values for each config page item with an `messageKey`, where the key is the `messageKey` and the value is the chosen value of that item. <br><br>This method will do some conversions depending on the type of the setting. Arrays will use message key array syntax to make the values of each item in the array available as individual message keys. Booleans will be converted to numbers. eg `true` becomes `1` and `false` becomes `0`. If the value is a number or an array of numbers and the optional property: "precision" is the power of precision (value * 10 ^ precision) and then floored. Eg: `1.4567` with a precision set to `3` will become `1456`. Pass `false` as the second parameter to disable this behavior. See the example below for how this all works |
|
||||
| `.setSettings( [string] key, [*] value )` <br> `key` - The key for the setting you want to set. <br> `value` - The value of the setting you want to set. | `void` |
|
||||
| `.setSettings( [object] settings )` <br> `settings` - An object of key/value pairs that you would like to update the settings with. eg `{ user_name: 'Emily', show_animations: true }` | `void` |
|
||||
|
||||
#### `.getSettings()` Example
|
||||
|
||||
```javascript
|
||||
|
||||
// webviewclosed response
|
||||
{
|
||||
"favorite_food": {"value": [1, 0, 1]},
|
||||
"cool_things_enabled": {"value": true},
|
||||
"user_name": {"value": "Jane Doe"},
|
||||
"date_of_birth[0]": {"value": 1989},
|
||||
"date_of_birth[1]": {"value": 11},
|
||||
"date_of_birth[2]": {"value": 28},
|
||||
"rating": {"value": 3.5, "precision": 1},
|
||||
}
|
||||
|
||||
// resulting converted values
|
||||
|
||||
var messageKeys = require('message_keys');
|
||||
|
||||
messageKeys.favorite_food + 0 = 1;
|
||||
messageKeys.favorite_food + 1 = 0;
|
||||
messageKeys.favorite_food + 2 = 1;
|
||||
messageKeys.cool_things_enabled = 1;
|
||||
messageKeys.user_name = 'Jane Doe';
|
||||
messageKeys.date_of_birth + 0 = 1989;
|
||||
messageKeys.date_of_birth + 1 = 11;
|
||||
messageKeys.date_of_birth + 2 = 28;
|
||||
messageKeys.rating = 35;
|
||||
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -919,7 +916,7 @@ Make sure to always wait for the config page to be built before manipulating ite
|
||||
##### app.js
|
||||
|
||||
```javascript
|
||||
var Clay = require('./clay');
|
||||
var Clay = require('@rebble/clay');
|
||||
var clayConfig = require('./config');
|
||||
var customClay = require('./custom-clay');
|
||||
var userData = {token: 'abc123'}
|
||||
@@ -982,9 +979,9 @@ This is the main way of talking to your generated config page. An instance of th
|
||||
| `.EVENTS.AFTER_DESTROY` | String | Dispatched after destroying the page. |
|
||||
| `.config` | Array | Reference to the config passed to the constructor and used for generating the page. |
|
||||
| `.meta` | Object | Contains information about the current user and watch |
|
||||
| `.meta.activeWatchInfo` | watchinfo\|null | An object containing information on the currently connected Pebble smartwatch or null if unavailable. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getActiveWatchInfo). |
|
||||
| `.meta.accountToken` | String | A unique account token that is associated with the Pebble account of the current user. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getAccountToken). |
|
||||
| `.meta.watchToken` | String | A unique token that can be used to identify a Pebble device. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getWatchToken). |
|
||||
| `.meta.activeWatchInfo` | watchinfo\|null | An object containing information on the currently connected Pebble smartwatch or null if unavailable. Read more [here](https://developer.rebble.io/docs/js/Pebble/#getActiveWatchInfo). |
|
||||
| `.meta.accountToken` | String | A unique account token that is associated with the Pebble account of the current user. Read more [here](https://developer.rebble.io/docs/js/Pebble/#getAccountToken). |
|
||||
| `.meta.watchToken` | String | A unique token that can be used to identify a Pebble device. Read more [here](https://developer.rebble.io/docs/js/Pebble/#getWatchToken). |
|
||||
| `.meta.userData` | Any | The data passed in the `options.userData` of the [Clay constructor.](#clayarray-config-function-customfn-object-options) |
|
||||
|
||||
|
||||
@@ -996,6 +993,7 @@ This is the main way of talking to your generated config page. An instance of th
|
||||
| `.getItemByMessageKey( [string] messageKey )` | `ConfigItem\|undefined` - a single `ConfigItem` that has the provided `messageKey`, otherwise `undefined`. |
|
||||
| `.getItemById( [string] id )` | `ConfigItem\|undefined` - a single `ConfigItem` that has the provided `id`, otherwise `undefined`. |
|
||||
| `.getItemsByType( [string] type )` | `Array.<ConfigItem>` - an array of config items that match the provided `type`. |
|
||||
| `.getItemsByGroup( [string] group )` | `Array.<ConfigItem>` - an array of config items that match the provided `group`. |
|
||||
| `.serialize()` | `Object` - an object representing all items with an `messageKey` where the key is the `messageKey` and the value is an object with the `value` property set to the result of running `.get()` on the Clay item. If the Clay item has a `precision` property set, it is included in the object |
|
||||
| `.build()` <br> Builds the config page. Will dispatch the `BEFORE_BUILD` event prior to building the page, then the `AFTER_BUILD` event once it is complete. If the config page has already been built, then the `ClayConfig.destroy()` method will be executed prior to building the page again. | `ClayConfig` |
|
||||
| `.destroy()` <br> Destroys the config page. Will dispatch the `BEFORE_DESTROY` event prior to destroying the page, then the `AFTER_DESTROY` event once it is complete. This method wipes the config page completely, including all existing items. You will need to make sure that you re-attach your event handlers for any items that are replaced | `ClayConfig` |
|
||||
@@ -1013,7 +1011,7 @@ This is the main way of talking to your generated config page. An instance of th
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `.id` | String | The ID of the item if provided in the config. |
|
||||
| `.messageKey` | String | The ID of the item if provided in the config. |
|
||||
| `.messageKey` | String | The messageKey of the item if provided in the config. |
|
||||
| `.config` | Object | Reference to the config passed to the constructer. |
|
||||
| `$element` | $Minified | A Minified list representing the root HTML element of the config item. |
|
||||
| `$manipulatorTarget` | $Minified | A Minified list representing the HTML element with **data-manipulator-target** set. This is generally pointing to the main `<input>` element and will be used for binding events. |
|
||||
@@ -1056,7 +1054,7 @@ Components are simple objects with the following properties.
|
||||
Components must be registered before the config page is built. The easiest way to do this is in your `app.js` after you have initialized Clay:
|
||||
|
||||
```javascript
|
||||
var Clay = require('./clay');
|
||||
var Clay = require('@rebble/clay');
|
||||
var clayConfig = require('./config.json');
|
||||
var clay = new Clay(clayConfig);
|
||||
|
||||
@@ -1093,56 +1091,6 @@ clay.registerComponent(require('./my-custom-component'));
|
||||
- `_.template()`
|
||||
- `_.isObject()`
|
||||
|
||||
# Project Structure and Development
|
||||
|
||||
There are two main entry points for Clay - `index.js` and `src/scripts/config-page.js`.
|
||||
|
||||
#### index.js
|
||||
|
||||
This is the main entry point for the code that will run in the Pebble app's `src/js/app.js`. It is responsible for serializing the provided config into a data URI that will be opened using `Pebble.openURL()`. It also persists data to `localStorage`.
|
||||
|
||||
#### src/scripts/config-page.js
|
||||
|
||||
This is the main entry point for the code that runs on the generated config page, and is responsible for passing the injected config and other components to the `ClayConfig` class.
|
||||
|
||||
|
||||
### Building
|
||||
|
||||
There are two ways to build Clay, production mode and development mode.
|
||||
|
||||
#### Production Mode
|
||||
|
||||
```
|
||||
$ npm run build
|
||||
```
|
||||
|
||||
Packages up the entire Clay project into `dist/clay.js` to be required in the developer's `app.js`.
|
||||
|
||||
#### Development Mode
|
||||
|
||||
```
|
||||
$ npm run dev
|
||||
```
|
||||
|
||||
Packages up `src/scripts/config-page.js` and `dev/dev.js` into the `tmp/` directory so `dev/dev.html` can include them as script tags. This will also watch for changes in the project.
|
||||
|
||||
While developing components and other functionality for Clay, it is much easier to work with the files in the `dev/` directory than on a phone or emulator. Below is an explanation of the files and their purpose.
|
||||
|
||||
| File | Purpose |
|
||||
|----------|-----|
|
||||
| `dev.html` | Open this page in a browser after running `$ npm run dev`. |
|
||||
| `dev.js` | Injects the components and dependencies into the window the same way `index.js` would. |
|
||||
| `config.js` | Clay config to use as a sandbox for testing components. |
|
||||
| `custom-fn.js` | Clay custom function to be injected by `dev.js`. |
|
||||
| `emulator.html` | Copy of the HTML page that is used to make the Clay compatible with the Pebble SDK emulator. |
|
||||
| `uri-test.html` | Used to stress test URI creation for older browser versions. |
|
||||
|
||||
## Functionality
|
||||
|
||||
Most of the magic happens in the `src/scripts/lib` directory. `config-page.js` initializes a new instance of `ClayConfig` and calls the injected custom function (`window.customFn`) with the `ClayConfig` as its context. This allows developers to add extra functionality to the config page, such as setting values of items dynamically or registering small custom components.
|
||||
|
||||
Once the `ClayConfig` is initialized, we run the `.build()` method. This iterates over the config and injects each item into the page. Each item is an instance of `ClayItem`. It also indexes the items to later be retrieved with `.getAllItems()`, `.getItemByMessageKey()`, `.getItemById()`, `.getItemsByType()`.
|
||||
|
||||
# Migrating from v0.1.x to v1.x
|
||||
|
||||
There were some changes in the 3.13 SDK that required Clay to undergo some major changes. For the majority of developers a simple find and replace over your config will do the trick.
|
||||
@@ -1176,6 +1124,74 @@ becomes:
|
||||
|
||||
If you have a [custom function](#custom-function) and are using the `clayConfig.getItemByAppKey()` method you will need to change this to `clayConfig.getItemByMessageKey()`
|
||||
|
||||
### clay.getSettings() will now by default, return an object where the keys are numbers.
|
||||
|
||||
In the past, `clay.getSettings()` would return something that looked like:
|
||||
|
||||
```javascript
|
||||
{
|
||||
BACKGROUND_COLOR: 0,
|
||||
NAME: 'Jane Doe',
|
||||
ENABLE_TOOLS: 1
|
||||
}
|
||||
```
|
||||
|
||||
It now uses the values provided in the `message_keys` module to construct this object.
|
||||
The new format looks something like:
|
||||
|
||||
```javascript
|
||||
{
|
||||
10000: 0,
|
||||
10001: 'Jane Doe',
|
||||
10002: 1
|
||||
}
|
||||
```
|
||||
|
||||
If you wish to find out what keys are associated with what values, you must use the `message_keys` module.
|
||||
|
||||
```javascript
|
||||
var messageKeys = require('message_keys');
|
||||
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
// Get the keys and values from each config item
|
||||
var claySettings = clay.getSettings(e.response);
|
||||
|
||||
// In this example messageKeys.NAME is equal to 10001
|
||||
console.log('Name is ' + claySettings[messageKeys.NAME]); // Logs: "Name is Jane Doe"
|
||||
});
|
||||
```
|
||||
|
||||
**NOTE:** The above only applies to the default behavior of the method. If you pass
|
||||
`false` to the second argument, a standard object will be returned with the `messageKey`
|
||||
as the key.
|
||||
|
||||
```javascript
|
||||
|
||||
Pebble.addEventListener('webviewclosed', function(e) {
|
||||
|
||||
clay.getSettings(e.response);
|
||||
/* returns:
|
||||
{
|
||||
10000: 0,
|
||||
10001: 'Jane Doe',
|
||||
10002: 1
|
||||
}
|
||||
*/
|
||||
|
||||
clay.getSettings(e.response, false);
|
||||
/* returns:
|
||||
{
|
||||
BACKGROUND_COLOR: {value: 0},
|
||||
NAME: {value: 'Jane Doe'},
|
||||
ENABLE_TOOLS: {value: true}
|
||||
}
|
||||
|
||||
Notice that the value for ENABLE_TOOLS was not converted to a number from a boolean
|
||||
*/
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### Checkbox groups now use arrays.
|
||||
|
||||
In the previous version of Clay, checkbox groups would split the values of the items with zeros. This made for clumsy usage on the C side. Checkbox groups are now much simpler to use thanks to message keys. You will however need to update you config to the new format.
|
||||
|
||||
+3
-3
@@ -64,11 +64,11 @@ module.exports = [
|
||||
{
|
||||
"type": "slider",
|
||||
"messageKey": "slider",
|
||||
"defaultValue": 15,
|
||||
"defaultValue": 0,
|
||||
"label": "Slider",
|
||||
"description": "This is the description for the slider",
|
||||
"min": 10,
|
||||
"max": 20,
|
||||
"min": 0,
|
||||
"max": 30,
|
||||
"step": 0.25
|
||||
},
|
||||
{
|
||||
|
||||
+62
-30
@@ -8,11 +8,10 @@ var stringify = require('stringify');
|
||||
var del = require('del');
|
||||
var inline = require('gulp-inline');
|
||||
var htmlmin = require('gulp-htmlmin');
|
||||
var sass = require('gulp-sass');
|
||||
var sass = require('gulp-sass')(require('sass'));
|
||||
var sourceMaps = require('gulp-sourcemaps');
|
||||
var autoprefixer = require('gulp-autoprefixer');
|
||||
var uglify = require('gulp-uglify');
|
||||
var sassify = require('sassify');
|
||||
var autoprefixify = require('./src/scripts/vendor/autoprefixify');
|
||||
var insert = require('gulp-insert');
|
||||
var clayPackage = require('./package.json');
|
||||
@@ -22,22 +21,13 @@ var sassIncludePaths = [].concat(
|
||||
'src/styles'
|
||||
);
|
||||
|
||||
var sassifyOptions = {
|
||||
base64Encode: false,
|
||||
sourceMap: false,
|
||||
sourceMapEmbed: false,
|
||||
sourceMapContents: false,
|
||||
outputStyle: 'compact',
|
||||
includePaths: sassIncludePaths
|
||||
};
|
||||
|
||||
var autoprefixerOptions = {
|
||||
browsers: ['Android 4', 'iOS 8'],
|
||||
cascade: false
|
||||
};
|
||||
|
||||
var stringifyOptions = ['.html', '.tpl'];
|
||||
var versionMessage = '/* Clay - https://github.com/pebble/clay - Version: ' +
|
||||
var stringifyOptions = ['.html', '.tpl', '.css'];
|
||||
var versionMessage = '/* Clay - https://github.com/pebble-dev/clay - Version: ' +
|
||||
clayPackage.version +
|
||||
' - Build Date: ' + new Date().toISOString() + ' */\n';
|
||||
|
||||
@@ -45,29 +35,44 @@ gulp.task('clean-js', function() {
|
||||
return del(['tmp/config-page.js']);
|
||||
});
|
||||
|
||||
gulp.task('js', ['clean-js'], function() {
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
function taskJs() {
|
||||
return browserify('src/scripts/config-page.js', { debug: true })
|
||||
.transform('deamdify')
|
||||
.bundle()
|
||||
.pipe(source('config-page.js'))
|
||||
.pipe(gulp.dest('./tmp/'));
|
||||
});
|
||||
}
|
||||
|
||||
gulp.task('js', gulp.series('clean-js', taskJs));
|
||||
|
||||
gulp.task('clean-sass', function() {
|
||||
return del(['tmp/config-page.scss']);
|
||||
});
|
||||
gulp.task('sass', ['clean-sass'], function() {
|
||||
gulp.src('./src/styles/config-page.scss')
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
function taskSass() {
|
||||
return gulp.src(['./src/styles/config-page.scss',
|
||||
'./src/styles/clay/components/*.scss'])
|
||||
.pipe(sourceMaps.init())
|
||||
.pipe(sass({
|
||||
includePaths: sassIncludePaths
|
||||
loadPaths: sassIncludePaths
|
||||
}).on('error', sass.logError))
|
||||
.pipe(autoprefixer(autoprefixerOptions))
|
||||
.pipe(sourceMaps.write('./'))
|
||||
.pipe(gulp.dest('tmp'));
|
||||
});
|
||||
}
|
||||
|
||||
gulp.task('inlineHtml', ['js', 'sass'], function() {
|
||||
gulp.task('sass', gulp.series('clean-sass', taskSass));
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
function taskInlineHtml() {
|
||||
return gulp.src('src/config-page.html')
|
||||
.pipe(inline())
|
||||
.pipe(htmlmin({
|
||||
@@ -80,17 +85,21 @@ gulp.task('inlineHtml', ['js', 'sass'], function() {
|
||||
minifyCSS: true
|
||||
}))
|
||||
.pipe(gulp.dest('tmp/'));
|
||||
});
|
||||
}
|
||||
|
||||
gulp.task('clay', ['inlineHtml'], function() {
|
||||
gulp.task('inlineHtml', gulp.series('js', 'sass', taskInlineHtml));
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
function taskClay() {
|
||||
return browserify('index.js', {
|
||||
debug: false,
|
||||
standalone: clayPackage.name
|
||||
})
|
||||
.transform('deamdify')
|
||||
.transform(stringify(stringifyOptions))
|
||||
.transform(sassify, sassifyOptions)
|
||||
.transform(autoprefixify, autoprefixerOptions)
|
||||
// .transform(autoprefixify, autoprefixerOptions)
|
||||
.require(require.resolve('./index'), {expose: clayPackage.name})
|
||||
.exclude('message_keys')
|
||||
.bundle()
|
||||
@@ -101,23 +110,46 @@ gulp.task('clay', ['inlineHtml'], function() {
|
||||
}))
|
||||
.pipe(insert.prepend(versionMessage))
|
||||
.pipe(gulp.dest('./src/js'));
|
||||
}
|
||||
|
||||
gulp.task('clay', gulp.series('inlineHtml', taskClay));
|
||||
|
||||
// Validates the curated index.d.ts against test/type-checks.ts.
|
||||
// For per-file reference declarations in dist-types/, run: npm run build:types
|
||||
gulp.task('types', function(done) {
|
||||
var exec = require('child_process').exec;
|
||||
exec('npx tsc -p tsconfig.typecheck.json', function(err, stdout, stderr) {
|
||||
if (stdout) { console.log(stdout); }
|
||||
if (stderr) { console.error(stderr); }
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('dev-js', ['js', 'sass'], function() {
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
function taskDevJs() {
|
||||
return browserify('dev/dev.js', { debug: true })
|
||||
.transform(stringify(stringifyOptions))
|
||||
.transform('deamdify')
|
||||
.transform(sassify, sassifyOptions)
|
||||
.transform(autoprefixify, autoprefixerOptions)
|
||||
.ignore('message_keys')
|
||||
.bundle()
|
||||
.pipe(source('dev.js'))
|
||||
.pipe(gulp.dest('./tmp/'));
|
||||
});
|
||||
}
|
||||
|
||||
gulp.task('default', ['clay']);
|
||||
gulp.task('dev-js', gulp.series('js', 'sass', taskDevJs));
|
||||
|
||||
gulp.task('dev', ['dev-js'], function() {
|
||||
gulp.task('default', gulp.series('clay', 'types'));
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
function taskDev() {
|
||||
gulp.watch('src/styles/**/*.scss', ['sass']);
|
||||
gulp.watch(['src/scripts/**/*.js', 'src/templates/**/*.tpl'], ['js']);
|
||||
gulp.watch(['src/**', 'dev/**/*.js'], ['dev-js']);
|
||||
});
|
||||
}
|
||||
|
||||
gulp.task('dev', gulp.series('dev-js', taskDev));
|
||||
|
||||
Vendored
+313
@@ -0,0 +1,313 @@
|
||||
/**
|
||||
* TypeScript declarations for @rebble/clay
|
||||
*
|
||||
* A Pebble configuration framework that provides a simple way to generate a
|
||||
* configuration page for Pebble watchapps and watchfaces.
|
||||
*/
|
||||
|
||||
/** Minimal DOM wrapper type from minified.js */
|
||||
interface M {
|
||||
[index: number]: HTMLElement;
|
||||
length: number;
|
||||
add(child: M | string): M;
|
||||
set(property: string, value?: unknown): M;
|
||||
get(property: string): unknown;
|
||||
select(selector: string): M;
|
||||
on(events: string, handler: (...args: unknown[]) => void): M;
|
||||
each(callback: (element: HTMLElement, index: number) => void): M;
|
||||
}
|
||||
|
||||
/** A Clay config item as provided in the config array */
|
||||
interface ClayConfigItem {
|
||||
type: string;
|
||||
defaultValue?: string | boolean | number;
|
||||
messageKey?: string;
|
||||
id?: string;
|
||||
label?: string;
|
||||
attributes?: Record<string, unknown>;
|
||||
options?: unknown[];
|
||||
serializeValueAs?: string,
|
||||
items?: ClayConfigItem[];
|
||||
capabilities?: string[];
|
||||
group?: string;
|
||||
}
|
||||
|
||||
/** A Clay component definition */
|
||||
interface ClayComponent {
|
||||
name: string;
|
||||
template: string;
|
||||
manipulator: string | ClayManipulator;
|
||||
defaults?: Record<string, unknown>;
|
||||
style?: string;
|
||||
initialize?: (this: ClayItem, minified: unknown, clay: ClayConfig) => void;
|
||||
}
|
||||
|
||||
/** A manipulator with get and set methods */
|
||||
interface ClayManipulator {
|
||||
get: (this: ClayItem) => unknown;
|
||||
set: (this: ClayItem, value: unknown) => ClayItem;
|
||||
disable?: (this: ClayItem) => ClayItem;
|
||||
enable?: (this: ClayItem) => ClayItem;
|
||||
hide?: (this: ClayItem) => ClayItem;
|
||||
show?: (this: ClayItem) => ClayItem;
|
||||
}
|
||||
|
||||
/** Clay meta information populated from the Pebble object */
|
||||
interface ClayMeta {
|
||||
activeWatchInfo: PebbleActiveWatchInfo | null;
|
||||
accountToken: string;
|
||||
watchToken: string;
|
||||
userData: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/** Watch info from the Pebble API */
|
||||
interface PebbleActiveWatchInfo {
|
||||
platform: string;
|
||||
model: string;
|
||||
language: string;
|
||||
firmware: {
|
||||
major: number;
|
||||
minor: number;
|
||||
patch: number;
|
||||
suffix: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** Options for the Clay constructor */
|
||||
interface ClayOptions {
|
||||
autoHandleEvents?: boolean;
|
||||
userData?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/** Event methods mixed in by ClayEvents */
|
||||
interface ClayEvents {
|
||||
/**
|
||||
* Attach an event listener.
|
||||
* @param events - a space-separated list of events
|
||||
* @param handler - the event handler
|
||||
*/
|
||||
on(events: string, handler: (...args: unknown[]) => void): this;
|
||||
|
||||
/**
|
||||
* Remove the given event handler from all registered events.
|
||||
* @param handler - the handler to remove
|
||||
*/
|
||||
off(handler: (...args: unknown[]) => void): this;
|
||||
|
||||
/**
|
||||
* Trigger an event.
|
||||
* @param name - a single event name to trigger
|
||||
* @param eventObj - an object to pass to the event handler
|
||||
*/
|
||||
trigger(name: string, eventObj?: unknown): this;
|
||||
}
|
||||
|
||||
/** A ClayItem represents a single config component in the config page */
|
||||
interface ClayItem extends ClayEvents {
|
||||
/** The item's id from the config, or null */
|
||||
id: string | null;
|
||||
|
||||
/** The item's messageKey from the config, or null */
|
||||
messageKey: string | null;
|
||||
|
||||
/** The raw config for this item */
|
||||
config: ClayConfigItem;
|
||||
|
||||
/** The root DOM element wrapper */
|
||||
$element: M;
|
||||
|
||||
/** The manipulator target DOM element wrapper */
|
||||
$manipulatorTarget: M;
|
||||
|
||||
/** The precision for numeric values */
|
||||
precision?: number;
|
||||
|
||||
/**
|
||||
* Run the component initialiser.
|
||||
* @param clay - the ClayConfig instance
|
||||
*/
|
||||
initialize(clay: ClayConfig): ClayItem;
|
||||
|
||||
/** Get the current value of the item via its manipulator */
|
||||
get(): unknown;
|
||||
|
||||
/** Set the value of the item via its manipulator */
|
||||
set(value: unknown): ClayItem;
|
||||
|
||||
/** Disable the item */
|
||||
disable(): ClayItem;
|
||||
|
||||
/** Enable the item */
|
||||
enable(): ClayItem;
|
||||
|
||||
/** Hide the item */
|
||||
hide(): ClayItem;
|
||||
|
||||
/** Show the item */
|
||||
show(): ClayItem;
|
||||
}
|
||||
|
||||
/** ClayConfig lifecycle event names */
|
||||
interface ClayConfigEvents {
|
||||
readonly BEFORE_BUILD: 'BEFORE_BUILD';
|
||||
readonly AFTER_BUILD: 'AFTER_BUILD';
|
||||
readonly BEFORE_DESTROY: 'BEFORE_DESTROY';
|
||||
readonly AFTER_DESTROY: 'AFTER_DESTROY';
|
||||
}
|
||||
|
||||
/** ClayConfig manages the config page and its items */
|
||||
interface ClayConfig extends ClayEvents {
|
||||
/** Meta information from the Pebble object */
|
||||
meta: ClayMeta;
|
||||
|
||||
/** The root container element */
|
||||
$rootContainer: M;
|
||||
|
||||
/** Lifecycle event name constants */
|
||||
EVENTS: ClayConfigEvents;
|
||||
|
||||
/** The config array (may be modified before build) */
|
||||
config: ClayConfigItem | ClayConfigItem[];
|
||||
|
||||
/** Get all items. Must call build() first. */
|
||||
getAllItems(): ClayItem[];
|
||||
|
||||
/** Get an item by its messageKey. Must call build() first. */
|
||||
getItemByMessageKey(messageKey: string): ClayItem;
|
||||
|
||||
/** Get an item by its id. Must call build() first. */
|
||||
getItemById(id: string): ClayItem;
|
||||
|
||||
/** Get all items of a given type. Must call build() first. */
|
||||
getItemsByType(type: string): ClayItem[];
|
||||
|
||||
/** Get all items belonging to a given group. Must call build() first. */
|
||||
getItemsByGroup(group: string): ClayItem[];
|
||||
|
||||
/** Serialise the current settings. Must call build() first. */
|
||||
serialize(): Record<string, { value: unknown; precision?: number }>;
|
||||
|
||||
/** Register a component. Alias for ClayConfig.registerComponent. */
|
||||
registerComponent(component: ClayComponent): boolean;
|
||||
|
||||
/** Destroy the config page and reset items. */
|
||||
destroy(): ClayConfig;
|
||||
|
||||
/** Build the config page. Must be called before get methods. */
|
||||
build(): ClayConfig;
|
||||
}
|
||||
|
||||
interface ClayConfigConstructor {
|
||||
new (
|
||||
settings: Record<string, unknown>,
|
||||
config: ClayConfigItem | ClayConfigItem[],
|
||||
$rootContainer: M,
|
||||
meta: ClayMeta
|
||||
): ClayConfig;
|
||||
|
||||
/**
|
||||
* Register a component to Clay. Must be called before build().
|
||||
*/
|
||||
registerComponent(component: ClayComponent): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main Clay constructor.
|
||||
*
|
||||
* @param config - the Clay config array
|
||||
* @param customFn - custom code to run from the config page
|
||||
* @param options - additional options
|
||||
*/
|
||||
declare class Clay {
|
||||
constructor(
|
||||
config: ClayConfigItem[],
|
||||
customFn?: ((this: ClayConfig) => void) | null,
|
||||
options?: ClayOptions
|
||||
);
|
||||
|
||||
/** The Clay config array */
|
||||
config: ClayConfigItem[];
|
||||
|
||||
/** The custom function */
|
||||
customFn: (this: ClayConfig) => void;
|
||||
|
||||
/** Registered components */
|
||||
components: Record<string, ClayComponent>;
|
||||
|
||||
/** Meta information populated from the Pebble object */
|
||||
meta: ClayMeta;
|
||||
|
||||
/** The Clay version string */
|
||||
version: string;
|
||||
|
||||
/**
|
||||
* Register a component to Clay.
|
||||
* @param component - the clay component to register
|
||||
*/
|
||||
registerComponent(component: ClayComponent): void;
|
||||
|
||||
/**
|
||||
* Generate the Data URI used by the config page with settings injected.
|
||||
*/
|
||||
generateUrl(): string;
|
||||
|
||||
/**
|
||||
* Parse the response from the webviewclosed event data.
|
||||
* @param response - the response string
|
||||
* @param convert - if false, return raw settings without conversion
|
||||
*/
|
||||
getSettings(response: string, convert?: boolean): Record<string, unknown>;
|
||||
|
||||
/**
|
||||
* Update settings with the given key/value pair.
|
||||
* @param key - the setting key
|
||||
* @param value - the setting value
|
||||
*/
|
||||
setSettings(key: string, value: unknown): void;
|
||||
|
||||
/**
|
||||
* Update settings with the given object.
|
||||
* @param settings - an object of key/value pairs to set
|
||||
*/
|
||||
setSettings(settings: Record<string, unknown>): void;
|
||||
|
||||
/**
|
||||
* Encode content as a data URI.
|
||||
* @param input - the content to encode
|
||||
* @param prefix - the URI prefix
|
||||
*/
|
||||
static encodeDataUri(input: string, prefix?: string): string;
|
||||
|
||||
/**
|
||||
* Convert a value to a type compatible with Pebble.sendAppMessage().
|
||||
*/
|
||||
static prepareForAppMessage(
|
||||
val: unknown
|
||||
): number | string | (number | string)[];
|
||||
|
||||
/**
|
||||
* Convert Clay settings to a format compatible with Pebble.sendAppMessage().
|
||||
*/
|
||||
static prepareSettingsForAppMessage(
|
||||
settings: Record<string, unknown>
|
||||
): Record<number, number | string>;
|
||||
}
|
||||
|
||||
declare namespace Clay {
|
||||
export {
|
||||
ClayConfigItem,
|
||||
ClayComponent,
|
||||
ClayManipulator,
|
||||
ClayMeta,
|
||||
PebbleActiveWatchInfo,
|
||||
ClayOptions,
|
||||
ClayEvents,
|
||||
ClayItem,
|
||||
ClayConfig,
|
||||
ClayConfigEvents,
|
||||
ClayConfigConstructor,
|
||||
M,
|
||||
};
|
||||
}
|
||||
|
||||
export = Clay;
|
||||
@@ -210,9 +210,40 @@ Clay.prototype.getSettings = function(response, convert) {
|
||||
|
||||
localStorage.setItem('clay-settings', JSON.stringify(settingsStorage));
|
||||
|
||||
return convert === false ?
|
||||
settings :
|
||||
Clay.prepareSettingsForAppMessage(settings, messageKeys);
|
||||
return convert === false ? settings : Clay.prepareSettingsForAppMessage(settings);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the settings with the given value(s).
|
||||
*
|
||||
* @signature `clay.setSettings(key, value)`
|
||||
* @param {String} key - The property to set.
|
||||
* @param {*} value - the value assigned to _key_.
|
||||
* @return {undefined}
|
||||
*
|
||||
* @signature `clay.setSettings(settings)`
|
||||
* @param {Object} settings - an object containing the key/value pairs to be set.
|
||||
* @return {undefined}
|
||||
*/
|
||||
Clay.prototype.setSettings = function(key, value) {
|
||||
var settingsStorage = {};
|
||||
|
||||
try {
|
||||
settingsStorage = JSON.parse(localStorage.getItem('clay-settings')) || {};
|
||||
} catch (e) {
|
||||
console.error(e.toString());
|
||||
}
|
||||
|
||||
if (typeof key === 'object') {
|
||||
var settings = key;
|
||||
Object.keys(settings).forEach(function(key) {
|
||||
settingsStorage[key] = settings[key];
|
||||
});
|
||||
} else {
|
||||
settingsStorage[key] = value;
|
||||
}
|
||||
|
||||
localStorage.setItem('clay-settings', JSON.stringify(settingsStorage));
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -230,8 +261,8 @@ Clay.encodeDataUri = function(input, prefix) {
|
||||
* - Strings will be returned without modification
|
||||
* - Numbers will be returned without modification
|
||||
* - Booleans will be converted to a 0 or 1
|
||||
* - Arrays that contain strings will be split with a zero.
|
||||
* eg: ['one', 'two'] becomes ['one', 0, 'two', 0]
|
||||
* - Arrays that contain strings will be returned without modification
|
||||
* eg: ['one', 'two'] becomes ['one', 'two']
|
||||
* - Arrays that contain numbers will be returned without modification
|
||||
* eg: [1, 2] becomes [1, 2]
|
||||
* - Arrays that contain booleans will be converted to a 0 or 1
|
||||
@@ -239,7 +270,7 @@ Clay.encodeDataUri = function(input, prefix) {
|
||||
* - Arrays must be single dimensional
|
||||
* - Objects that have a "value" property will apply the above rules to the type of
|
||||
* value. If the value is a number or an array of numbers and the optional
|
||||
* property: "precision" is provided, then the number will be multipled by 10 to
|
||||
* property: "precision" is provided, then the number will be multiplied by 10 to
|
||||
* the power of precision (value * 10 ^ precision) and then floored.
|
||||
* Eg: 1.4567 with a precision set to 3 will become 1456
|
||||
* @param {number|string|boolean|Array|Object} val
|
||||
|
||||
Generated
+13777
File diff suppressed because it is too large
Load Diff
+36
-28
@@ -1,13 +1,16 @@
|
||||
{
|
||||
"name": "pebble-clay",
|
||||
"version": "1.0.0",
|
||||
"name": "@rebble/clay",
|
||||
"version": "1.1.0",
|
||||
"description": "Pebble Config Framework",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"test-travis": "./node_modules/.bin/gulp && ./node_modules/.bin/karma start ./test/karma.conf.js --single-run --browsers chromeTravisCI && ./node_modules/.bin/eslint ./",
|
||||
"test-travis": "./node_modules/.bin/gulp && ./node_modules/.bin/karma start ./test/karma.conf.js --single-run --browsers chromeTravisCI",
|
||||
"test-debug": "(export DEBUG=true && ./node_modules/.bin/gulp && ./node_modules/.bin/karma start ./test/karma.conf.js --no-single-run)",
|
||||
"test": "./node_modules/.bin/gulp && ./node_modules/.bin/karma start ./test/karma.conf.js --single-run",
|
||||
"lint": "./node_modules/.bin/eslint ./",
|
||||
"build": "gulp",
|
||||
"build:types": "tsc -p tsconfig.declarations.json",
|
||||
"check:types": "tsc -p tsconfig.typecheck.json",
|
||||
"dev": "gulp dev",
|
||||
"pebble-clean": "rm -rf tmp src/js/index.js && pebble clean",
|
||||
"pebble-publish": "npm run pebble-clean && npm run build && pebble build && pebble package publish && npm run pebble-clean",
|
||||
@@ -15,7 +18,7 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pebble/clay.git"
|
||||
"url": "git+https://github.com/pebble-dev/clay.git"
|
||||
},
|
||||
"keywords": [
|
||||
"pebble",
|
||||
@@ -26,7 +29,7 @@
|
||||
"author": "Pebble Technology",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pebble/clay/issues"
|
||||
"url": "https://github.com/pebble-dev/clay/issues"
|
||||
},
|
||||
"pebble": {
|
||||
"projectType": "package",
|
||||
@@ -36,18 +39,23 @@
|
||||
"basalt",
|
||||
"chalk",
|
||||
"diorite",
|
||||
"emery"
|
||||
"emery",
|
||||
"flint",
|
||||
"gabbro"
|
||||
],
|
||||
"resources": {
|
||||
"media": []
|
||||
}
|
||||
},
|
||||
"capabilities": [
|
||||
"configurable"
|
||||
]
|
||||
},
|
||||
"homepage": "https://github.com/pebble/clay#readme",
|
||||
"homepage": "https://github.com/pebble-dev/clay#readme",
|
||||
"devDependencies": {
|
||||
"autoprefixer": "^6.3.1",
|
||||
"autoprefixer": "^10.4.23",
|
||||
"bourbon": "^4.2.6",
|
||||
"browserify": "^13.0.0",
|
||||
"browserify-istanbul": "^0.2.1",
|
||||
"browserify-istanbul": "^3.0.1",
|
||||
"chai": "^3.4.1",
|
||||
"deamdify": "^0.2.0",
|
||||
"deepcopy": "^0.6.1",
|
||||
@@ -55,34 +63,34 @@
|
||||
"eslint": "^1.5.1",
|
||||
"eslint-config-pebble": "^1.2.0",
|
||||
"eslint-plugin-standard": "^1.3.1",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp": "^5.0.1",
|
||||
"gulp-autoprefixer": "^3.1.0",
|
||||
"gulp-htmlmin": "^1.3.0",
|
||||
"gulp-inline": "0.0.15",
|
||||
"gulp-inline": "^0.1.3",
|
||||
"gulp-insert": "^0.5.0",
|
||||
"gulp-sass": "^2.1.1",
|
||||
"gulp-sass": "^6.0.1",
|
||||
"gulp-sourcemaps": "^1.6.0",
|
||||
"gulp-uglify": "^1.5.2",
|
||||
"joi": "^6.10.1",
|
||||
"karma": "^0.13.19",
|
||||
"karma-browserify": "^5.0.1",
|
||||
"karma-chrome-launcher": "^0.2.2",
|
||||
"karma-coverage": "^0.5.3",
|
||||
"karma-mocha": "^0.2.1",
|
||||
"karma-mocha-reporter": "^1.1.5",
|
||||
"karma-source-map-support": "^1.1.0",
|
||||
"karma": "^6.4.0",
|
||||
"karma-browserify": "^8.1.0",
|
||||
"karma-chrome-launcher": "^3.2.0",
|
||||
"karma-coverage": "^2.2.1",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"karma-mocha-reporter": "^2.2.5",
|
||||
"karma-source-map-support": "^1.4.0",
|
||||
"karma-threshold-reporter": "^0.1.15",
|
||||
"mocha": "^2.3.4",
|
||||
"postcss": "^5.0.14",
|
||||
"require-from-string": "^1.1.0",
|
||||
"sassify": "^0.9.1",
|
||||
"mocha": "^11.7.5",
|
||||
"postcss": "8.5.6",
|
||||
"require-from-string": "^2.0.2",
|
||||
"sass": "^1.94.2",
|
||||
"sinon": "^1.17.3",
|
||||
"stringify": "^3.2.0",
|
||||
"through": "^2.3.8",
|
||||
"tosource": "^1.0.0",
|
||||
"typescript": "6.0.2",
|
||||
"vinyl-buffer": "^1.0.0",
|
||||
"vinyl-source-stream": "^1.1.0",
|
||||
"watchify": "^3.7.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
"vinyl-source-stream": "^2.0.0",
|
||||
"watchify": "^3.11.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module.exports = {
|
||||
name: 'button',
|
||||
template: require('../../templates/components/button.tpl'),
|
||||
style: require('../../styles/clay/components/button.scss'),
|
||||
style: require('../../../tmp/button.css'),
|
||||
manipulator: 'button',
|
||||
defaults: {
|
||||
primary: false,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module.exports = {
|
||||
name: 'checkboxgroup',
|
||||
template: require('../../templates/components/checkboxgroup.tpl'),
|
||||
style: require('../../styles/clay/components/checkboxgroup.scss'),
|
||||
style: require('../../../tmp/checkboxgroup.css'),
|
||||
manipulator: 'checkboxgroup',
|
||||
defaults: {
|
||||
label: '',
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module.exports = {
|
||||
name: 'color',
|
||||
template: require('../../templates/components/color.tpl'),
|
||||
style: require('../../styles/clay/components/color.scss'),
|
||||
style: require('../../../tmp/color.css'),
|
||||
manipulator: 'color',
|
||||
defaults: {
|
||||
label: '',
|
||||
@@ -114,14 +114,16 @@ module.exports = {
|
||||
* @returns {Array}
|
||||
*/
|
||||
function autoLayout() {
|
||||
var bwWatches = ['aplite', 'diorite', 'flint'];
|
||||
if (!clay.meta.activeWatchInfo ||
|
||||
clay.meta.activeWatchInfo.firmware.major === 2 ||
|
||||
clay.meta.activeWatchInfo.platform === 'aplite' &&
|
||||
bwWatches.indexOf(clay.meta.activeWatchInfo.platform) > -1 &&
|
||||
!self.config.allowGray) {
|
||||
return standardLayouts.BLACK_WHITE;
|
||||
}
|
||||
|
||||
if (clay.meta.activeWatchInfo.platform === 'aplite' && self.config.allowGray) {
|
||||
if (bwWatches.indexOf(clay.meta.activeWatchInfo.platform) > -1 &&
|
||||
self.config.allowGray) {
|
||||
return standardLayouts.GRAY;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
module.exports = {
|
||||
name: 'input',
|
||||
template: require('../../templates/components/input.tpl'),
|
||||
style: require('../../styles/clay/components/input.scss'),
|
||||
style: require('../../../tmp/input.css'),
|
||||
manipulator: 'val',
|
||||
defaults: {
|
||||
label: '',
|
||||
serializeValueAs: 'string',
|
||||
description: '',
|
||||
attributes: {}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
module.exports = {
|
||||
name: 'radiogroup',
|
||||
template: require('../../templates/components/radiogroup.tpl'),
|
||||
style: require('../../styles/clay/components/radiogroup.scss'),
|
||||
style: require('../../../tmp/radiogroup.css'),
|
||||
manipulator: 'radiogroup',
|
||||
defaults: {
|
||||
label: '',
|
||||
options: [],
|
||||
serializeValueAs: 'string',
|
||||
description: '',
|
||||
attributes: {}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
module.exports = {
|
||||
name: 'select',
|
||||
template: require('../../templates/components/select.tpl'),
|
||||
style: require('../../styles/clay/components/select.scss'),
|
||||
style: require('../../../tmp/select.css'),
|
||||
manipulator: 'val',
|
||||
defaults: {
|
||||
label: '',
|
||||
options: [],
|
||||
serializeValueAs: 'string',
|
||||
description: '',
|
||||
attributes: {}
|
||||
},
|
||||
@@ -17,7 +18,7 @@ module.exports = {
|
||||
var $value = self.$element.select('.value');
|
||||
|
||||
/**
|
||||
* Updates the HTML value of the component to match the slected option's label
|
||||
* Updates the HTML value of the component to match the selected option's label
|
||||
* @return {void}
|
||||
*/
|
||||
function setValueDisplay() {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module.exports = {
|
||||
name: 'slider',
|
||||
template: require('../../templates/components/slider.tpl'),
|
||||
style: require('../../styles/clay/components/slider.scss'),
|
||||
style: require('../../../tmp/slider.css'),
|
||||
manipulator: 'slider',
|
||||
defaults: {
|
||||
label: '',
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module.exports = {
|
||||
name: 'submit',
|
||||
template: require('../../templates/components/submit.tpl'),
|
||||
style: require('../../styles/clay/components/submit.scss'),
|
||||
style: require('../../../tmp/submit.css'),
|
||||
manipulator: 'button',
|
||||
defaults: {
|
||||
attributes: {}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module.exports = {
|
||||
name: 'toggle',
|
||||
template: require('../../templates/components/toggle.tpl'),
|
||||
style: require('../../styles/clay/components/toggle.scss'),
|
||||
style: require('../../../tmp/toggle.css'),
|
||||
manipulator: 'checked',
|
||||
defaults: {
|
||||
label: '',
|
||||
|
||||
@@ -86,9 +86,9 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
// set the value of the item via the manipulator to ensure consistency
|
||||
var value = typeof _settings[_item.messageKey] !== 'undefined' ?
|
||||
_settings[_item.messageKey] :
|
||||
(_item.defaultValue || '');
|
||||
_item.defaultValue;
|
||||
|
||||
clayItem.set(value);
|
||||
clayItem.set(typeof value !== 'undefined' ? value : '');
|
||||
|
||||
$container.add(clayItem.$element);
|
||||
}
|
||||
@@ -182,6 +182,17 @@ function ClayConfig(settings, config, $rootContainer, meta) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} group
|
||||
* @returns {Array.<ClayItem>}
|
||||
*/
|
||||
self.getItemsByGroup = function(group) {
|
||||
_checkBuilt('getItemsByGroup');
|
||||
return _items.filter(function(item) {
|
||||
return item.config.group === group;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
@@ -73,10 +73,19 @@ module.exports = {
|
||||
},
|
||||
val: {
|
||||
get: function() {
|
||||
return this.$manipulatorTarget.get('value');
|
||||
let value = this.$manipulatorTarget.get('value');
|
||||
switch (this.config.serializeValueAs) {
|
||||
case 'integer':
|
||||
let integerValue = Math.trunc(Number.parseInt(value, 10));
|
||||
return Number.isNaN(integerValue) ? 0 : integerValue;
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
},
|
||||
set: function(value) {
|
||||
if (this.get() === value.toString(10)) { return this; }
|
||||
let currentValue = this.$manipulatorTarget.get('value');
|
||||
if (typeof currentValue !== 'undefined' &&
|
||||
currentValue === value.toString(10)) { return this; }
|
||||
this.$manipulatorTarget.set('value', value);
|
||||
return this.trigger('change');
|
||||
},
|
||||
@@ -116,12 +125,21 @@ module.exports = {
|
||||
},
|
||||
radiogroup: {
|
||||
get: function() {
|
||||
return this.$element.select('input:checked').get('value');
|
||||
let value = this.$element.select('input:checked').get('value');
|
||||
switch (this.config.serializeValueAs) {
|
||||
case 'integer':
|
||||
let integerValue = Math.trunc(Number.parseInt(value, 10));
|
||||
return Number.isNaN(integerValue) ? 0 : integerValue;
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
},
|
||||
set: function(value) {
|
||||
if (this.get() === value.toString(10)) { return this; }
|
||||
let currentValue = this.$element.select('input:checked').get('value');
|
||||
if (typeof currentValue !== 'undefined' &&
|
||||
currentValue === value.toString(10)) { return this; }
|
||||
this.$element
|
||||
.select('input[value="' + value.replace('"', '\\"') + '"]')
|
||||
.select('input[value="' + value.toString(10).replace('"', '\\"') + '"]')
|
||||
.set('checked', true);
|
||||
return this.trigger('change');
|
||||
},
|
||||
|
||||
@@ -44,21 +44,41 @@ module.exports.capabilityMap = {
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
PLATFORM_FLINT: {
|
||||
platforms: ['flint'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
PLATFORM_GABBRO: {
|
||||
platforms: ['gabbro'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
BW: {
|
||||
platforms: ['aplite', 'diorite'],
|
||||
platforms: ['aplite', 'diorite', 'flint'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
COLOR: {
|
||||
platforms: ['basalt', 'chalk', 'emery'],
|
||||
platforms: ['basalt', 'chalk', 'emery', 'gabbro'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
COMPASS: {
|
||||
platforms: ['aplite', 'basalt', 'chalk', 'emery', 'flint', 'gabbro'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
MICROPHONE: {
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery', 'flint', 'gabbro'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
RGB_BACKLIGHT: {
|
||||
platforms: ['emery'],
|
||||
minFwMajor: 4,
|
||||
minFwMinor: 9
|
||||
},
|
||||
SMARTSTRAP: {
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
|
||||
minFwMajor: 3,
|
||||
@@ -69,23 +89,33 @@ module.exports.capabilityMap = {
|
||||
minFwMajor: 3,
|
||||
minFwMinor: 4
|
||||
},
|
||||
SPEAKER: {
|
||||
platforms: ['emery', 'flint'],
|
||||
minFwMajor: 4,
|
||||
minFwMinor: 9
|
||||
},
|
||||
TOUCH: {
|
||||
platforms: ['emery', 'gabbro'],
|
||||
minFwMajor: 4,
|
||||
minFwMinor: 9
|
||||
},
|
||||
HEALTH: {
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
|
||||
platforms: ['basalt', 'chalk', 'diorite', 'emery', 'flint', 'gabbro'],
|
||||
minFwMajor: 3,
|
||||
minFwMinor: 10
|
||||
},
|
||||
RECT: {
|
||||
platforms: ['aplite', 'basalt', 'diorite', 'emery'],
|
||||
platforms: ['aplite', 'basalt', 'diorite', 'emery', 'flint'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
ROUND: {
|
||||
platforms: ['chalk'],
|
||||
platforms: ['chalk', 'gabbro'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
DISPLAY_144x168: {
|
||||
platforms: ['aplite', 'basalt', 'diorite'],
|
||||
platforms: ['aplite', 'basalt', 'diorite', 'flint'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
@@ -98,6 +128,11 @@ module.exports.capabilityMap = {
|
||||
platforms: ['emery'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
},
|
||||
DISPLAY_260x260_ROUND: {
|
||||
platforms: ['gabbro'],
|
||||
minFwMajor: 0,
|
||||
minFwMinor: 0
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+1
-15
@@ -24,24 +24,10 @@ module.exports = function(config) {
|
||||
[
|
||||
'stringify',
|
||||
{
|
||||
extensions: ['.html', '.tpl']
|
||||
extensions: ['.html', '.tpl', '.css']
|
||||
}
|
||||
],
|
||||
'deamdify',
|
||||
[
|
||||
'sassify',
|
||||
{
|
||||
base64Encode: false,
|
||||
sourceMap: false,
|
||||
sourceMapEmbed: false,
|
||||
sourceMapContents: false,
|
||||
outputStyle: 'compact',
|
||||
includePaths: [].concat(
|
||||
require('bourbon').includePaths,
|
||||
'src/styles'
|
||||
)
|
||||
}
|
||||
],
|
||||
[
|
||||
'browserify-istanbul',
|
||||
{
|
||||
|
||||
@@ -434,6 +434,72 @@ describe('component - color', function() {
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('diorite', standardLayouts.BLACK_WHITE, false, '', {
|
||||
platform: 'diorite',
|
||||
model: 'qemu_platform_diorite',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 4,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('diorite', standardLayouts.GRAY, true, '', {
|
||||
platform: 'diorite',
|
||||
model: 'qemu_platform_diorite',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 4,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('emery', standardLayouts.COLOR, true, '', {
|
||||
platform: 'emery',
|
||||
model: 'qemu_platform_emery',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 4,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('flint', standardLayouts.BLACK_WHITE, false, '', {
|
||||
platform: 'flint',
|
||||
model: 'qemu_platform_flint',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 4,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('flint', standardLayouts.GRAY, true, '', {
|
||||
platform: 'flint',
|
||||
model: 'qemu_platform_flint',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 4,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
testAutoLayout('gabbro', standardLayouts.COLOR, true, '', {
|
||||
platform: 'gabbro',
|
||||
model: 'qemu_platform_gabbro',
|
||||
language: 'en_US',
|
||||
firmware: {
|
||||
major: 4,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
suffix: ''
|
||||
}
|
||||
});
|
||||
|
||||
testCustomLayout();
|
||||
testCustomLayout('COLOR');
|
||||
|
||||
@@ -386,6 +386,54 @@ describe('Clay', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setSettings', function() {
|
||||
it('it writes to localStorage when passing an object',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
var settings = {
|
||||
key1: 'value1',
|
||||
key2: 'value2'
|
||||
};
|
||||
var expected = {
|
||||
key1: 'value1',
|
||||
key2: 'value2'
|
||||
};
|
||||
|
||||
clay.setSettings(settings);
|
||||
assert.equal(
|
||||
localStorage.getItem('clay-settings'),
|
||||
JSON.stringify(expected)
|
||||
);
|
||||
});
|
||||
|
||||
it('it writes to localStorage when passing a key and a value',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
var expected = {
|
||||
key1: 'value1',
|
||||
key2: 'value2%7Dbreaks'
|
||||
};
|
||||
|
||||
clay.setSettings('key1', 'value1');
|
||||
clay.setSettings('key2', 'value2%7Dbreaks');
|
||||
assert.equal(localStorage.getItem('clay-settings'),
|
||||
JSON.stringify(expected)
|
||||
);
|
||||
});
|
||||
|
||||
it('doesn\'t throw and logs an error if settings in localStorage are broken',
|
||||
function() {
|
||||
var clay = fixture.clay([]);
|
||||
var errorStub = sinon.stub(console, 'error');
|
||||
localStorage.setItem('clay-settings', 'not valid JSON');
|
||||
assert.doesNotThrow(function() {
|
||||
clay.setSettings('key', 'value');
|
||||
});
|
||||
assert(errorStub.calledWithMatch(/SyntaxError/i));
|
||||
errorStub.restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('.meta', function() {
|
||||
var emptyMeta = {
|
||||
activeWatchInfo: null,
|
||||
|
||||
@@ -15,6 +15,7 @@ describe('ClayConfig', function() {
|
||||
'getItemByMessageKey',
|
||||
'getItemById',
|
||||
'getItemsByType',
|
||||
'getItemsByGroup',
|
||||
'serialize',
|
||||
'registerComponent',
|
||||
'build',
|
||||
@@ -77,28 +78,39 @@ describe('ClayConfig', function() {
|
||||
describe('capability filtering', function() {
|
||||
testCapabilities('aplite', 2, 9, ['BW'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['COLOR'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['COMPASS'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['MICROPHONE'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['RGB_BACKLIGHT'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['SPEAKER'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['TOUCH'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['HEALTH'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['RECT'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['ROUND'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['DISPLAY_260x260_ROUND'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_APLITE'], 1);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_EMERY'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_FLINT'], 0);
|
||||
testCapabilities('aplite', 2, 9, ['PLATFORM_GABBRO'], 0);
|
||||
|
||||
testCapabilities('aplite', 3, 10, ['BW'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['COLOR'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['COMPASS'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['MICROPHONE'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['RGB_BACKLIGHT'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 3, 4, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['SPEAKER'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['TOUCH'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['HEALTH'], 0);
|
||||
testCapabilities('aplite', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['RECT'], 1);
|
||||
@@ -106,21 +118,28 @@ describe('ClayConfig', function() {
|
||||
testCapabilities('aplite', 3, 10, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['DISPLAY_260x260_ROUND'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_APLITE'], 1);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_FLINT'], 0);
|
||||
testCapabilities('aplite', 3, 10, ['PLATFORM_GABBRO'], 0);
|
||||
|
||||
testCapabilities('basalt', 3, 10, ['BW'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['COLOR'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['COMPASS'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('basalt', 3, 3, ['RGB_BACKLIGHT'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('basalt', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('basalt', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('basalt', 3, 4, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('basalt', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('basalt', 3, 3, ['SPEAKER'], 0);
|
||||
testCapabilities('basalt', 3, 3, ['TOUCH'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('basalt', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['RECT'], 1);
|
||||
@@ -128,21 +147,28 @@ describe('ClayConfig', function() {
|
||||
testCapabilities('basalt', 3, 10, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['DISPLAY_260x260_ROUND'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_BASALT'], 1);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_FLINT'], 0);
|
||||
testCapabilities('basalt', 3, 10, ['PLATFORM_GABBRO'], 0);
|
||||
|
||||
testCapabilities('chalk', 3, 10, ['BW'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['COLOR'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['COMPASS'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('chalk', 3, 3, ['RGB_BACKLIGHT'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('chalk', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('chalk', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('chalk', 3, 4, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('chalk', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('chalk', 3, 3, ['SPEAKER'], 0);
|
||||
testCapabilities('chalk', 3, 3, ['TOUCH'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('chalk', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['RECT'], 0);
|
||||
@@ -150,21 +176,28 @@ describe('ClayConfig', function() {
|
||||
testCapabilities('chalk', 3, 10, ['DISPLAY_144x168'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['DISPLAY_180x180_ROUND'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['DISPLAY_260x260_ROUND'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_CHALK'], 1);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_FLINT'], 0);
|
||||
testCapabilities('chalk', 3, 10, ['PLATFORM_GABBRO'], 0);
|
||||
|
||||
testCapabilities('diorite', 3, 10, ['BW'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['COLOR'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['COMPASS'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('diorite', 3, 3, ['RGB_BACKLIGHT'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('diorite', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('diorite', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('diorite', 3, 4, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('diorite', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('diorite', 3, 3, ['SPEAKER'], 0);
|
||||
testCapabilities('diorite', 3, 3, ['TOUCH'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('diorite', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['RECT'], 1);
|
||||
@@ -172,21 +205,28 @@ describe('ClayConfig', function() {
|
||||
testCapabilities('diorite', 3, 10, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['DISPLAY_260x260_ROUND'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_DIORITE'], 1);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_FLINT'], 0);
|
||||
testCapabilities('diorite', 3, 10, ['PLATFORM_GABBRO'], 0);
|
||||
|
||||
testCapabilities('emery', 3, 10, ['BW'], 0);
|
||||
testCapabilities('emery', 3, 10, ['COLOR'], 1);
|
||||
testCapabilities('emery', 3, 10, ['COMPASS'], 1);
|
||||
testCapabilities('emery', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('emery', 4, 10, ['RGB_BACKLIGHT'], 1);
|
||||
testCapabilities('emery', 3, 10, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('emery', 3, 4, ['SMARTSTRAP'], 1);
|
||||
testCapabilities('emery', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('emery', 3, 10, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('emery', 3, 4, ['SMARTSTRAP_POWER'], 1);
|
||||
testCapabilities('emery', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('emery', 4, 10, ['SPEAKER'], 1);
|
||||
testCapabilities('emery', 4, 10, ['TOUCH'], 1);
|
||||
testCapabilities('emery', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('emery', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('emery', 3, 10, ['RECT'], 1);
|
||||
@@ -194,11 +234,67 @@ describe('ClayConfig', function() {
|
||||
testCapabilities('emery', 3, 10, ['DISPLAY_144x168'], 0);
|
||||
testCapabilities('emery', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('emery', 3, 10, ['DISPLAY_200x228'], 1);
|
||||
testCapabilities('emery', 3, 10, ['DISPLAY_260x260_ROUND'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_EMERY'], 1);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_FLINT'], 0);
|
||||
testCapabilities('emery', 3, 10, ['PLATFORM_GABBRO'], 0);
|
||||
|
||||
testCapabilities('flint', 3, 10, ['BW'], 1);
|
||||
testCapabilities('flint', 3, 10, ['COLOR'], 0);
|
||||
testCapabilities('flint', 3, 10, ['COMPASS'], 1);
|
||||
testCapabilities('flint', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('flint', 3, 3, ['RGB_BACKLIGHT'], 0);
|
||||
testCapabilities('flint', 3, 10, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('flint', 3, 4, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('flint', 3, 3, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('flint', 3, 10, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('flint', 3, 4, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('flint', 3, 3, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('flint', 4, 10, ['SPEAKER'], 1);
|
||||
testCapabilities('flint', 4, 10, ['TOUCH'], 0);
|
||||
testCapabilities('flint', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('flint', 3, 9, ['HEALTH'], 0);
|
||||
testCapabilities('flint', 3, 10, ['RECT'], 1);
|
||||
testCapabilities('flint', 3, 10, ['ROUND'], 0);
|
||||
testCapabilities('flint', 3, 10, ['DISPLAY_144x168'], 1);
|
||||
testCapabilities('flint', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('flint', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('flint', 3, 10, ['DISPLAY_260x260_ROUND'], 0);
|
||||
testCapabilities('flint', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('flint', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('flint', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('flint', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('flint', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
testCapabilities('flint', 3, 10, ['PLATFORM_FLINT'], 1);
|
||||
testCapabilities('flint', 3, 10, ['PLATFORM_GABBRO'], 0);
|
||||
|
||||
testCapabilities('gabbro', 3, 10, ['BW'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['COLOR'], 1);
|
||||
testCapabilities('gabbro', 3, 10, ['COMPASS'], 1);
|
||||
testCapabilities('gabbro', 3, 10, ['MICROPHONE'], 1);
|
||||
testCapabilities('gabbro', 3, 10, ['RGB_BACKLIGHT'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['SMARTSTRAP'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['SMARTSTRAP_POWER'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['SPEAKER'], 0);
|
||||
testCapabilities('gabbro', 4, 10, ['TOUCH'], 1);
|
||||
testCapabilities('gabbro', 3, 10, ['HEALTH'], 1);
|
||||
testCapabilities('gabbro', 3, 10, ['RECT'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['ROUND'], 1);
|
||||
testCapabilities('gabbro', 3, 10, ['DISPLAY_144x168'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['DISPLAY_180x180_ROUND'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['DISPLAY_200x228'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['DISPLAY_260x260_ROUND'], 1);
|
||||
testCapabilities('gabbro', 3, 10, ['PLATFORM_APLITE'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['PLATFORM_BASALT'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['PLATFORM_CHALK'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['PLATFORM_DIORITE'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['PLATFORM_EMERY'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['PLATFORM_FLINT'], 0);
|
||||
testCapabilities('gabbro', 3, 10, ['PLATFORM_GABBRO'], 1);
|
||||
|
||||
testCapabilities('aplite', 3, 10, ['BW', 'HEALTH'], 0, 0);
|
||||
testCapabilities('emery', 3, 10, ['COLOR', 'HEALTH'], 1);
|
||||
@@ -224,6 +320,7 @@ describe('ClayConfig', function() {
|
||||
'getItemByMessageKey',
|
||||
'getItemById',
|
||||
'getItemsByType',
|
||||
'getItemsByGroup',
|
||||
'serialize'
|
||||
].forEach(function(method) {
|
||||
it('.' + method + '()', function() {
|
||||
@@ -287,6 +384,25 @@ describe('ClayConfig', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getItemsByGroup()', function() {
|
||||
it('it returns the correct items', function() {
|
||||
var config = fixtures.config([
|
||||
{type: 'input', id: 'g1-0', group: 'group1'},
|
||||
{type: 'text', id: 'g2-0', group: 'group2'},
|
||||
{type: 'input', id: 'g1-1', group: 'group1'}
|
||||
]);
|
||||
|
||||
var clayConfig = fixtures.clayConfig(config);
|
||||
assert.deepEqual(clayConfig.getItemsByGroup('group1'), [
|
||||
clayConfig.getItemById('g1-0'),
|
||||
clayConfig.getItemById('g1-1')
|
||||
]);
|
||||
assert.deepEqual(clayConfig.getItemsByGroup('group2'), [
|
||||
clayConfig.getItemById('g2-0')
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.serialize()', function() {
|
||||
it('returns the correct settings', function() {
|
||||
var config = [
|
||||
|
||||
@@ -161,13 +161,63 @@ describe('manipulators', function() {
|
||||
});
|
||||
|
||||
describe('val', function() {
|
||||
var type = 'input';
|
||||
testSetGet(type, 'test321');
|
||||
testSetGet(type, 1234, '1234');
|
||||
testDisable(type);
|
||||
testEnable(type);
|
||||
testShow(type);
|
||||
testHide(type);
|
||||
let stringInputType = {
|
||||
type: 'input',
|
||||
serializeValueAs: 'string'
|
||||
};
|
||||
|
||||
let integerInputType = {
|
||||
type: 'input',
|
||||
serializeValueAs: 'integer'
|
||||
};
|
||||
|
||||
let stringSelectType = {
|
||||
type: 'select',
|
||||
defaultValue: 'value-1',
|
||||
options: [
|
||||
{ label: 'label 1', value: '1' },
|
||||
{ label: 'label 2', value: '2' }],
|
||||
serializeValueAs: 'string'
|
||||
};
|
||||
|
||||
let integerSelectType = {
|
||||
type: 'select',
|
||||
defaultValue: 'value-1',
|
||||
options: [
|
||||
{ label: 'label 1', value: '1' },
|
||||
{ label: 'label 2', value: '2' }],
|
||||
serializeValueAs: 'integer'
|
||||
};
|
||||
|
||||
testSetGet(stringInputType, 'test321');
|
||||
testSetGet(stringInputType, 1234, '1234');
|
||||
testSetGet(integerInputType, 'test321', 0);
|
||||
testSetGet(integerInputType, 1234);
|
||||
|
||||
testSetGet(stringSelectType, '1');
|
||||
testSetGet(stringSelectType, 2, '2');
|
||||
testSetGet(integerSelectType, 1);
|
||||
testSetGet(integerSelectType, '2', 2);
|
||||
|
||||
testDisable(stringInputType);
|
||||
testDisable(integerInputType);
|
||||
testDisable(stringSelectType);
|
||||
testDisable(integerSelectType);
|
||||
|
||||
testEnable(stringInputType);
|
||||
testEnable(integerInputType);
|
||||
testEnable(stringSelectType);
|
||||
testEnable(integerSelectType);
|
||||
|
||||
testHide(stringInputType);
|
||||
testHide(integerInputType);
|
||||
testHide(stringSelectType);
|
||||
testHide(integerSelectType);
|
||||
|
||||
testShow(stringInputType);
|
||||
testShow(integerInputType);
|
||||
testShow(stringSelectType);
|
||||
testShow(integerSelectType);
|
||||
});
|
||||
|
||||
describe('slider', function() {
|
||||
@@ -203,22 +253,54 @@ describe('manipulators', function() {
|
||||
});
|
||||
|
||||
describe('radiogroup', function() {
|
||||
var type = {
|
||||
var stringType = {
|
||||
type: 'radiogroup',
|
||||
clayId: 1,
|
||||
options: [
|
||||
{ label: '1', value: 'one' },
|
||||
{ label: '2', value: 'two' },
|
||||
{ label: '3', value: 'three "quote' }
|
||||
]
|
||||
{ label: '3', value: 'three "quote' },
|
||||
{ label: '4', value: 4 },
|
||||
{ label: '5', value: '5 with text after' },
|
||||
{ label: '5', value: '6.5' }
|
||||
],
|
||||
serializeValueAs: 'string'
|
||||
};
|
||||
testSetGet(type, 'one');
|
||||
testSetGet(type, 'two');
|
||||
testSetGet(type, 'three "quote');
|
||||
testDisable(type);
|
||||
testEnable(type);
|
||||
testShow(type);
|
||||
testHide(type);
|
||||
|
||||
var integerType = {
|
||||
type: 'radiogroup',
|
||||
clayId: 1,
|
||||
options: [
|
||||
{ label: '1', value: 'one' },
|
||||
{ label: '2', value: 'two' },
|
||||
{ label: '3', value: 'three "quote' },
|
||||
{ label: '4', value: 4 },
|
||||
{ label: '5', value: '5 with text after' },
|
||||
{ label: '5', value: '6.5' }
|
||||
],
|
||||
serializeValueAs: 'integer'
|
||||
};
|
||||
|
||||
testSetGet(stringType, 'one');
|
||||
testSetGet(stringType, 'two');
|
||||
testSetGet(stringType, 'three "quote');
|
||||
testSetGet(stringType, '4');
|
||||
testSetGet(stringType, '5 with text after');
|
||||
testSetGet(stringType, '6.5');
|
||||
testSetGet(integerType, 'one', 0);
|
||||
testSetGet(integerType, 'two', 0);
|
||||
testSetGet(integerType, 'three "quote', 0);
|
||||
testSetGet(integerType, 4, 4);
|
||||
testSetGet(integerType, '5 with text after', 5);
|
||||
testSetGet(integerType, '6.5', 6);
|
||||
testDisable(stringType);
|
||||
testDisable(integerType);
|
||||
testEnable(stringType);
|
||||
testEnable(integerType);
|
||||
testShow(stringType);
|
||||
testShow(integerType);
|
||||
testHide(stringType);
|
||||
testHide(integerType);
|
||||
});
|
||||
|
||||
describe('checkboxgroup', function() {
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
import Clay = require('../index');
|
||||
|
||||
// --- Exported types are accessible via the Clay namespace ---
|
||||
|
||||
const configItem: Clay.ClayConfigItem = {
|
||||
type: 'input',
|
||||
messageKey: 'name',
|
||||
defaultValue: '',
|
||||
label: 'Name',
|
||||
attributes: { placeholder: 'Enter name' },
|
||||
capabilities: ['COLOR'],
|
||||
group: 'appearance',
|
||||
};
|
||||
|
||||
const meta: Clay.ClayMeta = {
|
||||
activeWatchInfo: {
|
||||
platform: 'basalt',
|
||||
model: 'qemu_platform_basalt',
|
||||
language: 'en_US',
|
||||
firmware: { major: 4, minor: 3, patch: 0, suffix: '' },
|
||||
},
|
||||
accountToken: 'abc',
|
||||
watchToken: 'def',
|
||||
userData: {},
|
||||
};
|
||||
|
||||
const options: Clay.ClayOptions = {
|
||||
autoHandleEvents: true,
|
||||
userData: { foo: 'bar' },
|
||||
};
|
||||
|
||||
const manipulator: Clay.ClayManipulator = {
|
||||
get() { return this.$manipulatorTarget.get('value'); },
|
||||
set(value) {
|
||||
this.$manipulatorTarget.set('value', value);
|
||||
return this;
|
||||
},
|
||||
disable() { return this; },
|
||||
enable() { return this; },
|
||||
hide() { return this; },
|
||||
show() { return this; },
|
||||
};
|
||||
|
||||
const component: Clay.ClayComponent = {
|
||||
name: 'my-component',
|
||||
template: '<div></div>',
|
||||
manipulator,
|
||||
defaults: { label: 'Default' },
|
||||
};
|
||||
|
||||
// --- Constructor ---
|
||||
|
||||
const clay = new Clay(
|
||||
[configItem, { type: 'heading', defaultValue: 'My App' }],
|
||||
function() {
|
||||
// `this` is ClayConfig — verify event methods
|
||||
const self: Clay.ClayConfig = this;
|
||||
|
||||
const handler = (..._args: unknown[]) => {};
|
||||
this.on('AFTER_BUILD', handler);
|
||||
this.off(handler);
|
||||
this.trigger('AFTER_BUILD');
|
||||
|
||||
// Verify chaining returns the same type
|
||||
this.on('BEFORE_BUILD', handler).off(handler);
|
||||
|
||||
// Verify EVENTS constants
|
||||
const events: Clay.ClayConfigEvents = this.EVENTS;
|
||||
const beforeBuild: 'BEFORE_BUILD' = events.BEFORE_BUILD;
|
||||
const afterBuild: 'AFTER_BUILD' = events.AFTER_BUILD;
|
||||
const beforeDestroy: 'BEFORE_DESTROY' = events.BEFORE_DESTROY;
|
||||
const afterDestroy: 'AFTER_DESTROY' = events.AFTER_DESTROY;
|
||||
|
||||
// Verify build/destroy return ClayConfig for chaining
|
||||
this.build().destroy().build();
|
||||
|
||||
// Verify item getters
|
||||
const allItems: Clay.ClayItem[] = this.getAllItems();
|
||||
const byKey: Clay.ClayItem = this.getItemByMessageKey('bg_color');
|
||||
const byId: Clay.ClayItem = this.getItemById('my-id');
|
||||
const byType: Clay.ClayItem[] = this.getItemsByType('color');
|
||||
const byGroup: Clay.ClayItem[] = this.getItemsByGroup('appearance');
|
||||
|
||||
// Verify ClayItem properties
|
||||
const item = byKey;
|
||||
const itemId: string | null = item.id;
|
||||
const itemMsgKey: string | null = item.messageKey;
|
||||
const itemConfig: Clay.ClayConfigItem = item.config;
|
||||
const $el: Clay.M = item.$element;
|
||||
const $target: Clay.M = item.$manipulatorTarget;
|
||||
|
||||
// Verify ClayItem manipulator methods
|
||||
const value: unknown = item.get();
|
||||
const afterSet: Clay.ClayItem = item.set('new value');
|
||||
const afterDisable: Clay.ClayItem = item.disable();
|
||||
const afterEnable: Clay.ClayItem = item.enable();
|
||||
const afterHide: Clay.ClayItem = item.hide();
|
||||
const afterShow: Clay.ClayItem = item.show();
|
||||
|
||||
// Verify ClayItem event methods
|
||||
item.on('change', handler).off(handler);
|
||||
item.trigger('change');
|
||||
|
||||
// Verify ClayItem initialize
|
||||
const afterInit: Clay.ClayItem = item.initialize(this);
|
||||
|
||||
// Verify serialize
|
||||
const serialised: Record<string, { value: unknown; precision?: number }> =
|
||||
this.serialize();
|
||||
|
||||
// Verify meta
|
||||
const configMeta: Clay.ClayMeta = this.meta;
|
||||
|
||||
// Verify registerComponent on instance
|
||||
const registered: boolean = this.registerComponent(component);
|
||||
},
|
||||
options
|
||||
);
|
||||
|
||||
// Constructor with null customFn
|
||||
const clay2 = new Clay([{ type: 'heading' }], null);
|
||||
|
||||
// Constructor with no options
|
||||
const clay3 = new Clay([{ type: 'heading' }]);
|
||||
|
||||
// --- Instance properties ---
|
||||
|
||||
const config: Clay.ClayConfigItem[] = clay.config;
|
||||
const version: string = clay.version;
|
||||
const components: Record<string, Clay.ClayComponent> = clay.components;
|
||||
const clayMeta: Clay.ClayMeta = clay.meta;
|
||||
const customFn: (this: Clay.ClayConfig) => void = clay.customFn;
|
||||
|
||||
// --- Instance methods ---
|
||||
|
||||
clay.registerComponent(component);
|
||||
|
||||
// String manipulator name
|
||||
clay.registerComponent({
|
||||
name: 'another',
|
||||
template: '<input>',
|
||||
manipulator: 'val',
|
||||
});
|
||||
|
||||
const url: string = clay.generateUrl();
|
||||
const settings: Record<string, unknown> = clay.getSettings('{}');
|
||||
const rawSettings: Record<string, unknown> = clay.getSettings('{}', false);
|
||||
clay.setSettings('key', 'value');
|
||||
clay.setSettings({ key: 'value' });
|
||||
|
||||
// --- Static methods ---
|
||||
|
||||
const uri: string = Clay.encodeDataUri('<html></html>');
|
||||
const uriWithPrefix: string = Clay.encodeDataUri('<html></html>', 'http://example.com/#');
|
||||
const prepared: number | string | (number | string)[] = Clay.prepareForAppMessage(42);
|
||||
const appMsg: Record<number, number | string> =
|
||||
Clay.prepareSettingsForAppMessage({ bg_color: { value: 255 } });
|
||||
|
||||
// --- M interface ---
|
||||
|
||||
function testM(el: Clay.M) {
|
||||
const len: number = el.length;
|
||||
const htmlEl: HTMLElement = el[0];
|
||||
const added: Clay.M = el.add('<span>');
|
||||
const afterSet: Clay.M = el.set('className', 'active');
|
||||
const val: unknown = el.get('value');
|
||||
const selected: Clay.M = el.select('.child');
|
||||
el.on('click', () => {});
|
||||
el.each((element: HTMLElement, index: number) => {});
|
||||
}
|
||||
|
||||
// --- PebbleActiveWatchInfo ---
|
||||
|
||||
const watchInfo: Clay.PebbleActiveWatchInfo = {
|
||||
platform: 'chalk',
|
||||
model: 'qemu_platform_chalk',
|
||||
language: 'en_US',
|
||||
firmware: { major: 4, minor: 3, patch: 0, suffix: '' },
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2015",
|
||||
"module": "node16",
|
||||
"allowJs": true,
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"rootDir": ".",
|
||||
"outDir": "./dist-types",
|
||||
"strict": false,
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "node16",
|
||||
"typeRoots": ["./types", "./node_modules/@types"]
|
||||
},
|
||||
"include": [
|
||||
"src/scripts/lib/clay-config.js",
|
||||
"src/scripts/lib/clay-events.js",
|
||||
"src/scripts/lib/clay-item.js",
|
||||
"src/scripts/lib/component-registry.js",
|
||||
"src/scripts/lib/manipulators.js",
|
||||
"src/scripts/lib/utils.js"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"test",
|
||||
"dev",
|
||||
"tmp",
|
||||
"src/scripts/config-page.js",
|
||||
"src/scripts/components",
|
||||
"src/scripts/vendor",
|
||||
"src/js"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2015",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node10",
|
||||
"esModuleInterop": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"ignoreDeprecations": "6.0"
|
||||
},
|
||||
"include": [
|
||||
"test/type-checks.ts"
|
||||
]
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
declare module './tmp/config-page.html' {
|
||||
const html: string;
|
||||
export = html;
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
declare module 'message_keys' {
|
||||
const messageKeys: { [key: string]: number };
|
||||
export = messageKeys;
|
||||
}
|
||||
Reference in New Issue
Block a user