@airtable/blocks 0.0.0-experimental-20e3506bd-20250428 → 0.0.0-experimental-f1c9010b3-20250609
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +561 -0
- package/dist/cjs/base/models/base.js +1 -1
- package/dist/cjs/base/models/create_aggregators.js +1 -1
- package/dist/cjs/base/models/cursor.js +2 -2
- package/dist/cjs/base/models/field.js +2 -2
- package/dist/cjs/base/models/record_coloring.js +2 -2
- package/dist/cjs/base/models/record_query_result.js +1 -1
- package/dist/cjs/base/models/session.js +4 -4
- package/dist/cjs/base/models/table.js +2 -2
- package/dist/cjs/base/models/view.js +1 -1
- package/dist/cjs/base/perform_record_action.js +1 -1
- package/dist/cjs/base/sdk.js +4 -1
- package/dist/cjs/base/settings_button.js +2 -2
- package/dist/cjs/base/types/view.js +1 -1
- package/dist/cjs/base/ui/base_provider.js +1 -1
- package/dist/cjs/base/ui/expand_record.js +1 -1
- package/dist/cjs/base/ui/expand_record_list.js +1 -1
- package/dist/cjs/base/ui/expand_record_picker_async.js +1 -1
- package/dist/cjs/base/ui/global_alert.js +1 -1
- package/dist/cjs/base/ui/initialize_block.js +20 -5
- package/dist/cjs/base/ui/progress_bar.js +1 -1
- package/dist/cjs/base/ui/select_and_select_buttons_helpers.js +2 -0
- package/dist/cjs/base/ui/system/utils/ensure_numbers_are_within_scale.js +2 -0
- package/dist/cjs/base/ui/ui.js +9 -1
- package/dist/cjs/base/ui/use_base.js +1 -1
- package/dist/cjs/base/ui/use_cursor.js +1 -1
- package/dist/cjs/{shared → base}/ui/use_loadable.js +6 -6
- package/dist/cjs/base/ui/use_record_action_data.js +2 -2
- package/dist/cjs/base/ui/use_records.js +5 -5
- package/dist/cjs/base/ui/use_session.js +1 -1
- package/dist/cjs/base/ui/use_settings_button.js +1 -1
- package/dist/cjs/base/ui/use_view_metadata.js +2 -2
- package/dist/cjs/base/ui/use_viewport.js +1 -1
- package/dist/cjs/base/ui/viewport_constraint.js +2 -2
- package/dist/cjs/base/viewport.js +1 -1
- package/dist/cjs/interface/models/models.js +53 -0
- package/dist/cjs/interface/models/table.js +45 -0
- package/dist/cjs/interface/sdk.js +0 -15
- package/dist/cjs/interface/ui/expand_record.js +2 -1
- package/dist/cjs/interface/ui/initialize_block.js +16 -4
- package/dist/cjs/interface/ui/ui.js +27 -8
- package/dist/cjs/interface/ui/use_custom_properties.js +52 -5
- package/dist/cjs/shared/colors.js +2 -2
- package/dist/cjs/shared/global_config.js +45 -40
- package/dist/cjs/shared/models/base_core.js +34 -11
- package/dist/cjs/shared/models/field_core.js +1 -1
- package/dist/cjs/shared/models/record_core.js +1 -1
- package/dist/cjs/shared/models/session_core.js +1 -1
- package/dist/cjs/shared/models/table_core.js +1 -1
- package/dist/cjs/shared/sdk_core.js +6 -6
- package/dist/cjs/shared/types/field.js +1 -1
- package/dist/cjs/shared/ui/remote_utils.js +3 -3
- package/dist/cjs/shared/ui/use_color_scheme.js +60 -0
- package/dist/cjs/shared/ui/use_global_config.js +13 -8
- package/dist/cjs/shared/ui/use_synced.js +1 -1
- package/dist/cjs/shared/ui/use_watchable.js +3 -22
- package/dist/cjs/shared/ui/with_hooks.js +3 -3
- package/dist/types/src/base/models/base.d.ts +1 -1
- package/dist/types/src/base/models/create_aggregators.d.ts +1 -1
- package/dist/types/src/base/models/cursor.d.ts +2 -2
- package/dist/types/src/base/models/field.d.ts +2 -2
- package/dist/types/src/base/models/record_coloring.d.ts +2 -2
- package/dist/types/src/base/models/record_query_result.d.ts +1 -1
- package/dist/types/src/base/models/session.d.ts +4 -4
- package/dist/types/src/base/models/table.d.ts +2 -2
- package/dist/types/src/base/models/view.d.ts +1 -1
- package/dist/types/src/base/perform_record_action.d.ts +1 -1
- package/dist/types/src/base/sdk.d.ts.map +1 -1
- package/dist/types/src/base/settings_button.d.ts +2 -2
- package/dist/types/src/base/types/view.d.ts +1 -1
- package/dist/types/src/base/ui/base_provider.d.ts +1 -1
- package/dist/types/src/base/ui/expand_record.d.ts +1 -1
- package/dist/types/src/base/ui/expand_record_list.d.ts +1 -1
- package/dist/types/src/base/ui/expand_record_picker_async.d.ts +1 -1
- package/dist/types/src/base/ui/global_alert.d.ts +1 -1
- package/dist/types/src/base/ui/initialize_block.d.ts +1 -1
- package/dist/types/src/base/ui/initialize_block.d.ts.map +1 -1
- package/dist/types/src/base/ui/progress_bar.d.ts +1 -1
- package/dist/types/src/base/ui/select_and_select_buttons_helpers.d.ts.map +1 -1
- package/dist/types/src/base/ui/types/tooltip_anchor_props.d.ts +1 -0
- package/dist/types/src/base/ui/types/tooltip_anchor_props.d.ts.map +1 -1
- package/dist/types/src/base/ui/ui.d.ts +2 -1
- package/dist/types/src/base/ui/ui.d.ts.map +1 -1
- package/dist/types/src/base/ui/use_base.d.ts +1 -1
- package/dist/types/src/base/ui/use_cursor.d.ts +1 -1
- package/dist/types/src/{shared → base}/ui/use_loadable.d.ts +3 -3
- package/dist/types/src/base/ui/use_loadable.d.ts.map +1 -0
- package/dist/types/src/base/ui/use_record_action_data.d.ts +1 -1
- package/dist/types/src/base/ui/use_session.d.ts +1 -1
- package/dist/types/src/base/ui/use_settings_button.d.ts +1 -1
- package/dist/types/src/base/ui/use_viewport.d.ts +1 -1
- package/dist/types/src/base/ui/viewport_constraint.d.ts +2 -2
- package/dist/types/src/base/viewport.d.ts +1 -1
- package/dist/types/src/interface/models/models.d.ts +8 -0
- package/dist/types/src/interface/models/models.d.ts.map +1 -0
- package/dist/types/src/interface/models/table.d.ts +30 -0
- package/dist/types/src/interface/models/table.d.ts.map +1 -1
- package/dist/types/src/interface/sdk.d.ts.map +1 -1
- package/dist/types/src/interface/types/table.d.ts +1 -0
- package/dist/types/src/interface/types/table.d.ts.map +1 -1
- package/dist/types/src/interface/ui/expand_record.d.ts +2 -1
- package/dist/types/src/interface/ui/expand_record.d.ts.map +1 -1
- package/dist/types/src/interface/ui/initialize_block.d.ts +30 -0
- package/dist/types/src/interface/ui/initialize_block.d.ts.map +1 -1
- package/dist/types/src/interface/ui/ui.d.ts +2 -1
- package/dist/types/src/interface/ui/ui.d.ts.map +1 -1
- package/dist/types/src/interface/ui/use_custom_properties.d.ts +52 -5
- package/dist/types/src/interface/ui/use_custom_properties.d.ts.map +1 -1
- package/dist/types/src/shared/color_utils.d.ts +3 -3
- package/dist/types/src/shared/colors.d.ts +2 -2
- package/dist/types/src/shared/global_config.d.ts +45 -40
- package/dist/types/src/shared/global_config.d.ts.map +1 -1
- package/dist/types/src/shared/models/base_core.d.ts +34 -11
- package/dist/types/src/shared/models/base_core.d.ts.map +1 -1
- package/dist/types/src/shared/models/field_core.d.ts +1 -1
- package/dist/types/src/shared/models/session_core.d.ts +1 -1
- package/dist/types/src/shared/private_utils.d.ts +1 -1
- package/dist/types/src/shared/private_utils.d.ts.map +1 -1
- package/dist/types/src/shared/sdk_core.d.ts +4 -4
- package/dist/types/src/shared/types/field.d.ts +1 -1
- package/dist/types/src/shared/ui/remote_utils.d.ts +3 -3
- package/dist/types/src/shared/ui/use_color_scheme.d.ts +28 -0
- package/dist/types/src/shared/ui/use_color_scheme.d.ts.map +1 -0
- package/dist/types/src/shared/ui/use_global_config.d.ts +13 -8
- package/dist/types/src/shared/ui/use_global_config.d.ts.map +1 -1
- package/dist/types/src/shared/ui/use_synced.d.ts +1 -1
- package/dist/types/src/shared/ui/use_watchable.d.ts +3 -22
- package/dist/types/src/shared/ui/use_watchable.d.ts.map +1 -1
- package/dist/types/src/shared/ui/with_hooks.d.ts +3 -3
- package/dist/types/stories/collaborator_token.stories.d.ts.map +1 -1
- package/dist/types/test/ui/use_color_scheme.test.d.ts +2 -0
- package/dist/types/test/ui/use_color_scheme.test.d.ts.map +1 -0
- package/package.json +16 -12
- package/dist/types/src/shared/ui/use_loadable.d.ts.map +0 -1
- package/ui.d.ts +0 -1
- package/ui.js +0 -1
- package/unstable_private_utils.d.ts +0 -1
- package/unstable_private_utils.js +0 -1
- package/unstable_standalone_ui.d.ts +0 -1
- package/unstable_standalone_ui.js +0 -1
- package/unstable_testing_utils.d.ts +0 -1
- package/unstable_testing_utils.js +0 -1
|
@@ -46,7 +46,6 @@ var hasBeenInitialized = false;
|
|
|
46
46
|
* initializeBlock({interface: () => <App />});
|
|
47
47
|
* ```
|
|
48
48
|
* @docsPath UI/utils/initializeBlock
|
|
49
|
-
* @internal
|
|
50
49
|
*/
|
|
51
50
|
function initializeBlock(entryPoints) {
|
|
52
51
|
var body = typeof document !== 'undefined' ? document.body : null;
|
|
@@ -79,10 +78,23 @@ function initializeBlock(entryPoints) {
|
|
|
79
78
|
throw (0, _error_utils.spawnError)("The first argument to initializeBlock didn't return a valid React element");
|
|
80
79
|
}
|
|
81
80
|
var container = document.createElement('div');
|
|
81
|
+
container.style.height = '100%';
|
|
82
|
+
container.style.width = '100%';
|
|
82
83
|
body.appendChild(container);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
|
|
85
|
+
// Try to use createRoot API (React 18+)
|
|
86
|
+
try {
|
|
87
|
+
var _require = require('react-dom/client'),
|
|
88
|
+
createRoot = _require.createRoot;
|
|
89
|
+
createRoot(container).render( /*#__PURE__*/React.createElement(_block_wrapper.BlockWrapper, {
|
|
90
|
+
sdk: sdk
|
|
91
|
+
}, entryElement));
|
|
92
|
+
} catch (e) {
|
|
93
|
+
// Fallback to legacy render for React 16/17
|
|
94
|
+
_reactDom.default.render( /*#__PURE__*/React.createElement(_block_wrapper.BlockWrapper, {
|
|
95
|
+
sdk: sdk
|
|
96
|
+
}, entryElement), container);
|
|
97
|
+
}
|
|
86
98
|
}
|
|
87
99
|
var sdk;
|
|
88
100
|
|
|
@@ -28,28 +28,46 @@ Object.defineProperty(exports, "initializeBlock", {
|
|
|
28
28
|
return _initialize_block.initializeBlock;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
+
Object.defineProperty(exports, "loadCSSFromString", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function get() {
|
|
34
|
+
return _remote_utils.loadCSSFromString;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "loadCSSFromURLAsync", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function get() {
|
|
40
|
+
return _remote_utils.loadCSSFromURLAsync;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "loadScriptFromURLAsync", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _remote_utils.loadScriptFromURLAsync;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
31
49
|
Object.defineProperty(exports, "useBase", {
|
|
32
50
|
enumerable: true,
|
|
33
51
|
get: function get() {
|
|
34
52
|
return _use_base.useBase;
|
|
35
53
|
}
|
|
36
54
|
});
|
|
37
|
-
Object.defineProperty(exports, "
|
|
55
|
+
Object.defineProperty(exports, "useColorScheme", {
|
|
38
56
|
enumerable: true,
|
|
39
57
|
get: function get() {
|
|
40
|
-
return
|
|
58
|
+
return _use_color_scheme.useColorScheme;
|
|
41
59
|
}
|
|
42
60
|
});
|
|
43
|
-
Object.defineProperty(exports, "
|
|
61
|
+
Object.defineProperty(exports, "useCustomProperties", {
|
|
44
62
|
enumerable: true,
|
|
45
63
|
get: function get() {
|
|
46
|
-
return
|
|
64
|
+
return _use_custom_properties.useCustomProperties;
|
|
47
65
|
}
|
|
48
66
|
});
|
|
49
|
-
Object.defineProperty(exports, "
|
|
67
|
+
Object.defineProperty(exports, "useGlobalConfig", {
|
|
50
68
|
enumerable: true,
|
|
51
69
|
get: function get() {
|
|
52
|
-
return
|
|
70
|
+
return _use_global_config.default;
|
|
53
71
|
}
|
|
54
72
|
});
|
|
55
73
|
Object.defineProperty(exports, "useRecords", {
|
|
@@ -92,14 +110,15 @@ require("..");
|
|
|
92
110
|
var _expand_record = require("./expand_record");
|
|
93
111
|
var _initialize_block = require("./initialize_block");
|
|
94
112
|
var _use_base = require("./use_base");
|
|
113
|
+
var _use_color_scheme = require("../../shared/ui/use_color_scheme");
|
|
95
114
|
var _use_custom_properties = require("./use_custom_properties");
|
|
96
115
|
var _use_records = require("./use_records");
|
|
97
116
|
var _use_run_info = require("./use_run_info");
|
|
98
117
|
var _use_session = require("./use_session");
|
|
99
118
|
var _use_global_config = _interopRequireDefault(require("../../shared/ui/use_global_config"));
|
|
100
|
-
var _use_loadable = _interopRequireDefault(require("../../shared/ui/use_loadable"));
|
|
101
119
|
var _use_synced = _interopRequireDefault(require("../../shared/ui/use_synced"));
|
|
102
120
|
var _use_watchable = _interopRequireDefault(require("../../shared/ui/use_watchable"));
|
|
103
121
|
var _with_hooks = _interopRequireDefault(require("../../shared/ui/with_hooks"));
|
|
104
122
|
var _colors = _interopRequireDefault(require("../../shared/colors"));
|
|
105
|
-
var _color_utils = _interopRequireDefault(require("../../shared/color_utils"));
|
|
123
|
+
var _color_utils = _interopRequireDefault(require("../../shared/color_utils"));
|
|
124
|
+
var _remote_utils = require("../../shared/ui/remote_utils");
|
|
@@ -27,14 +27,61 @@ var _error_utils = require("../../shared/error_utils");
|
|
|
27
27
|
// passes a Table model instance, and then we transform that to be a fieldId custom
|
|
28
28
|
// property with a tableId before we pass it to hyperbase.
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* An object that represents a custom property that a block can set.
|
|
31
|
+
*
|
|
32
|
+
* ```
|
|
33
|
+
* type BlockPageElementCustomProperty = {key: string; label: string} & (
|
|
34
|
+
* | {type: 'boolean'; defaultValue: boolean}
|
|
35
|
+
* | {type: 'string'; defaultValue?: string}
|
|
36
|
+
* | {
|
|
37
|
+
* type: 'enum';
|
|
38
|
+
* possibleValues: Array<{value: string; label: string}>;
|
|
39
|
+
* defaultValue?: string;
|
|
40
|
+
* }
|
|
41
|
+
* | {
|
|
42
|
+
* type: 'field';
|
|
43
|
+
* table: Table;
|
|
44
|
+
* possibleValues?: Array<Field>; // If not provided, all visible fields in the table will be shown in the dropdown.
|
|
45
|
+
* defaultValue?: Field;
|
|
46
|
+
* }
|
|
47
|
+
* );
|
|
48
|
+
* ```
|
|
32
49
|
*/
|
|
33
50
|
|
|
34
51
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
52
|
+
* A hook for integrating configuration settings for your block with the Interface Designer properties
|
|
53
|
+
* panel. Under the hood, this uses {@link GlobalConfig} to store the custom property values.
|
|
54
|
+
*
|
|
55
|
+
* Returns an object with:
|
|
56
|
+
* - `customPropertyValueByKey`: an object mapping custom property keys to their current value.
|
|
57
|
+
* - `errorState`: an object with an `error` property if there was an error setting the custom properties
|
|
58
|
+
*
|
|
59
|
+
* @param getCustomProperties A function that returns an array of {@link BlockPageElementCustomProperty}.
|
|
60
|
+
* This function should have a stable identity, so it should either be defined at the top level of the
|
|
61
|
+
* file or wrapped in useCallback. It will receive an instance of {@link Base} as an argument.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```js
|
|
65
|
+
* import {useCustomProperties} from '@airtable/blocks/interface/ui';
|
|
66
|
+
*
|
|
67
|
+
* function getCustomProperties(base: Base) {
|
|
68
|
+
* const table = base.tables[0];
|
|
69
|
+
* const numberFields = table.fields.filter(field => field.type === FieldType.NUMBER);
|
|
70
|
+
* return [
|
|
71
|
+
* {key: 'title', label: 'Title', type: 'string', defaultValue: 'Chart'},
|
|
72
|
+
* {key: 'xAxis', label: 'X-axis', type: 'field', table, possibleValues: numberFields},
|
|
73
|
+
* {key: 'yAxis', label: 'Y-axis', type: 'field', table, possibleValues: numberFields},
|
|
74
|
+
* {key: 'color', label: 'Color', type: 'enum', possibleValues: ['red', 'blue', 'green'], defaultValue: 'red'},
|
|
75
|
+
* {key: 'showLegend', label: 'Show Legend', type: 'boolean', defaultValue: true},
|
|
76
|
+
* ];
|
|
77
|
+
* }
|
|
78
|
+
*
|
|
79
|
+
* function MyApp() {
|
|
80
|
+
* const {customPropertyValueByKey, errorState} = useCustomProperties(getCustomProperties);
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
* @docsPath UI/hooks/useCustomProperties
|
|
84
|
+
* @hook
|
|
38
85
|
*/
|
|
39
86
|
function useCustomProperties(getCustomProperties) {
|
|
40
87
|
var sdk = (0, _sdk_context.useSdk)();
|
|
@@ -16,9 +16,9 @@ exports.rgbTuplesByColor = exports.default = void 0;
|
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```js
|
|
19
|
-
* import {
|
|
19
|
+
* import {colors, colorUtils} from '@airtable/blocks/[placeholder-path]/ui';
|
|
20
20
|
*
|
|
21
|
-
* <
|
|
21
|
+
* <div style={{backgroundColor: colorUtils.getHexForColor(colors.BLUE)}}>Hello world</div>
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
24
24
|
* @docsPath UI/utils/colors
|
|
@@ -58,10 +58,6 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
58
58
|
* The maximum allowed size for a given GlobalConfig instance is 150kB.
|
|
59
59
|
* The maximum number of keys for a given GlobalConfig instance is 1000.
|
|
60
60
|
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```js
|
|
63
|
-
* import {globalConfig} from '@airtable/blocks';
|
|
64
|
-
* ```
|
|
65
61
|
* @docsPath models/GlobalConfig
|
|
66
62
|
*/
|
|
67
63
|
var GlobalConfig = /*#__PURE__*/function (_Watchable) {
|
|
@@ -136,10 +132,13 @@ var GlobalConfig = /*#__PURE__*/function (_Watchable) {
|
|
|
136
132
|
* @param key A string for the top-level key, or an array of strings describing the path to the value.
|
|
137
133
|
* @example
|
|
138
134
|
* ```js
|
|
139
|
-
* import {
|
|
135
|
+
* import {useGlobalConfig} from '@airtable/blocks/[placeholder-path]/ui';
|
|
140
136
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
137
|
+
* function MyApp() {
|
|
138
|
+
* const globalConfig = useGlobalConfig();
|
|
139
|
+
* const topLevelValue = globalConfig.get('topLevelKey');
|
|
140
|
+
* const nestedValue = globalConfig.get(['topLevelKey', 'nested', 'deeply']);
|
|
141
|
+
* }
|
|
143
142
|
* ```
|
|
144
143
|
*/
|
|
145
144
|
}, {
|
|
@@ -238,23 +237,26 @@ var GlobalConfig = /*#__PURE__*/function (_Watchable) {
|
|
|
238
237
|
* @param value The value to set at the specified path. Use `undefined` to delete the value at the given path.
|
|
239
238
|
* @example
|
|
240
239
|
* ```js
|
|
241
|
-
* import {
|
|
242
|
-
*
|
|
243
|
-
* function
|
|
244
|
-
*
|
|
245
|
-
*
|
|
240
|
+
* import {useGlobalConfig} from '@airtable/blocks/[placeholder-path]/ui';
|
|
241
|
+
*
|
|
242
|
+
* function MyApp() {
|
|
243
|
+
* const globalConfig = useGlobalConfig();
|
|
244
|
+
* const updateFavoriteColorIfPossible = (color) => {
|
|
245
|
+
* if (globalConfig.hasPermissionToSet('favoriteColor', color)) {
|
|
246
|
+
* globalConfig.setAsync('favoriteColor', color);
|
|
247
|
+
* }
|
|
248
|
+
* // The update is now applied within your extension (eg will be
|
|
249
|
+
* // reflected in globalConfig) but are still being saved to
|
|
250
|
+
* // Airtable servers (e.g. may not be updated for other users yet)
|
|
246
251
|
* }
|
|
247
|
-
* // The update is now applied within your extension (eg will be
|
|
248
|
-
* // reflected in globalConfig) but are still being saved to
|
|
249
|
-
* // Airtable servers (e.g. may not be updated for other users yet)
|
|
250
|
-
* }
|
|
251
252
|
*
|
|
252
|
-
* async
|
|
253
|
-
*
|
|
254
|
-
*
|
|
253
|
+
* const updateFavoriteColorIfPossibleAsync = async (color) => {
|
|
254
|
+
* if (globalConfig.hasPermissionToSet('favoriteColor', color)) {
|
|
255
|
+
* await globalConfig.setAsync('favoriteColor', color);
|
|
256
|
+
* }
|
|
257
|
+
* // globalConfig updates have been saved to Airtable servers.
|
|
258
|
+
* alert('favoriteColor has been updated');
|
|
255
259
|
* }
|
|
256
|
-
* // globalConfig updates have been saved to Airtable servers.
|
|
257
|
-
* alert('favoriteColor has been updated');
|
|
258
260
|
* }
|
|
259
261
|
* ```
|
|
260
262
|
*/
|
|
@@ -370,28 +372,31 @@ var GlobalConfig = /*#__PURE__*/function (_Watchable) {
|
|
|
370
372
|
* @param updates The paths and values to set.
|
|
371
373
|
* @example
|
|
372
374
|
* ```js
|
|
373
|
-
* import {
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* ]
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
375
|
+
* import {useGlobalConfig} from '@airtable/blocks/[placeholder-path]/ui';
|
|
376
|
+
*
|
|
377
|
+
* function MyApp() {
|
|
378
|
+
* const globalConfig = useGlobalConfig();
|
|
379
|
+
* const updates = [
|
|
380
|
+
* {path: ['topLevelKey1', 'nestedKey1'], value: 'foo'},
|
|
381
|
+
* {path: ['topLevelKey2', 'nestedKey2'], value: 'bar'},
|
|
382
|
+
* ];
|
|
383
|
+
*
|
|
384
|
+
* const applyUpdatesIfPossible = () => {
|
|
385
|
+
* if (globalConfig.hasPermissionToSetPaths(updates)) {
|
|
386
|
+
* globalConfig.setPathsAsync(updates);
|
|
387
|
+
* }
|
|
388
|
+
* // The updates are now applied within your extension (eg will be reflected in
|
|
389
|
+
* // globalConfig) but are still being saved to Airtable servers (e.g. they
|
|
390
|
+
* // may not be updated for other users yet)
|
|
383
391
|
* }
|
|
384
|
-
* // The updates are now applied within your extension (eg will be reflected in
|
|
385
|
-
* // globalConfig) but are still being saved to Airtable servers (e.g. they
|
|
386
|
-
* // may not be updated for other users yet)
|
|
387
|
-
* }
|
|
388
392
|
*
|
|
389
|
-
* async
|
|
390
|
-
*
|
|
391
|
-
*
|
|
393
|
+
* const applyUpdatesIfPossibleAsync = async () => {
|
|
394
|
+
* if (globalConfig.hasPermissionToSetPaths(updates)) {
|
|
395
|
+
* await globalConfig.setPathsAsync(updates);
|
|
396
|
+
* }
|
|
397
|
+
* // globalConfig updates have been saved to Airtable servers.
|
|
398
|
+
* alert('globalConfig has been updated');
|
|
392
399
|
* }
|
|
393
|
-
* // globalConfig updates have been saved to Airtable servers.
|
|
394
|
-
* alert('globalConfig has been updated');
|
|
395
400
|
* }
|
|
396
401
|
* ```
|
|
397
402
|
*/
|
|
@@ -111,8 +111,12 @@ var BaseCore = exports.BaseCore = /*#__PURE__*/function (_AbstractModel) {
|
|
|
111
111
|
*
|
|
112
112
|
* @example
|
|
113
113
|
* ```js
|
|
114
|
-
* import {
|
|
115
|
-
*
|
|
114
|
+
* import {useBase} from '@airtable/blocks/[placeholder-path]/ui';
|
|
115
|
+
*
|
|
116
|
+
* function MyApp() {
|
|
117
|
+
* const base = useBase();
|
|
118
|
+
* console.log('The name of your base is', base.name);
|
|
119
|
+
* }
|
|
116
120
|
* ```
|
|
117
121
|
*/
|
|
118
122
|
}, {
|
|
@@ -126,8 +130,12 @@ var BaseCore = exports.BaseCore = /*#__PURE__*/function (_AbstractModel) {
|
|
|
126
130
|
*
|
|
127
131
|
* @example
|
|
128
132
|
* ```js
|
|
129
|
-
* import {
|
|
130
|
-
*
|
|
133
|
+
* import {useBase} from '@airtable/blocks/[placeholder-path]/ui';
|
|
134
|
+
*
|
|
135
|
+
* function MyApp() {
|
|
136
|
+
* const base = useBase();
|
|
137
|
+
* console.log('The workspace id of your base is', base.workspaceId);
|
|
138
|
+
* }
|
|
131
139
|
* ```
|
|
132
140
|
*/
|
|
133
141
|
}, {
|
|
@@ -141,9 +149,16 @@ var BaseCore = exports.BaseCore = /*#__PURE__*/function (_AbstractModel) {
|
|
|
141
149
|
*
|
|
142
150
|
* @example
|
|
143
151
|
* ```js
|
|
144
|
-
* import {
|
|
145
|
-
*
|
|
146
|
-
*
|
|
152
|
+
* import {colorUtils, useBase} from '@airtable/blocks/[placeholder-path]/ui';
|
|
153
|
+
*
|
|
154
|
+
* function MyApp() {
|
|
155
|
+
* const base = useBase();
|
|
156
|
+
* return (
|
|
157
|
+
* <div style={{backgroundColor: colorUtils.getHexForColor(base.color)}}>
|
|
158
|
+
* This div's background is the same color as the base background
|
|
159
|
+
* </div>
|
|
160
|
+
* );
|
|
161
|
+
* }
|
|
147
162
|
* ```
|
|
148
163
|
*/
|
|
149
164
|
}, {
|
|
@@ -157,8 +172,12 @@ var BaseCore = exports.BaseCore = /*#__PURE__*/function (_AbstractModel) {
|
|
|
157
172
|
*
|
|
158
173
|
* @example
|
|
159
174
|
* ```js
|
|
160
|
-
* import {
|
|
161
|
-
*
|
|
175
|
+
* import {useBase} from '@airtable/blocks/[placeholder-path]/ui';
|
|
176
|
+
*
|
|
177
|
+
* function MyApp() {
|
|
178
|
+
* const base = useBase();
|
|
179
|
+
* console.log(`You have ${base.tables.length} tables`);
|
|
180
|
+
* }
|
|
162
181
|
* ```
|
|
163
182
|
*/
|
|
164
183
|
}, {
|
|
@@ -197,8 +216,12 @@ var BaseCore = exports.BaseCore = /*#__PURE__*/function (_AbstractModel) {
|
|
|
197
216
|
*
|
|
198
217
|
* @example
|
|
199
218
|
* ```js
|
|
200
|
-
* import {
|
|
201
|
-
*
|
|
219
|
+
* import {useBase} from '@airtable/blocks/[placeholder-path]/ui';
|
|
220
|
+
*
|
|
221
|
+
* function MyApp() {
|
|
222
|
+
* const base = useBase();
|
|
223
|
+
* console.log(base.activeCollaborators[0].email);
|
|
224
|
+
* }
|
|
202
225
|
* ```
|
|
203
226
|
*/
|
|
204
227
|
function get() {
|
|
@@ -127,7 +127,7 @@ var FieldCore = exports.FieldCore = /*#__PURE__*/function (_AbstractModel) {
|
|
|
127
127
|
* @see {@link FieldType}
|
|
128
128
|
* @example
|
|
129
129
|
* ```js
|
|
130
|
-
* import {FieldType} from '@airtable/blocks/models';
|
|
130
|
+
* import {FieldType} from '@airtable/blocks/[placeholder-path]/models';
|
|
131
131
|
*
|
|
132
132
|
* if (myField.type === FieldType.CURRENCY) {
|
|
133
133
|
* console.log(myField.options.symbol);
|
|
@@ -79,7 +79,7 @@ var RecordCore = exports.RecordCore = /*#__PURE__*/function (_AbstractModel) {
|
|
|
79
79
|
* @internal (since we may not be able to return parent model instances in the immutable models world)
|
|
80
80
|
* @example
|
|
81
81
|
* ```js
|
|
82
|
-
* import {useRecords} from '@airtable/blocks/ui';
|
|
82
|
+
* import {useRecords} from '@airtable/blocks/base/ui';
|
|
83
83
|
* const records = useRecords(myTable);
|
|
84
84
|
* console.log(records[0].parentTable.id === myTable.id);
|
|
85
85
|
* // => true
|
|
@@ -86,7 +86,7 @@ var SessionCore = exports.SessionCore = /*#__PURE__*/function (_AbstractModel) {
|
|
|
86
86
|
*
|
|
87
87
|
* @example
|
|
88
88
|
* ```js
|
|
89
|
-
* import {useSession} from '@airtable/blocks/ui';
|
|
89
|
+
* import {useSession} from '@airtable/blocks/[placeholder-path]/ui';
|
|
90
90
|
*
|
|
91
91
|
* function CurrentUser() {
|
|
92
92
|
* const session = useSession();
|
|
@@ -81,7 +81,7 @@ var TableCore = exports.TableCore = /*#__PURE__*/function (_AbstractModel) {
|
|
|
81
81
|
* @internal (since we may not be able to return parent model instances in the immutable models world)
|
|
82
82
|
* @example
|
|
83
83
|
* ```js
|
|
84
|
-
* import {base} from '@airtable/blocks';
|
|
84
|
+
* import {base} from '@airtable/blocks/base';
|
|
85
85
|
* const table = base.getTableByName('Table 1');
|
|
86
86
|
* console.log(table.parentBase.id === base.id);
|
|
87
87
|
* // => true
|
|
@@ -13,7 +13,7 @@ var _global_config = _interopRequireDefault(require("./global_config"));
|
|
|
13
13
|
* @hidden
|
|
14
14
|
* @example
|
|
15
15
|
* ```js
|
|
16
|
-
* import {runInfo} from '@airtable/blocks';
|
|
16
|
+
* import {runInfo} from '@airtable/blocks/base';
|
|
17
17
|
* if (runInfo.isFirstRun) {
|
|
18
18
|
* // The current user just installed this block.
|
|
19
19
|
* // Take the opportunity to show any onboarding and set
|
|
@@ -39,7 +39,7 @@ var BlockSdkCore = exports.BlockSdkCore = /*#__PURE__*/function () {
|
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* ```js
|
|
42
|
-
* import {installationId} from '@airtable/blocks';
|
|
42
|
+
* import {installationId} from '@airtable/blocks/base';
|
|
43
43
|
* console.log(installationId);
|
|
44
44
|
* // => 'blifDutUr92OKwnUn'
|
|
45
45
|
* ```
|
|
@@ -69,7 +69,7 @@ var BlockSdkCore = exports.BlockSdkCore = /*#__PURE__*/function () {
|
|
|
69
69
|
|
|
70
70
|
// Bind the public methods on this class so users can import
|
|
71
71
|
// just the method, e.g.
|
|
72
|
-
// import {reload} from '@airtable/blocks';
|
|
72
|
+
// import {reload} from '@airtable/blocks/base';
|
|
73
73
|
this.reload = this.reload.bind(this);
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -83,8 +83,8 @@ var BlockSdkCore = exports.BlockSdkCore = /*#__PURE__*/function () {
|
|
|
83
83
|
* @example
|
|
84
84
|
* ```js
|
|
85
85
|
* import React from 'react';
|
|
86
|
-
* import {reload} from '@airtable/blocks';
|
|
87
|
-
* import {Button, initializeBlock} from '@airtable/blocks/ui';
|
|
86
|
+
* import {reload} from '@airtable/blocks/base';
|
|
87
|
+
* import {Button, initializeBlock} from '@airtable/blocks/base/ui';
|
|
88
88
|
* function MyBlock() {
|
|
89
89
|
* return <Button onClick={() => reload()}>Reload</Button>;
|
|
90
90
|
* }
|
|
@@ -112,4 +112,4 @@ var BlockSdkCore = exports.BlockSdkCore = /*#__PURE__*/function () {
|
|
|
112
112
|
* @hidden
|
|
113
113
|
*/
|
|
114
114
|
// @ts-ignore
|
|
115
|
-
(0, _defineProperty2.default)(BlockSdkCore, "VERSION", "1.
|
|
115
|
+
(0, _defineProperty2.default)(BlockSdkCore, "VERSION", "1.19.0");
|
|
@@ -12,7 +12,7 @@ exports.FieldType = void 0;
|
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```js
|
|
15
|
-
* import {FieldType} from '@airtable/blocks/models';
|
|
15
|
+
* import {FieldType} from '@airtable/blocks/[placeholder-path]/models';
|
|
16
16
|
* const numberFields = myTable.fields.filter(field => (
|
|
17
17
|
* field.type === FieldType.NUMBER
|
|
18
18
|
* ));
|
|
@@ -17,7 +17,7 @@ var _error_utils = require("../error_utils");
|
|
|
17
17
|
* @param css The CSS string.
|
|
18
18
|
* @example
|
|
19
19
|
* ```js
|
|
20
|
-
* import {loadCSSFromString} from '@airtable/blocks/ui';
|
|
20
|
+
* import {loadCSSFromString} from '@airtable/blocks/[placeholder-path]/ui';
|
|
21
21
|
* loadCSSFromString('body { background: red; }');
|
|
22
22
|
* ```
|
|
23
23
|
* @docsPath UI/utils/loadCSSFromString
|
|
@@ -38,7 +38,7 @@ function loadCSSFromString(css) {
|
|
|
38
38
|
* @param url The URL of the stylesheet.
|
|
39
39
|
* @example
|
|
40
40
|
* ```js
|
|
41
|
-
* import {loadCSSFromURLAsync} from '@airtable/blocks/ui';
|
|
41
|
+
* import {loadCSSFromURLAsync} from '@airtable/blocks/[placeholder-path]/ui';
|
|
42
42
|
* loadCSSFromURLAsync('https://example.com/style.css');
|
|
43
43
|
* ```
|
|
44
44
|
* @docsPath UI/utils/loadCSSFromURLAsync
|
|
@@ -69,7 +69,7 @@ function loadCSSFromURLAsync(url) {
|
|
|
69
69
|
* @param url The URL of the script.
|
|
70
70
|
* @example
|
|
71
71
|
* ```js
|
|
72
|
-
* import {loadScriptFromURLAsync} from '@airtable/blocks/ui';
|
|
72
|
+
* import {loadScriptFromURLAsync} from '@airtable/blocks/[placeholder-path]/ui';
|
|
73
73
|
* loadScriptFromURLAsync('https://example.com/script.js');
|
|
74
74
|
* ```
|
|
75
75
|
* @docsPath UI/utils/loadScriptFromURLAsync
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useColorScheme = useColorScheme;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
/** @module @airtable/blocks/ui: useColorScheme */ /** */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A hook for checking whether Airtable is in light mode or dark mode.
|
|
14
|
+
*
|
|
15
|
+
* @returns An object with a `colorScheme` property, which can be `'light'` or `'dark'`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```js
|
|
19
|
+
* import {useColorScheme} from '@airtable/blocks/[placeholder-path]/ui';
|
|
20
|
+
*
|
|
21
|
+
* function MyApp() {
|
|
22
|
+
* const {colorScheme} = useColorScheme();
|
|
23
|
+
* return (
|
|
24
|
+
* <div style={colorScheme === 'dark' ?
|
|
25
|
+
* {color: 'white', backgroundColor: 'black'} :
|
|
26
|
+
* {color: 'black', backgroundColor: 'white'}
|
|
27
|
+
* }>
|
|
28
|
+
* Tada!
|
|
29
|
+
* </div>
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
* @docsPath UI/hooks/useColorScheme
|
|
34
|
+
* @hook
|
|
35
|
+
*/
|
|
36
|
+
// Returns an object so we can add more properties if we need to, eg a setter to change the
|
|
37
|
+
// color scheme from within extensions, whether the preference is directly set or inherited from
|
|
38
|
+
// the browser, etc.
|
|
39
|
+
function useColorScheme() {
|
|
40
|
+
var _useState = (0, _react.useState)(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'),
|
|
41
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
42
|
+
colorScheme = _useState2[0],
|
|
43
|
+
setColorScheme = _useState2[1];
|
|
44
|
+
(0, _react.useEffect)(() => {
|
|
45
|
+
var darkModeQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
46
|
+
// Fires when e.matches changes. If there are more color schemes than light and dark,
|
|
47
|
+
// we'll need multiple listeners (and corresponding media queries)
|
|
48
|
+
var darkModeListener = e => {
|
|
49
|
+
setColorScheme(e.matches ? 'dark' : 'light');
|
|
50
|
+
};
|
|
51
|
+
darkModeQuery.addEventListener('change', darkModeListener);
|
|
52
|
+
return () => {
|
|
53
|
+
// Clear listeners when the component unmounts
|
|
54
|
+
darkModeQuery.removeEventListener('change', darkModeListener);
|
|
55
|
+
};
|
|
56
|
+
}, []);
|
|
57
|
+
return {
|
|
58
|
+
colorScheme
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -15,9 +15,10 @@ var _sdk_context = require("./sdk_context");
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```js
|
|
18
|
-
* import {
|
|
18
|
+
* import {useGlobalConfig, useRunInfo} from '@airtable/blocks/[placeholder-path]/ui';
|
|
19
19
|
*
|
|
20
20
|
* function SyncedCounter() {
|
|
21
|
+
* const runInfo = useRunInfo();
|
|
21
22
|
* const globalConfig = useGlobalConfig();
|
|
22
23
|
* const count = globalConfig.get('count');
|
|
23
24
|
*
|
|
@@ -25,13 +26,17 @@ var _sdk_context = require("./sdk_context");
|
|
|
25
26
|
* const decrement = () => globalConfig.setAsync('count', count - 1);
|
|
26
27
|
* const isEnabled = globalConfig.hasPermissionToSet('count');
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* <
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
29
|
+
* if (runInfo.isPageElementInEditMode) {
|
|
30
|
+
* return (
|
|
31
|
+
* <div>
|
|
32
|
+
* <button onClick={decrement} disabled={!isEnabled} ariaLabel="decrease">-</button>
|
|
33
|
+
* {count}
|
|
34
|
+
* <button onClick={increment} disabled={!isEnabled} ariaLabel="increase">+</button>
|
|
35
|
+
* </div>
|
|
36
|
+
* );
|
|
37
|
+
* } else {
|
|
38
|
+
* return <div>{count}</div>;
|
|
39
|
+
* }
|
|
35
40
|
* }
|
|
36
41
|
* ```
|
|
37
42
|
* @docsPath UI/hooks/useGlobalConfig
|
|
@@ -14,7 +14,7 @@ var _sdk_context = require("./sdk_context");
|
|
|
14
14
|
* @param globalConfigKey
|
|
15
15
|
* @example
|
|
16
16
|
* ```js
|
|
17
|
-
* import {useBase, useSynced} from '@airtable/blocks/ui';
|
|
17
|
+
* import {useBase, useSynced} from '@airtable/blocks/[placeholder-path]/ui';
|
|
18
18
|
*
|
|
19
19
|
* function CustomInputSynced() {
|
|
20
20
|
* const [value, setValue, canSetValue] = useSynced('myGlobalConfigKey');
|
|
@@ -45,39 +45,20 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
45
45
|
*
|
|
46
46
|
* @example
|
|
47
47
|
* ```js
|
|
48
|
-
* import {useWatchable} from '@airtable/blocks/ui';
|
|
48
|
+
* import {useWatchable} from '@airtable/blocks/[placeholder-path]/ui';
|
|
49
49
|
*
|
|
50
50
|
* function TableName({table}) {
|
|
51
51
|
* useWatchable(table, 'name');
|
|
52
52
|
* return <span>The table name is {table.name}</span>;
|
|
53
53
|
* }
|
|
54
54
|
*
|
|
55
|
-
* function
|
|
56
|
-
* useWatchable(
|
|
57
|
-
* return <span>The view name is {view.name} and the type is {view.type}</span>;
|
|
58
|
-
* }
|
|
59
|
-
*
|
|
60
|
-
* function RecordValuesAndColorInViewIfExists({record, field, view}) {
|
|
61
|
-
* useWatchable(record, ['cellValues', view ? `colorInView:${view.id}` : null]);
|
|
55
|
+
* function RecordValues({record, field}) {
|
|
56
|
+
* useWatchable(record, ['cellValues']);
|
|
62
57
|
* return <span>
|
|
63
58
|
* The record has cell value {record.getCellValue(field)} in {field.name}.
|
|
64
|
-
* {view ? `The record has color ${record.getColorInView(view)} in ${view.name}.` : null}
|
|
65
59
|
* </span>
|
|
66
60
|
* }
|
|
67
61
|
* ```
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```js
|
|
71
|
-
* import {useWatchable} from '@airtable/blocks/ui';
|
|
72
|
-
*
|
|
73
|
-
* function ActiveView({cursor}) {
|
|
74
|
-
* useWatchable(cursor, 'activeViewId', () => {
|
|
75
|
-
* alert('active view changed!!!')
|
|
76
|
-
* });
|
|
77
|
-
*
|
|
78
|
-
* return <span>Active view id: {cursor.activeViewId}</span>;
|
|
79
|
-
* }
|
|
80
|
-
* ```
|
|
81
62
|
* @docsPath UI/hooks/useWatchable
|
|
82
63
|
* @hook
|
|
83
64
|
*/
|